Home > Article > Backend Development > Example of how to add watermark to images in php
This article mainly shares with you an example of adding watermarks to php images, which has certain reference value. Interested friends can refer to
Adding watermarks to images. I believe all friends know it. Today we will look at an example of adding watermarks to pictures in PHP. I hope this article can help you all.
<?php /** * 图片添加水印 * $target 源文件路径 * $wtrmrk_file 水印图片路径 * $newcopy 添加水印后的图片路径 * */ public function watermark_image($target, $wtrmrk_file, $newcopy) { $watermark = imagecreatefrompng($wtrmrk_file); imagealphablending($watermark, false); imagesavealpha($watermark, true); $img = imagecreatefromjpeg($target); $img_w = imagesx($img); $img_h = imagesy($img); $wtrmrk_w = imagesx($watermark); $wtrmrk_h = imagesy($watermark); $dst_x = ($img_w ) – ($wtrmrk_w); // For centering the watermark on any image //phpfensi.com $dst_y = ($img_h) – ($wtrmrk_h ); // For centering the watermark on any image imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h); imagejpeg($img, $newcopy, 100); imagedestroy($img); imagedestroy($watermark); //return $img; } ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Detailed explanation of the steps to generate data dictionary in PHP
##phpFramework CodeIgniter database Detailed explanation of the configuration steps
php7 Detailed explanation of the use of new features
The above is the detailed content of Example of how to add watermark to images in php. For more information, please follow other related articles on the PHP Chinese website!