Php text watermark and thumbnail implementation code. ImageCreateFrom * the image loading function loads images with different suffixes: imagecreatefromgifimagecreatefrom?imagecreatefrompngimagecreatefromwbmp imagecreatefromstring in the format of imageCreateFrom *.
// 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
The code is as follows:
/*
* 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 ";
}
*/
?>
ImageCreateFrom * image loading function // use the format of imagecreatefromgif imagecreatefromjpeg imagecreatefrompng imagecreatefromwbmp imagecreatefromstring for different suffixes...