Batch Image Trim

1k views Asked by At

I have a Flash fla file that contains a whole lot of images. The majority of each image is composed of transparent pixels with a visual object in there somewhere. Each image at the moment is at {x:0, y:0}.

I want to trim away the transparent pixels of the image down to a minimum bounding box, but keep the object at the same global position. This requires shifting the trimmed image to the global position of the object in the untrimmed image.

This is not so much a problem, but the fact that the images are all contained in a fla is the problem. The options I see at the moment are:

  • investigate JSFL, the Bitmap object has a getPixels, this in combination with a selection and delete operation could work

  • save the fla to xfl and enumerate the images and associated xml with something like Ruby + image processing lib

Questions:

  • Does anyone know upfront if this operation is possible in JSFL?
  • Have anyone done much automated processing of xfl files?
  • Is there an off the shelf image processor that can perform this trimming operation?
3

There are 3 answers

1
James Tomasino On

You might want to try doing the trimming automatically in ActionScript as the images are being used. Color shift the image to a single color and using the pixel methods to identify the bounding area. It's a similar technique used here.

0
Haronious On

It should be possible to use a language like Ruby to find all image files in the xfl project directory structure and edit them with a program like ImageMagick (which is free and works with a variety of scripting languages).

This guy does a good job of explaining how to access your assets from the XFL document: http://blog.mencio.com/?p=121

Here's a link on removing border pixels on the ImageMagick forum: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=11103&start=0

Hope that's enough to get you started.

0
iND On

I worked this problem out in Photoshop. Using PS's scripting language, a selection can have multiple regions, and you can access these "islands" through code.

In the above example, I found (automatically) the {x,y} position of all separate islands, trimmed the island's graphics, and saved each island as a separate image file. The {x,y} location became part of the filename. I have not built the JSFL portion in Flash which would read the filenames and position them according to the {x,y} in the name; but instead did it by hand.

If you can export all your images, you can use this PS script to find the location and crop the images. It would be a fairly striaghforward task to write a JSFL script to position the images.