1

我目前正在使用带有 Imagick 扩展版本 1620 的 imagemagick 版本 ImageMagick 6.8.4-6 2013-04-04 Q16

我正在尝试旋转 jpg 图像并将其合并到另一个 jpg 图像中,但是当我合并图像时,我会在图像周围出现一个黑框。

请参阅下面我使用的代码:

public function image($images,$x,$y,$angle){

        if($images != "" && $images != NULL){
         $base = $this->instance;
         $layer = new Imagick($images);

         //resize image

         if($this->id == 45){
             $layer->scaleImage(329,0);
         }
         if($this->id == 44){
            $layer->scaleImage(280,0);
         }
         if($this->id == 42){
            $layer->scaleImage(350,0);
         }

         //rotate image

         $layer->rotateImage(new ImagickPixel("none"), $angle);

         //Merge Image
         if($this->id == 44){
          $base->compositeImage($layer, imagick::COMPOSITE_OVER, $x, $y);
         }else{
          $base->compositeImage($layer, imagick::COMPOSITE_DEFAULT, $x, $y);
         }

         $this->image = $base;
        }


    }

当 $this->id 使用 44 时,当前正在运行测试。任何人都可以阐明这个问题吗?提前致谢

4

2 回答 2

1

您需要使用imagecolortransparent才能具有透明度功能。

NB JPG没有透明属性,只有PNGGIF文件(和TIFF),但浏览器不支持该格式。

Your output file will need to be converted to one of those formats, preferably PNG then set the transparency for the desired color.

"so would you suggest converting to PNG then rotating? then merging the PNG image into the JPG (if it is possible) as the image output is required to be a jpg"

You will lose transparency as soon as you resave as JPG

于 2013-09-13T14:32:10.210 回答
0

I came across this via Google, here's the correct answer as others may find it. You need to use setImageMatte(1) to enable the transparency, e.g.

$src->setImageMatte(1); 
$mask->rotateImage(new ImagickPixel('#00000000'), 10); 

You may also use an image Mask, where black will become transparent using

$src->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
于 2015-09-15T13:11:42.727 回答