Tile crop, overlap and final image size

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?".
Locked
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Tile crop, overlap and final image size

Post by xpt »

Hi,

I'm just trying to figure out exactly how the overlapping affect the tile cropping. Let me explain with an example:

Code: Select all

$ convert logo: -crop 4x1@ +repage +adjoin logo_%d.gif

$ identify logo_?.gif
logo_0.gif GIF 160x480 160x480+0+0 8-bit PseudoClass 256c 2.97KB 0.000u 0:00.000
logo_1.gif[1] GIF 160x480 160x480+0+0 8-bit PseudoClass 256c 9.55KB 0.000u 0:00.000
logo_2.gif[2] GIF 160x480 160x480+0+0 8-bit PseudoClass 256c 21.2KB 0.000u 0:00.000
logo_3.gif[3] GIF 160x480 160x480+0+0 8-bit PseudoClass 256c 7.21KB 0.000u 0:00.000
Now I want the tile cropped images to be of 212 pixel width. Since 212-160 = 52, intuitively I'll do:

Code: Select all

convert logo: -crop 4x1+52@ +repage +adjoin logo_%d.gif
but the result is now what I was expecting:

Code: Select all

$ identify logo_?.gif
logo_0.gif GIF 199x480 199x480+0+0 8-bit PseudoClass 256c 4.34KB 0.000u 0:00.000
logo_1.gif[1] GIF 199x480 199x480+0+0 8-bit PseudoClass 256c 11.4KB 0.000u 0:00.000
logo_2.gif[2] GIF 199x480 199x480+0+0 8-bit PseudoClass 256c 25.7KB 0.000u 0:00.000
logo_3.gif[3] GIF 199x480 199x480+0+0 8-bit PseudoClass 256c 14.5KB 0.000u 0:00.000
What causes such difference?
How can I calculate the correct amount for the overlapping?

Thanks

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

Re: Tile crop, overlap and final image size

Post by fmw42 »

You cannot do what you want by that method. I don't think equal size crop method allows offsets

Either you crop with 212 width and let the last image be some other size or you crop and pad to 212.

convert logo: -crop 212x480 +repage +adjoin logo_%d.gif

or

convert logo: -crop 212x480 +repage gravity center -background white -extent 212x480 +adjoin logo_%d.gif

or

convert logo: -crop 4x1@ +repage -gravity center -background white -extent 212x480 +adjoin logo_%d.gif

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tile crop, overlap and final image size

Post by anthony »

Cropping using (near) equal size cropping does support overlaps. Howevr the value you give is the number of pixels that is shared between images, as such it gets counted twice!

Also it depends on another flag whether edge images should also contain a "border" area (and thus all images are equal in size - the default), or not (and thus edges are a little smaller) add a '!')

To see the differences in how the flags work see...
Separating Spaced-out Tiling Images
http://www.imagemagick.org/Usage/crop/#crop_spaced

There are three methods of spacing. no-overlap (montage-like), overlap with border (resulting images are same sized), overlap without border (edge images slightly smaller -- add a '!' flag as well)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked