12

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?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
molicule
  • 5,481
  • 3
  • 29
  • 40

5 Answers5

15

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

Ingvi Gautsson
  • 151
  • 1
  • 5
9

You can also use these options:

  -background none
reuben
  • 3,360
  • 23
  • 28
uFarooq
  • 171
  • 2
  • 3
  • FYI: Depending on how ImageMagick is installed an configured, `-background none' might result in an error like `convert: unable to access configure file `colors.xml' @ warning/configure.c/GetConfigureOptions/589.`. This happens when ImageMagick can't find a config file because of where things are installed. If you run into that, you can use `-background 'rgba(0,0,0,0)'` instead. – Alan W. Smith Feb 12 '13 at 03:07
3

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 :)

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
nak
  • 3,077
  • 3
  • 27
  • 35
1
convert -rotate 66 -background none c:\input.png c:\output.png

works well for me

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
sukinsan
  • 513
  • 3
  • 14
0

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);                    
}
dlemstra
  • 7,813
  • 2
  • 27
  • 43
Mohammad Gabr
  • 221
  • 2
  • 5
  • I don't think you need the Alpha, AlphaColor and FillColor calls in it. You just need to make sure to set BackgroundColor to transparent *before* rotating. – caiosm1005 Dec 23 '21 at 12:49