Using PHP thumbnails and clipping graphs

Source: Internet
Author: User
Tags image identifier imagecopy imagejpeg
Using PHP thumbnails and clipping graphs
Api:
Resource Imagecreatetruecolor(int $width, int $height)
Magecreatetruecolor () returns an image identifier representing a black image with a size of x_size and y_size.

Whether this function is defined depends on the version of PHP and GD. From PHP 4.0.6 to 4.1.x as long as the GD module has been loaded this function has been in existence, but when the GD2 is not installed, PHP will send a fatal error and exit. In PHP 4.2.x This behavior instead of an error is issued instead of a warning. Other versions define this function only when the correct GD version is installed.

bool imagecopy(Resource $dst _im, resource $src _im, int $dst _x, int $dst _y, int $src _x, int $src _y, int $src _w, int $src _h)
Starts the coordinates in the src_im image from Src_x,src_y, with a width of src_w, and a portion of the height of Src_h copied to the Dst_im and dst_x locations in the dst_y image.

bool imagejpeg(Resource $image [, String $filename [, int $quality]])
Imagejpeg () creates a JPEG image from the image images with filename.

Ool Imagedestroy(Resource $image)
Imagedestroy () releases the memory associated with the image. Images are image identifiers returned by the image creation function, such as Imagecreatetruecolor ().



Http://www.cnblogs.com/xiaomia/archive/2010/11/13/1876191.html
At first, the Imagecopyresized method was used to reduce the image, and the actual operation revealed that the dryness point was very serious after the image was reduced. After the use of Imagecopysampled method, the method will re-sampling the image, the image is reduced to smooth processing, so that the clarity is greatly improved
List ($src _w, $src _h) =getimagesize ($src _img);  Get the original size $dst_scale = $DST _h/$dst _w; Target image aspect ratio $src_scale = $src _h/$src _w; Original aspect ratio if ($src _scale>= $dst _scale) {  //High $w = Intval ($src _w); $h = Intval ($dst _scale* $w); $x = 0; $y = ($src _h-$h)/3 ;} else{//over-width $h = intval ($src _h), $w = Intval ($h/$DST _scale); $x = ($src _w-$w)/2; $y = 0;} Cut $source=imagecreatefromjpeg ($src _img), $croped =imagecreatetruecolor ($w, $h) imagecopy ($croped, $source, 0,0, $x , $y, $src _w, $src _h);//Zoom $scale = $dst _w/$w; $target = Imagecreatetruecolor ($dst _w, $dst _h); $final _w = Intval ($w * $scale) ; $final _h = Intval ($h * $scale); imagecopyresampled ($target, $croped, 0,0,0,0, $final _w, $final _h, $w, $h);//Save $timestamp = time (); Imagejpeg ($target, "$timestamp. jpg"); Imagedestroy ($target);


Http://www.cnblogs.com/analyzer/articles/1267017.html
First of all, the thumbnail, it used more, the code is as follows:
 
  



In other words, the shear chart, is not to scale, but from the original image cut a small plot, compare personality. The code is as follows:
 
  
  • 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.