convert thumbnail with offset

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
LinuxPope
Posts: 11
Joined: 2012-01-14T07:27:34-07:00
Authentication code: 8675308

convert thumbnail with offset

Post by LinuxPope »

I've developed a thumbnail editor for my application, which allows the user to "move" his large avatar within a set dimensions and thus save a thumbnail that looks better than the auto-generated one. I do this by using the old method of "-resize Y -resize Xx< -resize 50% -gravity center -crop XxY+offsetX+offsetY +repage" (which is described here: http://www.imagemagick.org/Usage/resize/#space_fill). This works beautifully.

I then tried to change the command to use the new "^" feature (which is described here: http://www.imagemagick.org/Usage/thumbnails/#cut), like this:

-define jpeg:size=X*2xY*2 source.jpg -auto-orient -thumbnail XxY^+offsetX+offsetY -gravity center -unsharp 0x.5 jpeg:output.jpg

Unfortunately, the +offsetX and +offsetY parameters for the -thumbnail geometry are ignored.

for example (should show a thumbnail that has been pushed downwards by 50px, but its not):

Code: Select all

convert -define jpeg:size=200x200 source.jpg -auto-orient -thumbnail 100x100^+0+50 -gravity center -unsharp 0x.5 jpeg:output.jpg
LinuxPope
Posts: 11
Joined: 2012-01-14T07:27:34-07:00
Authentication code: 8675308

Re: convert thumbnail with offset

Post by LinuxPope »

*bump*

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

Re: convert thumbnail with offset

Post by fmw42 »

try

-thumbnail XxY+offsetX+offsetY^

or


-thumbnail XxY+offsetX+offsetY\^
LinuxPope
Posts: 11
Joined: 2012-01-14T07:27:34-07:00
Authentication code: 8675308

Re: convert thumbnail with offset

Post by LinuxPope »

unfortunately, that didn't work.

does it work for others? maybe my version (6.5.8-10) is a bit too old?
LinuxPope
Posts: 11
Joined: 2012-01-14T07:27:34-07:00
Authentication code: 8675308

Re: convert thumbnail with offset

Post by LinuxPope »

I tried version 6.7.0, then I tried 6.7.4... I tried to move the ^ character and made sure it is properly escaped.... no go, they all have the same problem.

Probably a bug that has been around for a long time but nobody noticed because it is not so frequent to displace/offset a thumbnail.
LinuxPope
Posts: 11
Joined: 2012-01-14T07:27:34-07:00
Authentication code: 8675308

Re: convert thumbnail with offset

Post by LinuxPope »

Here is a test case:

convert im logo to a 100x100 thumbnail without any offset:

Code: Select all

convert logo: -thumbnail 100x100^ -gravity center -extent 100x100 test.png
do the same with +50px vertical offset:

Code: Select all

convert logo: -thumbnail 100x100^+0+50 -gravity center -extent 100x100 test.png
Based on the documentation, the "^" character is part of the "size" part of the geometry and not part of the offset, so in theory it should stay as: dX x dY ^ +|- oX +|0 oY

Can someone please test the above commands? If they produce the same result then there is definitely a bug in im, unless -thumbnail is on purpose made to ignore offsets for some reason?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: convert thumbnail with offset

Post by glennrp »

If the "-thumbnail" option runs StripImage(image) (as if the "-strip" option had been supplied) then the offset information gets stripped by the PNG encoder.

There's probably a workaround via the "-define png:include-chunks=vpag,offs" but I'm not sure. I'll test and report back when I get a few minutes.

[edit] That's not the problem. Apparently it's more like an automatic "+repage" has happened, so there is nothing for the PNG encoder to ignore.
If you add "-page +0+50" after the -thumbnail option you get the offset included in an oFFs chunk in the PNG file.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert thumbnail with offset

Post by fmw42 »

Does it work with -resize? If so then add -strip after the -resize and see if that will produce what you want.
LinuxPope
Posts: 11
Joined: 2012-01-14T07:27:34-07:00
Authentication code: 8675308

Re: convert thumbnail with offset

Post by LinuxPope »

I'm sorry to report but none of the suggestions worked. I had to resort to the "long" way of doing this:

-resize xY -resize Xx< -resize 50% -crop XxY+OffsetX+OffsetY

not very elegant, and the "^" character was supposed to be a shortcut but since ^ doesn't work with offsets... I have to go the long way :(
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert thumbnail with offset

Post by anthony »

I can say definitive that -thumbnail does NOT take a offset!

In the cut to fit thumbnailing technique (using '^' resize flag) the option that does take -gravity and -geometry offset info is -extent.

http://www.imagemagick.org/Usage/thumbnails/#cut
http://www.imagemagick.org/Usage/crop/#extent

The alternative is to do a crop with the righ aspect ratio BEFORE the resize.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply