0

Hi I'm porting a script from a windows environment running MagickWand 0.1.8 and ImageMagick 6.2.9 where transparency worked fine with MagickRotateImage.

New environment is linux running MagickWand 1.0.8 with ImageMagick 6.5.4-7 and transparency gets lost and it shows black as the background as soon as my logo image gets rotated.

From what I've found online, seems that PixelSetColor($bg,"none") doesn't work with the newer versions hence the black. Ultimately, I need to know what to replace PixelSetColor($bg,"none") with. I just don't have a background in image creation so struggling a bit with this.

First my php runs this function which makes a local 60x60 version of 600x600 png image gotten from a url.

function makeThumb($fileContents){
    GLOBAL $localImgPath1;
    GLOBAL $localImgPath2;
    $wand = NewMagickWand();
    $lg = MagickReadImageBlob($wand,$fileContents);
    $lg_w = MagickGetImageWidth($wand);
    $lg_h = MagickGetImageHeight($wand);
    $max = max($lg_h,$lg_w);
    $scale_factor = 60/$max;
    MagickResizeImage($wand,$lg_w*$scale_factor,$lg_h*$scale_factor, MW_GaussianFilter, .7);
    MagickWriteImage($wand, $localImgPath1);
    if($localImgPath2!="")
        MagickWriteImage($wand, $localImgPath2);
    $resized_w = MagickGetImageWidth($wand);
    $resized_h = MagickGetImageHeight($wand);
    DestroyMagickWand($wand);
}

then, I use this to read that locally written png image and rotate it:

$logo = NewMagickWand();
$bg = NewPixelWand();
PixelSetColor($bg,"none");
MagickReadImage($logo, $localImgPath1);
MagickRotateImage($logo, $bg, $r);
header('Content-Type: image/PNG');
MagickEchoImageBlob($logo);
DestroyPixelWand($bg);
DestroyMagickWand($logo);

I've tried things like adding:

$transparent = NewPixelWand("#FFFFFF");
PixelSetAlpha($transparent, 0);
//and then making the rotate call:
MagickRotateImage($logo, $transparent, $r);

Also tried adding MagickSetImageAlphaChannel($logo, MW_SetAlphaChannel); before the rotate step. Saw some posts mentioning that method but possibly that's not the correct way to use it. Not sure.

I also have the same problem in a script that draws a text string with a set font onto the image. Black immediately shows there even before rotation is applied so hoping same fix for the logo script will be useable by the font script.

Any help would be greatly appreciated. Thanks.

4

2 に答える 2

0

透明な背景には 4 つの値から選択できます。それぞれを順番に試してください:

"none", "transparent", "#00000000", or "rgba(0, 0, 0, 0.0)"
于 2013-04-10T18:25:39.073 に答える