【发布时间】:2016-12-15 07:33:48
【问题描述】:
所以我的以下代码就像我上传图片一样,它会将图片大小调整为 720x450,然后添加水印。但我不希望修改宽度和高度并将水印放在任何尺寸的图像的右下角
如果有人可以在这里帮助我?
$image_path = "../images/watermark.png";
function watermark_image($oldimage_name, $new_image_name){
global $image_path;
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = 720; $height = 450;
$im = imagecreatetruecolor($width, $height);
$img_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$watermark = imagecreatefrompng($image_path);
list($w_width, $w_height) = getimagesize($image_path);
$pos_x = $width - $w_width;
$pos_y = $height - $w_height;
imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
imagejpeg($im, $new_image_name, 90);
imagedestroy($im);
unlink($oldimage_name);
return true;
}
感谢您的帮助和时间。
【问题讨论】:
标签: php image-resizing watermark