The GD extension of PHP provides two functions to scale an image:
Imagecopyresized (destsrcdxdysxsyDWDH SWsh);
Imagecopyresampled (destsrcdxdysxsyDW dhSWsh);
The imagecopyresized () function works in all GD versions, but its scaled image algorithm is coarser and may cause jagged edges of the image. GD 2.x has a new imagecopyresampled () function, and its pixel interpolation algorithm gets a smoother image edge (but the function is slower than imagecopyresized () .
To take a look at an example, we'll reduce this figure by four times times:
$SRC= Imagecreatefromjpeg(' php.jpg ');
$width= Imagesx($src);
$height= Imagesy($src);
$x= $width/2; $y= $height/2;
$DST= Imagecreatetruecolor($x,$y);
imagecopyresized($DST,$src,0,0,0,0,$x,$y,$width,$height);
//imagecopyresampled ($DST, $SRC, 0,0,0,0, $x, $y, $width, $height);
Header(' Content-type:image/jpeg ');
imagejpeg($DST,'', -);
?>
Original:
Use
ImageCopyResized()函数生成的结果:
使用
ImageCopyResampled()函数生成的结果:
It's obvious that two functions produce a different image than the one you see.
ImageCopyResampled()函数生成的结果比较平滑,效果较好。
By the way, an effect is represented by an ASCII representation of the image. Imagecolorat () has a very interesting use, it can cycle check
The color of each pixel in the image, and then manipulate the color data.
Source:
$im
= Imagecreatefromjpeg(' test1.jpg ');
$DX= Imagesx($im);
$dy= Imagesy($im);
for ($y= 0; $y<$dy; $y++) {
for ($x=0; $x<$DX; $x++) {
$col= Imagecolorat($im, $x, $y);
$rgb= Imagecolorsforindex($im,$col);
printf('*',
$rgb[' Red '],$rgb[' Green '],$rgb[' Blue ']);
}
Echo"
\ n ";
}
Imagedestroy($im);
?>
Very interesting, hehe.
http://www.bkjia.com/PHPjc/318380.html www.bkjia.com true http://www.bkjia.com/PHPjc/318380.html techarticle the GD extension of PHP provides two functions to scale the image: Imagecopyresized (dest, src, dx, dy, sx, SY, DW, DH, SW, SH); imagecopyresampled (dest, src, dx, dy, sx, SY, DW ...)