Imagecreatefrom * image loading Function
// Image with different suffix names
Imagecreatefromgif
Imagecreatefromjpeg
Imagecreatefrompng
Imagecreatefromwbmp
Imagecreatefromstring
Format: imagecreatefromgif ("jjj.gif ");
2. imagecopy image merging function
Imagecopy (destimage, simage, int X, int y, int src_x, int src_y, int src_w, int src_h );
Destimage --- original image (large image)
Simage --- logo image (small image)
X --- coordinates of the original image
Y ---
Src_x --- coordinates of the logo image
Src_y ---
Src_w --- logo image width
Src_h --- logo image height
3. imagecopyresized
Imagecopyresized (resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h );
Dst_image --- original true color image
Src_image --- Original Image
Dst_x --- generally 0 from where
Dst_y --- generally 0
Src_x --- starting from where the cut is generally 0
Src_y --- generally 0
Dst_w --- width and height of the new image
Dst_h ---
Src_w --- width and height of the original image
Src_h ---
Example:
Image. php CopyCode The Code is as follows: <? PHP
/*
* This PHP file provides image watermarks and thumbnails.
*
*/
// This Is Not A write upload function. First, place the image to the project root directory.
// Import and parse Images
$ Image = "img.jpg ";
$ IMG = getimagesize ($ image );
// Determine the suffix of the image
Switch ($ IMG [2]) {
Case 1:
$ Im = imagecreatefromgif ($ image );
Break;
Case 2:
$ Im = imagecreatefromjpeg ($ image );
Break;
Case 3:
$ Im = imagecreatefrompng ($ image );
Break;
}
// Parse the image
$ Logo = "pic.jpg ";
$ PIC = getimagesize ($ logo );
Switch ($ PIC [2]) {
Case 1:
$ Im_pic = imagecreatefromgif ($ logo );
Break;
Case 2:
$ Im_pic = imagecreatefromjpeg ($ logo );
Break;
Case 3:
$ Im_pic = imagecreatefrompng ($ logo );
Break;
}
// Image synthesis, which is also a watermark
Imagecopy ($ im, $ im_pic, 0,500, 75 );
// Set the color
$ Fc = imagecolorallocate ($ im, 255,255,255 );
// First, convert the text to UTF-8 format
// $ STR = iconv ("gb2312", "UTF-8", "heheh ");
// Add a Chinese watermark
Imagettftext ($ im, 12, 0, 20, 20, $ FC, "simkai. TTF", "My QQ: 260954520 ");
// Create an original true color image
$ New_img = imagecreatetruecolor (50, 40 );
// Cut the image
Imagecopyresized ($ new_img, $ im, 0, 0, 0, 50, 40, $ IMG [0], $ IMG [1]);
// Output image
Header ("Content-Type: image/JPEG ");
// The cropped thumbnail, which can be generated using the following judgment
Imagejpeg ($ new_img );
// Generate a watermark image
/*
If (imagejpeg ($ im, "New Image .jpg ")){
Echo "watermark successful ";
}
*/
?>