php实现图片合并

<?php //$qrc 原图 //$bg 背景图 //$new 新图 //$text 文字 //$font 字体 function mergeImages($qrc, $bg, $new, $text, $font) { //创建图片的实例 $dst = imagecreatefromstring(file_get_contents($bg)); $src = imagecreatefromstring(file_get_contents($qrc)); //获取覆盖图图片的宽高 list($src_w, $src_h) = getimagesize($qrc); //将覆盖图复制到目标图片上,最后个参数100是设置透明度(100是不透明),这里实现不透明效果 imagecopymerge($dst, $src, 1200, 210, 0, 0, $src_w, $src_h, 100); //位置可以自己调试 imagepng($dst, $new);//根据需要生成相应的图片 imagedestroy($dst); imagedestroy($src); $image = imagecreatefrompng($new); if ($text && $font) { $color = imagecolorallocate($image, 0, 0, 0); // 文字颜色 imagettftext($image, 40, 0, 250, 600, $color, $font, $text);// 创建文字 } imagepng($image, $new); return $new; }
Last modification:August 19, 2022
如果觉得我的文章对你有用,请随意赞赏