"-distort resize" followed by "-flatten" causes a strange 2px border

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
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

"-distort resize" followed by "-flatten" causes a strange 2px border

Post by sas »

This command:

Code: Select all

convert  netscape:  -distort resize 100x100!  -flatten  x.png
Results in this image for me:
Image
Note the image size of 102x102, and a 2px green border on the bottom and right egde.

When I run the same command with "-resize" instead of "-distort resize", I get a 100x100 image without border:
Image

I would have expected both commands to produce a 100x100 image without border.
Why is -distort resize behaving differently, and how can I prevent it?
(I prefer to use -distort resize because of the better result quality, especially when upscaling.)

ImageMagick version: 6.9.2-6 Q16 x86_64 2015-12-06, on Linux.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by magick »

Remove the virtual canvas:
  • convert netscape: -distort resize 100x100! +repage -flatten x.png
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by sas »

That seems to work in my case, thanks!

I'm still a little worried about the "-distort resize" behavior though, since I don't understand why it happens.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by magick »

The extra pixels come from the -flatten option, not -distort. The -flatten option respects any virtual canvas.
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by sas »

But "-distort" is responsible for extending the virtual canvas in this strange way, isn't it?
Is it supposed to do that?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by magick »

The -distort resize option is a special case for distort, it does not extend the virtual canvas.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by fmw42 »

.
I believe there is a problem with -distort resize. The resulting image virtual canvas is indeed 102x102+0+0 rather than 100x100+0+0.

Code: Select all

convert  netscape:  -distort resize 100x100! tmp.png
Fred-Weinhauss-Mac-mini:desktop fred$ identify -verbose tmp.png
Image: tmp.png
   Geometry: 100x100+0+0
...
  Page geometry: 102x102+0+0
 ...
 
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.9.2-10 Beta, available by sometime tomorrow. Thanks.
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

Re: "-distort resize" followed by "-flatten" causes a strange 2px border

Post by sas »

Good to know, thanks!
Post Reply