PHP image text mixed watermark and thumbnail code
- 2020-03-31 17:01:06
- OfStack
ImageCreateFrom * image loading function
// for different suffixes
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromwbmp
imagecreatefromstring
Format: imagecreatefromgif(" jj.gif");
Imagecopy image merge 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 picture (small picture)
X -- the coordinates of the original picture
Y -- -- --
Src_x -- coordinates of logo image
Src_y -
Src_w -- width of logo image
Src_h -- height of logo image
Three imagecopyresized image shearing function
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 -- the original image
Dst_x -- where does dst_x normally start
Dst_y -- is usually 0
Src_x -- where do we start
Src_y -- well, it's usually 0
Dst_w -- new image width and height
Dst_h -
Src_w -- the width and height of the original image
Src_h -
Examples:
Image. PHP
// for different suffixes
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromwbmp
imagecreatefromstring
Format: imagecreatefromgif(" jj.gif");
Imagecopy image merge 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 picture (small picture)
X -- the coordinates of the original picture
Y -- -- --
Src_x -- coordinates of logo image
Src_y -
Src_w -- width of logo image
Src_h -- height of logo image
Three imagecopyresized image shearing function
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 -- the original image
Dst_x -- where does dst_x normally start
Dst_y -- is usually 0
Src_x -- where do we start
Src_y -- well, it's usually 0
Dst_w -- new image width and height
Dst_h -
Src_w -- the width and height of the original image
Src_h -
Examples:
Image. PHP
<?php
//This does not write upload function, first put the picture in the project's 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;
}
//Resolution images
$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;
}
//Picture synthesis, also make watermark
imagecopy($im,$im_pic,0,500,0,0,100,75);
//Set the color
$fc=imagecolorallocate($im,255,255,255);
//First, convert the text to utf-8 format
//$STR =iconv("gb2312","utf-8"," hehehe ");
//Add 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);
//Shear pictures
imagecopyresized($new_img,$im,0,0,0,0,50,40,$img[0],$img[1]);
//The output image
header("Content-type:image/jpeg");
//After cutting the small figure, can be like the following judgment to generate a small figure
imagejpeg($new_img);
//Generate a watermarked image
?>