Simple PHP Picture Scaling Code _php Tutorial

Source: Internet
Author: User
I used getimagesize to get the size of the original image and then x0.5 the picture/5 Oh.

Array getimagesize (string $filename [, Array & $imageinfo])
The getimagesize () function will determine any gif,jpg,png,swf,swc,ps tutorials D,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM or wbmp The size of the image file and returns the size of the image as well as the file type and a height/width text string that can be used in markup in normal HTML files.
If the image specified by filename cannot be accessed or is not a valid image, GetImageSize () returns false and produces an e_warning level error

*/
Define a file
$filename = ' 1.jpg ';
$percent = 0.5;
Send header File
Header (' Content-type:image/jpeg ');
Get the size of an image
List ($width, $height) =getimagesize ($filename);
Define a new size
$new _width= $width * $percent;
$new _height= $height * $percent;
$image _p=imagecreatetruecolor ($new _width, $new _height);
/*
: int imagecreate (int x_size, int y_size);

return value: Integer

Content Description


This function is used to create an all-empty graph. The parameter x_size, Y_size is the size of the graph, in pixels (pixel).

*/
$image =imagecreatefromjpeg ($filename);

/*
Resource Imagecreatefromjpeg (string filename) imagecreatefromjpeg () returns an image identifier that represents the image obtained from the given file name. Imagecreatefromjpeg () returns an empty string on failure and outputs an error message that unfortunately appears as a broken link in the browser. To alleviate the debugging work The following example produces an error JPEG:
*/
Imagecopyresampled ($image _p, $image, 0,0,0,0, $new _width, $new _height, $width, $height);

/*
): Imagecopyresamples (), the pixel interpolation algorithm gets a smoother image edge. Good quality (but the function is slower than imagecopyresized ().) The parameters of the two functions are the same. as follows: Imagecopyresampled (DEST,SRC,DX,DY,SX,SY,DW,DH,SW,SH);
*/
Output image
Imagejpeg ($image _p, NULL, 100);
/*
Executing this code will scale the original image by 50% and output it as a new image
*/

http://www.bkjia.com/PHPjc/632993.html www.bkjia.com true http://www.bkjia.com/PHPjc/632993.html techarticle I used getimagesize to get the size of the original image and then x0.5 the picture/5 Oh. Array getimagesize (string $filename [, array $imageinfo]) the getimagesize () function will measure any ...

  • 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.