Command line help

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
joexv
Posts: 2
Joined: 2015-08-09T13:44:11-07:00
Authentication code: 1151

Command line help

Post by joexv »

I have a large image of sprites
Image

And each set of 16 color sprites is split with different background colors as seen in the above image.
As Im doing now, I manually split them and then I use this command after decreasing it to 16 colors with infranview.
convert image.bmp -crop 32x32 image-%02d.bmp

what i want to know is, is there a simpler way to do this via image magick?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command line help

Post by fmw42 »

You can do it all in IM with -colors

Code: Select all

convert image.bmp +dither -colors 16 -crop 32x32 image-%02d.bmp

or you can create a color table image of only the 16 specific colors you want and use -remap as

Code: Select all

convert image.bmp +dither -remap colortable.gif -crop 32x32 image-%02d.bmp
see http://www.imagemagick.org/Usage/quantize/#remap
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Command line help

Post by snibgo »

joexv wrote:what i want to know is, is there a simpler way to do this via image magick?
A simpler way to do what?
Only the top 1024 rows are relevant. "-crop x1024+0+0" will remove the stuff at the bottom. There are 10 panels across the image but the width is not divisible by 10. However, "-crop 10x8@" will chop it into panels. Then we can chop each panel into 3x4 sprites with "-crop 3x4@".

Code: Select all

convert ..\sprites.png -crop x1024+0+0 -crop 10x8@ -crop 3x4@ +repage p-%03d.png
"identify p*.png" tells us each sprite is 31 or 32 high, and 32 wide. Most sprites have 16 or fewer colours. A few have more.

We can make all sprites 32x32 pixels:

Code: Select all

convert ..\sprites.png -crop x1024+0+0 -crop 10x8@ -crop 3x4@ +repage -define distort:viewport=32x32+0+0 -filter box -distort SRT 1,0 p-%03d.png
We can reduce each one to 16 colours with "-colors 15". (Don't ask me why "15".)

Code: Select all

convert ..\sprites.png -crop x1024+0+0 -crop 10x8@ -crop 3x4@ +repage -define distort:viewport=32x32+0+0 -filter box -distort SRT 1,0 +dither -colors 15 p-%03d.png
After cropping into panels, you might want to do something about bad pixels at edges, caused by the panels being badly placed in the large image.
snibgo's IM pages: im.snibgo.com
joexv
Posts: 2
Joined: 2015-08-09T13:44:11-07:00
Authentication code: 1151

Re: Command line help

Post by joexv »

snibgo wrote:
joexv wrote:what i want to know is, is there a simpler way to do this via image magick?
A simpler way to do what?
Only the top 1024 rows are relevant. "-crop x1024+0+0" will remove the stuff at the bottom. There are 10 panels across the image but the width is not divisible by 10. However, "-crop 10x8@" will chop it into panels. Then we can chop each panel into 3x4 sprites with "-crop 3x4@".

Code: Select all

convert ..\sprites.png -crop x1024+0+0 -crop 10x8@ -crop 3x4@ +repage p-%03d.png
"identify p*.png" tells us each sprite is 31 or 32 high, and 32 wide. Most sprites have 16 or fewer colours. A few have more.

We can make all sprites 32x32 pixels:

Code: Select all

convert ..\sprites.png -crop x1024+0+0 -crop 10x8@ -crop 3x4@ +repage -define distort:viewport=32x32+0+0 -filter box -distort SRT 1,0 p-%03d.png
We can reduce each one to 16 colours with "-colors 15". (Don't ask me why "15".)

Code: Select all

convert ..\sprites.png -crop x1024+0+0 -crop 10x8@ -crop 3x4@ +repage -define distort:viewport=32x32+0+0 -filter box -distort SRT 1,0 +dither -colors 15 p-%03d.png
After cropping into panels, you might want to do something about bad pixels at edges, caused by the panels being badly placed in the large image.
Im looking for a simpler wayt o split the image up by their color palette.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command line help

Post by fmw42 »

joexv wrote: Im looking for a simpler wayt o split the image up by their color palette.
Please explain further. There is only one color palette in any given image. Do you want to make one image per each color in the color palette?
Post Reply