PHP image functions

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_68b56adb0100vq1a.html

Photo Album program, image thumbnail generation is a necessary function, with the PHP GD function for the image generated thumbnails is very simple, the core is a

The imagecopyresampled function. The main trouble is to consider the image of various long, wide, zoom ratio and so on.

if the quality of the thumbnail is not high, you can use the imagecopyresized () function, the image generated by Imagecopyresize () is coarser, but faster; the imagecopyresampled () function is GD 2. After X, the newly added function, literally meaning that the image will be resampled (resampling),GD uses an interpolation algorithm to produce a smoother image , but the speed is slower relative to the imagecopyresize () function.
Imagecopyresample () A total of 10 parameters, the first two are the target file and the source file, the following 4 are DST and SRC width,height, the middle of the src_x,src_y,dst_x,dst_y look more faint. Examples are set to 0, and then try to find the 4 parameters written dst_start_x, dst_start_y, src_start_x, src_start_y words are very good understanding. Let me give you an example. If you want to leave a blank in the thumbnail, you can use Imagecopyresampled ($DST, $SRC, dst_start_x, Dst_start_y + ten, src_start_x, src_start_y, DST Pixel _width, dst_height–20, Src_width, src_height) to achieve.

The imagecreatetruecolor (int x,int y) is a black image of size x and Y (black by default), which requires a fill color function Imagefill ($img, 0,0, $color) If you want to change the background color;

Imagecreate Create a new blank image resource, add a background color with imagecolorallocate ()

<?php
$img =imagecreatetruecolor (100,100);

Create a true Color image resource
$color =imagecolorallocate ($img, 200,200,200); Assign a gray
Imagefill ($img, 0,0, $color); Fill in gray from top left corner
Header (' Content-type:image/jpeg '); JPG format
Imagejpeg ($IMG); Show Gray Squares
?>

<?php
$img = Imagecreate (100,100);
$color = Imagecolorallocate ($img, 200,200,200);
Header (' Content-type:image/jpeg ');

JPG format
Imagejpeg ($IMG); Show Gray Squares
?>

PHP image functions

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.