Use GD to generate thumbnails in php. 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, the GD extension of src, dx, dy, sx, sy, dw 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, dh, sw, sh);
ImageCopyResized ()Function in allGDIt is effective in the version, but its algorithm for scaling the image is rough, which may lead to image edge aliasing.GD 2.xAddedImageCopyResampled ()Function. the edge of the image obtained by the pixel interpolation algorithm is relatively smooth (but the speed ratio of this function isImageCopyResized ()Slow ).
Let's take a look at an example. We will quadruple this image:
$ 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, $ x, $ y, $ width, $ height );
Header('Content-Type: image/jpeg');
ImageJPEG($ Dst,'',100);
?>
SOURCE image:
Use
ImageCopyResized()Function generation result:
Use
ImageCopyResampled()Function generation result:
Obviously, the effects of the two functions are different,
ImageCopyResampled()The results generated by the function are smoother and better.
By the way, paste an effect and use ASCII to represent the image. ImageColorAt () has an interesting use, which can be checked cyclically.
The color of each pixel in the image, and then operate on the color data.
Source code:
$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);
?>
Interesting, huh, huh ..
Incluimagecopyresized (dest, src, dx, dy, sx, sy, dw, dh, sw, sh); ImageCopyResampled (dest, src, dx, dy, sx, sy, dw...