Home >Backend Development >PHP Tutorial >PHP adds text watermark and image watermark code to pictures (1/3)_PHP tutorial
Add text watermark and image watermark code to pictures with php When this program adds text watermarks to pictures, it calls the C:\WINDOWS\Fonts\SIMHEI.TTF font. When adding watermarks to pictures, you can customize the pictures.
php tutorial to add text watermark and image watermark code to pictures
When this program adds text watermarks to pictures, it calls the c:windowsfontssimhei.ttf font. When adding watermarks to pictures, you can customize the pictures.
$image->wprint_img();//Execute image watermark
$image->wprint_string();//Execute text watermark
*/
class editimage{
private $imagefile; //Image file
private $smallimg;//Watermark image
private $string;//watermark text
private $position;//storage location
private $dst_x=600;//Original image watermark x coordinate
private $dst_y=0; //Original picture watermarked y coordinate
private $str_x=450;
private $str_y=200;
private $font="c:windowsfontssimhei.ttf";//Original picture watermark font path
private $imgej;//Variables after imagecolorallocate
function __get($value){
Return $this->$value;
}
function __set($property,$value){
$this->$property=$value;
}
/**
*Constructor initialization
*
* @param string $imagefile The watermarked file
* @param string $smallimg watermark file
* @param string $string watermark text
* @param string $position storage location
* @param int $dst_x The watermarked picture x
* @param int $dst_y The watermarked picture y
*/
function __construct($imagefile,$smallimg='',$string=''){//,$position='',$dst_x=0,$dst_y=0
$this->imagefile=$imagefile;
$this->smallimg=$smallimg;
$this->string=$string;
$this->imgej=$this->imagecreatef($this->imagefile);
}function get_extname($file){//Get the suffix name of the file
if (file_exists($this->imagefile)) {
$img=getimagesize($file);
switch ($img[2]){
case "1":
Return "gif";
case "2":
Return "jpg";
case "3":
Return "png";
}
}else{
Return false;
}
}
1 2 3