开发者

How to change the background black color to transparent?

开发者_开发百科I am rotating an image using Image Magick (as PHP-GD scales down image).

But it leaves the background to be black. Also, the image doesn't look good at all(but better than PHP-GD).

Any suggestions?

@oren , @razzed Here's the code

$patchImageS        =   'kapeels.png'; // the image to be patched over the final bg
$imagick            =   new Imagick();     $imagick->readImage($patchImageS);
$imagick->rotateImage(new ImagickPixel(), 355);
$imagick->transparentPaintImage('black', 0.0,0,false);
header('content-type:image/png');
$fp=fopen('tts.png','w+'); 
fwrite($fp,$imagick->getImage()); 
fclose($fp);

And this's the image which I am trying to rotate -

http://www.lilpirate.net/kapeels.png

Thanks for the reply guys :-)


After create Imagick object, in him arguments set a background transparent:

$imagick->newimage($width, $height, "rgba(0, 0, 0, 0)");


Rotate the image like this:

$im = new Imagick('kapeels.png'); 
$im->rotateImage( new ImagickPixel('none'), 7 ); 
$im->trimImage ( 0 ); 
$im->resetImagePage( '216x174+0+0' ); 
$im->writeImage('rotateImage.png');  
$im->destroy(); 

You need thr repage to center the image back on the canvas but I do not know why you need values as Imagemagick does not use them. The only way I can think of automatical setting the values is to get the image size after the trim and use that in the reset.

With the quility all I could suggest is start with a larger image and reduce it after the rotate and see if that helps; perhaps use some sharpening. But I do not think much will help as the lines are so thin and close together.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜