How do I change the black background color to transparent?

I rotate the image using Image Magick (since PHP-GD scales the image down).

But it leaves the background black. Also, the image doesn't look good (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 is the image I am trying to rotate -

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

Thanks for the answer guys :-)

+2


a source to share


2 answers


After creating an Imagick object in it, the arguments set a transparent background:



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

      

+1


a source


Rotate the image as follows:

$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 repression to center the image on the canvas, but I don't know why you need values ​​as Imagemagick doesn't use them. The only way I can think of automatically adjusting the values ​​is to get the image size after cropping and use it to reset.

With all I have to suggest, start with a larger image and scale it down after rotating and see if that helps; maybe use some sharpness. But I don't think it will help much as the lines are so thin and close together.

+1


a source







All Articles