Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
Programming

ImageMagick Help Request

Brandon Beaumia
Tuesday, July 12, 2011 - 22:21

Hi, folks. I've been doing a lot of manual select/copy/new/paste/save to split up spritesheets recently, and remembered reading something about pfunked's workflow including an ImageMagick command. I've been through a good amount of the documentation and determined it will definitely solve my problem, but have also determined that I'm near-useless on the command line.

I'm looking for two commands right now: one to replace a color with transparency and one to split a file into XxY blocks. Pretty simple on their own (and I had finicky versions working, even if I didn't fully understand them), but it would make them ten times as helpful if I could use them for batches. For example, cd'ing into a directory and performing the operation on every file matching *.png.

 

The command I used for transparency was

mogrify /path/to/spritesheet.png -matte -fill none -draw 'color 0,0 replace'

(Replace pixels the same color as pixel 0,0 with fill of 'none'.)

 

The command I used for creating tiles from an image was

convert /path/to/spritesheet.png -crop 32x32 +repage +adjoin tile_%02d.png

 

Unfortunately, I don't know how to get these working in a batch scenario, and #2 seems especially difficult because the resulting tile names would be the same for each image I split. (Make a new folder named the same as the parent image, maybe?)

Any help on this would be greatly appreciated, as my bash experience doesn't go much past copy/paste. =/

  • Log in or register to post comments
Pompei2
joined 15 years 7 months ago
Wednesday, July 13, 2011 - 12:07
Pompei2's picture

You can do this with a shell script. Of the top of my head, the following could work:

 

#!/bin/bash

for f in *.png ; do

    mogrify $f -matte -fill none -draw 'color 0,0 replace'

    convert $f -crop 32x32 +repage +adjoin `basename $f`.%02d.png

done

explanation:

the first line says "do the following for each of *.png file", the next lines say what to do and are executed once for each file, with $f being replaced by the current filename.

I hope there are no mistakes, I didn't try it out.

  • Log in or register to post comments
Brandon Beaumia
joined 13 years 11 months ago
Wednesday, July 13, 2011 - 14:21

This worked perfectly, thanks!

  • Log in or register to post comments
hc
joined 14 years 11 months ago
Thursday, July 14, 2011 - 14:55

Thanks, too!

Will try that on some older sheets I'd like to commit as individual images.

 

  • Log in or register to post comments