Home  >  Article  >  Backend Development  >  PHP image watermark program, PHP gd library to add image watermark

PHP image watermark program, PHP gd library to add image watermark

WBOY
WBOYOriginal
2016-07-25 08:51:501070browse
PHP watermark code for images, PHP image watermark example, you can set the upload file size limit, set whether to attach a watermark, set the watermark position, watermark string and watermark image, whether to generate a preview image, etc.

Example, php image watermark code.

Picture watermarking program - bbs.it-home.org
upload files:

The file types allowed to be uploaded are:=implode(', ',$uptypes)?>

This demonstration space is provided by TuWoo, this program uses text watermark.
Successfully uploaded
File name: ".$destination_folder.$fname."
"; echo "Width:".$image_size[0]; echo "length:".$image_size[1]; echo "
size:".$file["size"]." bytes"; if($watermark==1) { $iinfo=getimagesize($destination,$iinfo); $nimage=imagecreatetruecolor($image_size[0],$image_size[1]); $white=imagecolorallocate($nimage,255,255,255); $black=imagecolorallocate($nimage,0,0,0); $red=imagecolorallocate($nimage,255,0,0); imagefill($nimage,0,0,$white); switch ($iinfo[2]) { case 1: $simage =imagecreatefromgif($destination); break; case 2: $simage =imagecreatefromjpeg($destination); break; case 3: $simage =imagecreatefrompng($destination); break; case 6: $simage =imagecreatefromwbmp($destination); break; default: die("Unsupported file type"); exit; } imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]); imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white); switch($watertype) { case 1: //Add watermark string imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black); break; case 2: //Add watermark image $simage1 =imagecreatefromgif("xplore.gif"); imagecopy($nimage,$simage1,0,0,0,0,85,15); imagedestroy($simage1); break; } switch ($iinfo[2]) { case 1: //imagegif($nimage, $destination); imagejpeg($nimage, $destination); break; case 2: imagejpeg($nimage, $destination); break; case 3: imagepng($nimage, $destination); break; case 6: imagewbmp($nimage, $destination); //imagejpeg($nimage, $destination); break; } //Overwrite the original uploaded file imagedestroy($nimage); imagedestroy($simage); }

if($imgpreview==1) { echo "
Picture preview:
"; echo "PHP image watermark program, PHP gd library to add image watermark"; } } ?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn