-rotate jpeg leaves jagged edges

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Zelf
Posts: 12
Joined: 2015-05-12T11:14:41-07:00
Authentication code: 6789

-rotate jpeg leaves jagged edges

Post by Zelf »

You can see that -rotate 22 ends up with jagged edges.

Image

Code: Select all

convert treefrog.jpg -background transparent -rotate 22 -antialias -resize 340x440 -gravity Center -background transparent -extent 350x450 treefrog.rotated.png
How do I get rid of the jagged edges?

If I convert to png it is fine, but I want the resultant image to be jpeg.

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -rotate jpeg leaves jagged edges

Post by fmw42 »

Please post your input image and (always) provide your IM version and platform.

Note: PNG supports transparency and thus 8-bit alpha (for antialiasing the boundary). JPG does not support alpha.

-antialias does nothing in this command. Try flattening against black first. You also need to add +repage after the rotate to remove the virtual canvas.

Code: Select all

convert treefrog.jpg -background transparent -rotate 22 +repage -resize 340x440 -gravity Center -background transparent -extent 350x450 -background black -flatten result.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -rotate jpeg leaves jagged edges

Post by snibgo »

When an image has transparency but you want to save it as JPEG, which can't record transparency, I suggest you explicitly flatten it first, eg "-background Black -layers flatten". This will keep the anti-aliasing.

If you don't flatten it, IM will simply remove the alpha channel, creating jaggies.
snibgo's IM pages: im.snibgo.com
Zelf
Posts: 12
Joined: 2015-05-12T11:14:41-07:00
Authentication code: 6789

Re: -rotate jpeg leaves jagged edges

Post by Zelf »

@fmw42, I knew I should put my info in there. Missed it in my haste to post problem.

ImageMagick 6.9.1-9

Original image: Image

Your command worked. Thank you.

@snibgo, thank you for the understanding I was lacking. I get it now.
Last edited by Zelf on 2017-09-27T12:42:08-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -rotate jpeg leaves jagged edges

Post by fmw42 »

See my command above.
Post Reply