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