Hello everyone, I am Huang Ahma, and today I will tell you how to add watermarks to pictures in tp.
Before this, I tried it myself, adding text directly to the picture, but it backfired, and there would always be garbled characters, no matter how I set it, it would not work, unless I set the font, but the font is most afraid of copyright issues or incompatibility, so I am rough and add image watermark directly on the image.
Not much nonsense, just go to the code
/**
* @param $sourcePath
* @param $logoPath
* @param $savePath
* 给图片加水印
*/
function addImageWater($sourcePath,$logoPath,$savePath){
$img_info = getimagesize($sourcePath);
$im = null;
if($img_info[2]==3){
$im = imagecreatefrompng($sourcePath);
}else{
$im = imagecreatefromjpeg($sourcePath);
}
$watermark = imagecreatefrompng($logoPath);
//获取图、水印 宽高类型
list($bgWidth, $bgHight, $bgType) = getimagesize($sourcePath);
list($logoWidth, $logoHight, $logoType) = getimagesize($logoPath);
//定义平铺数据
$x_length = $bgWidth-10; //x轴总长度
$y_le