imagecopyresampled

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

imagecopyresampled锟截诧拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷图锟今并碉拷锟斤拷锟斤拷小

说锟斤拷

imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) : bool

imagecopyresampled() 锟斤拷一锟斤拷图锟斤拷锟叫碉拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟津拷憋拷锟斤拷锟斤拷一锟斤拷图锟斤拷锟叫o拷平锟斤拷锟截诧拷锟斤拷锟斤拷锟斤拷值锟斤拷锟斤拷耍锟斤拷锟斤拷锟斤拷牵锟斤拷锟叫★拷锟酵硷拷锟侥达拷小锟斤拷锟斤拷然锟斤拷锟斤拷锟剿硷拷锟斤拷锟斤拷锟斤拷锟斤拷取锟�

In other words, imagecopyresampled() will take a rectangular area from src_image of width src_w and height src_h at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_w and height dst_h at position (dst_x,dst_y).

锟斤拷锟皆达拷锟侥匡拷锟侥匡拷群透叨炔锟酵拷锟斤拷锟斤拷锟斤拷锟斤拷锟接︼拷锟酵硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷臁o拷锟斤拷锟街革拷锟斤拷锟斤拷锟斤拷辖恰锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟酵伙拷锟酵硷拷诓锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 dst_image 锟斤拷 src_image 锟斤拷同锟侥伙拷锟斤拷锟斤拷锟津,碉拷锟斤拷锟斤拷锟斤拷蚪坏锟斤拷幕锟斤拷锟斤拷锟斤拷锟斤拷锟皆ぶ拷锟�

锟斤拷锟斤拷

dst_image

目锟斤拷图锟斤拷锟斤拷锟斤拷锟斤拷源锟斤拷

src_image

源图锟斤拷锟斤拷锟斤拷锟斤拷源锟斤拷

dst_x

目锟斤拷 X 锟斤拷锟斤拷恪�

dst_y

目锟斤拷 Y 锟斤拷锟斤拷恪�

src_x

源锟斤拷 X 锟斤拷锟斤拷恪�

src_y

源锟斤拷 Y 锟斤拷锟斤拷恪�

dst_w

目锟斤拷锟饺★拷

dst_h

目锟斤拷叨取锟�

src_w

源图锟斤拷目锟饺★拷

src_h

源图锟斤拷母叨取锟�

锟斤拷锟斤拷值

锟缴癸拷时锟斤拷锟斤拷 TRUE锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷

锟斤拷锟斤拷

Example #1 锟津单碉拷锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷踊峤硷拷锟斤拷锟斤拷为原锟叫尺达拷锟揭伙拷搿�

<?php
// 锟斤拷锟斤拷募锟�
$filename 'test.jpg';
$percent 0.5;

// 锟斤拷锟斤拷锟斤拷锟斤拷
header('Content-Type: image/jpeg');

// 锟斤拷取锟铰的尺达拷
list($width$height) = getimagesize($filename);
$new_width $width $percent;
$new_height $height $percent;

// 锟斤拷锟斤拷取锟斤拷
$image_p imagecreatetruecolor($new_width$new_height);
$image imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$new_width$new_height$width$height);

// 锟斤拷锟�
imagejpeg($image_pnull100);
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

锟斤拷锟斤拷锟斤拷锟斤拷樱锟斤拷虻サ锟斤拷锟斤拷锟�

Example #2 锟斤拷锟斤拷锟斤拷锟斤拷图锟斤拷锟斤拷锟铰诧拷锟斤拷

锟斤拷锟斤拷锟斤拷踊锟斤拷锟斤拷锟斤拷锟饺高讹拷为 200 锟斤拷锟斤拷锟斤拷示一锟斤拷图锟斤拷

<?php
// 源锟侥硷拷
$filename 'test.jpg';

// 锟斤拷锟斤拷锟斤拷锟斤拷锟�
$width 200;
$height 200;

// Content type
header('Content-Type: image/jpeg');

// 锟斤拷取锟铰尺达拷
list($width_orig$height_orig) = getimagesize($filename);

$ratio_orig $width_orig/$height_orig;

if (
$width/$height $ratio_orig) {
   
$width $height*$ratio_orig;
} else {
   
$height $width/$ratio_orig;
}

// 锟斤拷锟斤拷取锟斤拷
$image_p imagecreatetruecolor($width$height);
$image imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);

// 锟斤拷锟�
imagejpeg($image_pnull100);
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

锟斤拷锟斤拷锟斤拷樱锟斤拷锟斤拷锟斤拷锟斤拷锟酵硷拷锟斤拷锟斤拷虏锟斤拷锟�

注锟斤拷

Note:

锟斤拷为锟斤拷色锟斤拷图锟斤拷锟斤拷锟狡o拷255+1 锟斤拷锟斤拷色锟斤拷锟叫革拷锟斤拷锟解。锟截诧拷锟斤拷锟斤拷锟斤拷锟酵硷拷锟酵拷锟斤拷锟揭拷锟斤拷锟� 255 锟斤拷锟斤拷色锟斤拷锟斤拷锟斤拷锟铰的憋拷锟截诧拷锟斤拷锟斤拷锟斤拷锟截硷拷锟斤拷锟斤拷色时锟斤拷锟斤拷锟斤拷一锟街斤拷锟斤拷值锟斤拷锟皆碉拷色锟斤拷图锟斤拷锟皆凤拷锟斤拷一锟斤拷锟斤拷锟斤拷色时锟斤拷锟斤拷锟绞э拷锟斤拷锟斤拷锟窖★拷锟斤拷思锟斤拷锟斤拷锟斤拷锟接斤拷锟斤拷锟斤拷锟斤拷锟较o拷锟斤拷锟斤拷色锟斤拷锟解并锟斤拷锟斤拷锟斤拷锟接撅拷锟斤拷锟斤拷咏锟斤拷锟斤拷锟缴拷锟斤拷锟斤拷锟杰伙拷锟斤拷锟斤拷锟斤拷锟侥斤拷锟斤拷锟斤拷锟斤拷锟秸白o拷锟斤拷锟斤拷锟接撅拷锟斤拷锟角空白o拷锟斤拷图锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷猓拷锟绞癸拷锟斤拷锟斤拷色图锟斤拷锟斤拷为目锟斤拷图锟斤拷锟斤拷锟斤拷锟斤拷 imagecreatetruecolor() 锟斤拷锟斤拷锟侥★拷

锟轿硷拷

imagecopyresized() - 锟斤拷锟斤拷锟斤拷锟斤拷图锟今并碉拷锟斤拷锟斤拷小