Automatic Image-Chopper?
September 1, 2005 1:42 PM   Subscribe

I need an automated way to slice 'n' dice some images into regularly sized chunks.

Here's the deal: I'm making a mosaic-style sidebar for a website I'm working on. There are 6x7 squares arranged sorta like a calendar, with each square cell being about 20px to a side.

I want the background of each square to be 20px. square chunk of a larger image, such that it looks like a mosaic when assembled together. To do this, I need a program that will automate the process of getting 42 20px^2 chunks out of every image I use. It would need to do these things, in order:

1) Resize the input image to the proper size.

2) Select the first 20px^2 region (from the top left, natch)

3) Save it with some regular naming scheme (e.g. n+1.jpg)

4) Grab the next 20px^2 region (to the right), do the same thing.

5) Repeat until the region #42 is grabbed and saved.

Is there any freeware program to do this? Barring that, some sort of batch file I could write? I could do the whole project by hand, but it would be mind-numbing. I've got Paintshop at my direct disposal, and could get to a copy of Photoshop, Illustrator, etc. if necessary. Thanks!
posted by electric_counterpoint to Computers & Internet (6 answers total)
 
ImageMagick can do this. One command (resize) to resize and one command (crop) to generate all the tiles.
convert -resize 140x120 myoriginal.jpg mynew.jpg
convert -crop 20x20 mynew.jpg mytiles.jpg

posted by Wolfdog at 2:14 PM on September 1, 2005


What platform are you on? It seems to me that you could probably do exactly what you want with a bit of PHP and GD, but that may or may not be beyond the scope of what you wanna do...
posted by ph00dz at 2:14 PM on September 1, 2005


Have a look at the Photoshop Slice tool.
posted by fake at 2:15 PM on September 1, 2005


Just to be clear, you'd just make a grid of slices and choose "Save for web".... it does almost everything else you want. It will even make a table.
posted by fake at 2:15 PM on September 1, 2005


Have you thought instead about loading up the entire image, then using the CSS background-position style to change the 20x20 area for each tile?

This would probably load faster than 42 separate images anyway, but it won't take care of your step (1).
posted by fleacircus at 2:22 PM on September 1, 2005


(BTW: ImageMagick is available for Windows and Unix - including Darwin - and what you'll get out of that pair of commands is a bunch of files named mytiles.jpg.0, mytiles.jpg.1, ..., mytiles.jpg.4)
posted by Wolfdog at 2:25 PM on September 1, 2005


« Older RV Rental?   |   Advise on honeymoon destinations. Newer »
This thread is closed to new comments.