Two choices and differences for generating thumbnails with GD under PHP _php tutorial

Source: Internet
Author: User
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 ...)

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.