molicule
molicule

Reputation: 5561

How can I rotate a transparent png by 45 degrees using imagemagick and keep the new image transparent?

I have a 16x16 transparent png and I did

convert -rotate -45 a.png b.png

This rotated it and created a new image b.png which is of size 22x22 and which when I use against a background shows the original image (16x16) rotated with the underlying background but the new filling that came about shows up with a white background.

How is it possible to have the new filling too be transparent?

If that is not possible, than how can I have all the background of the new image be one color?

Upvotes: 13

Views: 9114

Answers (5)

Mohammad Gabr
Mohammad Gabr

Reputation: 221

I used C# to rotate it

using (MagickImage mimg = new MagickImage(path))
{
  mimg.BackgroundColor = MagickColor.Transparent;
  mimg.Alpha(AlphaOption.Background);
  mimg.AlphaColor = new MagickColor(System.Drawing.Color.White);
  mimg.FillColor = new MagickColor(255, 255, 255, 0);
  mimg.Rotate(degree);                    
}

Upvotes: 0

nak
nak

Reputation: 3137

I was also having the same issue, however I was using the command like so:

convert a.png -rotate 45 -background transparent b.png

It needed to be:

convert -rotate 45 -background transparent a.png b.png

So, this actually helped a little, thanks :)

Upvotes: 4

sukinsan
sukinsan

Reputation: 513

convert -rotate 66 -background none c:\input.png c:\output.png

works well for me

Upvotes: 1

Ingvi Gautsson
Ingvi Gautsson

Reputation: 151

Use the -background option to specify a transparent color with alpha set to zero:

convert -background 'rgba(0,0,0,0)' -rotate 45 a.png b.png

Upvotes: 15

uFarooq
uFarooq

Reputation: 181

You can also use these options:

  -background none

Upvotes: 10

Related Questions