合并图像并调整其大小

时间:2013-01-10 19:43:48

标签: php image image-processing gd

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

$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);

1 个答案:

答案 0 :(得分:0)

在发布代码后,我发现了一些错误,与我的看法相反,主要的错误是watermark.png的错误文件路径。它已更新,对我有用。但是,Alpha透明度仍然存在问题。