Howto split image?

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
const

Howto split image?

Post by const »

Hello, is there simple way to split Magick::Image to sequence of images?

Image - is an image (1024x1024), created in photoshop by artists, now I want to split this image to 64x64 tiles and write them to file sequence (img000.tga, img001.tga etc), but couldn't find suitable method so far.

const

Re: Howto split image?

Post by const »

Browsing documentation, I've found something suitable in convert utility -
-crop parameter

Quote from documentation:
If the x and y offsets are omitted, a set of tiles of the specified geometry, covering the entire input image, is generated. The rightmost tiles and the bottom tiles are smaller if the specified geometry extends beyond the dimensions of the input image.
Is there way to implement this functionality using C/C++ API?

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

Re: Howto split image?

Post by anthony »

See IM examples, tile cropping
http://imagemagick.org/Usage/crop/#crop_tile

The same syntax should be used for all API crop operators.

NOTE remember IM does not deal in units of single images, but lists or sequences of images. as such the one image will become many images refered to by the one reference. When you save you then specify how you want to save the many images using things like...
Writing a Multi-Image Sequence
http://imagemagick.org/Usage/files/#write_seq

the same methods are also using in API's
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

live4fun

Re: Howto split image?

Post by live4fun »

I try to split an image horizontal into two tiles.

Code: Select all

convert -crop 100%x50% 0017kh.gif +repage  tiles%d.gif
The Tiles show the upper and lower part of the images but the opposite half is filled with black. The tiles still have the same size as the original image not only half of it as expected. Looks to me as if repage is ignored or am i using it wrong??

I just want to split my image horizontal and get two tiles that represent the upper and the lower half of the input image.

When I run after tile generation:

Code: Select all

mogrify +repage tiles*
black areas of the tiles get removed and I get the tiles I wanted in the first place. Why isn't the repage option respected in the convert call?

Best Regards

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

Re: Howto split image?

Post by fmw42 »

put your input image before -crop. see http://www.imagemagick.org/Usage/basics/#why

for 50% split, see http://www.fmwconcepts.com/imagemagick/ ... .php#crop1
for 25% split or 128x128 tiles, see http://www.fmwconcepts.com/imagemagick/ ... .php#crop2

perhaps your IM version is too old. try upgrading if needed.

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

Re: Howto split image?

Post by anthony »

As you saved to GIF the virtual canvas position was preserved. The black areas is empty space containing no image.

To remove all the position information leaving just the image without a virtual canvas and offset do a +repage afetr the crop.

See Tile Cropping, which has examples showing this.
http://www.imagemagick.org/Usage/crop/#crop_tile

PS the black sections you see in some examples to the right of the real image is a BUG in firefox. It was reported at the start of the year but NOTHING has been done about it.
https://bugzilla.mozilla.org/show_bug.cgi?id=487562
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply