Question

I want to rotate an image with transparent background fill to uncovered zone.

I refereed this official documentation with syntax

// Rotate
$rotate = imagerotate($source, $degrees, 0);

but did not get success.

After rotation I am getting image with black color fill to uncovered zone. like below

enter image description here

Original image is here

I also have tried below command

$> convert -rotate 5 image.png image_rotated.png

Reference is this

Above command I have used on png and jpg image, but I didn't get fruits..

Now I don't know where the things are going wrong ?? is there any problems with versions of library I am using ??

My php version is PHP 5.4.9-4ubuntu2.4

Thanks in advance.

Was it helpful?

Solution

Following command worked for me on Debian wheezy 7.5 with mageMagick 6.7.7-10.

convert -background "rgba(0,0,0,0)" -rotate 5 images.jpg new.png

Specify -background "rgba(0,0,0,0)" it will set transparent background fill for output image. Also make sure to save output image in .png format (which supports transparency)

Hope It will help. :)

Note: By default -rotate option uses Black color to fill background.

EDIT:

Make sure imagemagick package is installed properly.

check version details:

$convert --version
Version: ImageMagick 6.7.7-10 2014-03-08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP 

If you are not getting similar output try checking for installation of package.

$sudo dpkg --get-selection | grep imagemagick

You might want to install that if its status is deinstalled in output of above command.

$sudo apt-get install imagemagick

OTHER TIPS

since you are using php, I assume you will accept css code as answer? add these css to your image and it'll tilt

/* Firefox */
-moz-transform:rotate(45deg);
/* Safari and Chrome */
-webkit-transform:rotate(45deg);
/* Opera */
-o-transform:rotate(45deg);
/* IE9 */
-ms-transform:rotate(45deg);

edit: so not css huh, try this instead

$source = imagerotate($source,$degree,0XFFFFFF00,0); //<-- FFFFFF00 = RRGGBBAA
//you might not need to disable blending, try if it's not working
//imagealphablending($source, false);
imagesavealpha($source, true);
//then user $source however you want
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top