Use the PHP thumbnail and cut graph

Source: Internet
Author: User
Use the PHP thumbnail and cut Graph API: resourceimagecreatetruecolor (int $ width, int $ height) magecreatetruecolor () to return an image identifier, representing a black image of x_size and y_size. Whether the use of PHP thumbnails and cut charts are defined
API:
Resource imagecreatetruecolor (int $ width, int $ height)
Magecreatetruecolor () returns an image identifier, representing a black image of x_size and y_size.

Whether this function is defined depends on the PHP and GD versions. From PHP 4.0.6 to 4.1.x, as long as the GD module is loaded, this function always exists, but it is called when GD2 is not installed, PHP will issue a fatal error and exit. In PHP 4.2.x, this behavior is changed to warning rather than error. This function is defined only when the correct GD version is installed in other versions.

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)
Copy the coordinates of the src_im image from src_x, src_y, src_w in width, and src_h in height to the position where the coordinates of dst_im are dst_x and dst_y.

Bool imagejpeg (resource $ image [, string $ filename [, int $ quality])
Imagejpeg () creates a JPEG image with filename as the file name from the image.

Ool imagedestroy (resource $ image)
Imagedestroy () releases the memory associated with the image. An image is the identifier returned by the image creation function, for example, imagecreatetruecolor ().



Http://www.cnblogs.com/xiaomia/archive/2010/11/13/1876191.html
At first, the imagecopyresized method was used for image proportional reduction. after the actual operation, it was found that the dry points were very serious after the image was reduced. Then use the imagecopysampled method. this method will re-sample the image and perform smooth processing on the reduced image to greatly improve the definition.
List ($ src_w, $ src_h) = getimagesize ($ src_img); // Obtain the source image size $ dst_scale = $ dst_h/$ dst_w; // target image aspect ratio $ src_scale = $ src_h/$ src_w; // source image aspect ratio if ($ src_scale> = $ dst_scale) {// too high $ w = intval ($ src_w ); $ h = intval ($ dst_scale * $ w); $ x = 0; $ y = ($ src_h-$ h)/3 ;} else {// too wide $ h = intval ($ src_h); $ w = intval ($ h/$ dst_scale); $ x = ($ src_w-$ w)/2; $ y = 0;} // crop $ source = imagecreatefromjpeg ($ src_img); $ croped = imagecreatetruecolor ($ w, $ h); imagecopy ($ croped, $ source, 0, 0, $ x, $ y, $ src_w, $ src_h); // scale $ 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, "success"); imagedestroy ($ target );


Http://www.cnblogs.com/analyzer/articles/1267017.html
Let's talk about the thumbnail. it is used a lot. the code is as follows:
  



To cut a graph, you just cut a small image from the source image without scaling. The code is as follows:
 

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.