PHP from 0 single row (18) image processing

Source: Internet
Author: User
Tags imagejpeg
PHP from 0 single row (18) image processing 1. open an existing image & lt ;? Phpheader (& quot; Content-type: imagejpeg"{{imgimagecreatefrom=("cc.jpg & quot;); imagejpeg ($ img); imagedestroy ($ img );? & Gt; function imagecreatef PHP image processing from 0 to 18

1. open an existing image

 
The parameter of the imagecreatefromjpeg () function is the path of the file. the returned value is the resource identifier of the image referred to by the parameter. This function creates an image through an existing image instead of simply opening the original image. If you change the image extension .jpg to .png, you cannot open the file even if you use the imagecreatefrompng () function, because the image is still in jpg format.

2. get image attributes

 $ XPixels "; echo"
"; Echo"
"; Echo" the height of the cc.jpg image is:$ YPixels ";?>

In addition, a function getimagesize () that does not belong to the GD library can be used to obtain image size and other related attributes. the syntax of this function is as follows:

Array getimagesize (string $ filename [, array & imageinfo])

 ";}?>
The third element is the image format. its value is as follows:

1: indicates that the image is in GIF format.

2: The image is in JPG format.

3: The image is in PNG format.

4: The image is in SWF format.

5: The image is in PSD format.

6: The image is in BMP format.

 "
 >

3. add watermarks to images

· Obtain the width and height of the image to add a watermark

· Determine whether the image size meets the watermark text size

· Determine the position of the watermark effect in the image

· Set the mixed color mode of the image

· Generate watermark effect

· Release resources

 0) {$ uploadfile = ". /". time (). "_". $ _ FILES ['userfile'] ['name']; if (copy ($ _ FILES ['userfile'] ['tmp _ name'], $ uploadfile )) {makeimagewatermark ($ uploadfile, 2, "Photo by Mac", 16, "# ipv42a"); echo "" ;}else {echo "uploadWrong!
";}}?>19.9.php

4. generate thumbnails of existing images

 
The first and second parameters are the identifier of the target image and the original image respectively. the next four parameters are the coordinates of the copying position of the target image and the original image, the last four parameters are the width and height of the target image and the original image copy area.
!! Use the imagecopyresampled () function

 




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.