difference | Thumbnail PHP's GD extension provides two functions to scale images:
Imagecopyresized (destsrcdxdysxsyDWDH SWsh);
Imagecopyresampled (destsrcdxdysxsyDW dhSWSH
The imagecopyresized () function is valid in all versions of GD, but its algorithm for scaling the image is coarse and may cause jagged edges of the image. GD 2.x has a new imagecopyresampled () function, its pixel interpolation algorithm to get the edge of the image is relatively smooth (but the function is faster than imagecopyresized () slow).
To see an example, we'll shrink this figure four times times:
<?php
$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,'',100);
?>
原图:
使用
ImageCopyResized()函数生成的结果:
使用
ImageCopyResampled()函数生成的结果:
It's obvious to see that two functions produce different image effects,
ImageCopyResampled()函数生成的结果比较平滑,效果较好。
By the way, you put an effect in ASCII to represent the image. Imagecolorat () has a very interesting use, it can be cycled check
The color of each pixel in the image, and then manipulate the color data.
Source:
<body bgcolor= "#000000" style= "line-height:6pt" ><?php
$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 (' <font color=#%02x%02x%02x>*</font> ',
$rgb [' Red '], $rgb [' Green '], $rgb [' Blue ']]);
}
echo "<br>\n";
}
Imagedestroy ($im);
?>
</body>
It's funny, huh?