Php 合并图像并调整其大小

Php 合并图像并调整其大小,php,image,image-processing,gd,Php,Image,Image Processing,Gd,我试图将我的功能从简单地调整图像大小扩展到添加水印。问题是没有添加水印。我已经确认路径是正确的。为什么它不起作用 $image = imagecreatefromjpeg($this->getFile()); $size = getimagesize($this->getFile()); $watermark = imagecreatefrompng('../watermark.png'); $watermark_width = imagesx($wa

我试图将我的功能从简单地调整图像大小扩展到添加水印。问题是没有添加水印。我已经确认路径是正确的。为什么它不起作用

$image = imagecreatefromjpeg($this->getFile());

    $size = getimagesize($this->getFile());  

    $watermark = imagecreatefrompng('../watermark.png');
    $watermark_width = imagesx($watermark);  
    $watermark_height = imagesy($watermark);

    $dest_x = $size[0] - $watermark_width - 10;  

    $dest_y = $size[1] - $watermark_height - 5; 

    //die($watermark_width);

    $thumb_image = imagecreatetruecolor($this->getThumbWidth(), $this->getThumbHeight());

    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  

    imagecopyresampled( $thumb_image, $image, 0, 0, 0, 0, $this->getThumbResizeWidth(), $this->getThumbResizeHeight(), $this->getWidth(), $this->getHeight() );
    imagejpeg( $thumb_image, $this->getThumbDestination(), $this->getThumbQuality() );

    imagedestroy($thumb_image);
    imagedestroy($image);

发布代码后,我发现了几个错误,与我的想法相反,主要错误是watermark.png的文件路径不正确。已更新,并且对我有效。但是,alpha透明度仍然存在问题。

什么是
$dest_x
$dest_y
?你确定它们在目标映像的范围内吗?哎呀。忘了从另一个脚本复制一些代码。我认为这是水印的x和y位置?我知道它们的用途;我的意思是,当你运行代码时,它们的实际值是多少?它们都返回-5。为什么其他变量没有返回任何东西?图像的大小绝对不同。嗯。。。
$size[0]
$size[1]
$watermark\u width
$watermark\u height
的运行时值是什么?你能把它们作为注释添加到代码中吗?