Question

I have a large amount of images which at first had a black background, then the solid black color was removed leaving the image with pixelated dark-edges.

I am looking for a way to batch process these images to either color-erase the black pixels adjacent to transparent pixels, or to smooth the edge leaving the black edges not as jagged.

I had xnview, irfanview, and GIMP, but I cannot find a suitable method for doing this other than manually with GIMP by using the magic wand on transparent area, growing by one pixel, and color-erasing the black color.

Any ideas? I'm talking over 800 images, so batch processing is pretty important. They are automatically generated from 3d models.

I'll keep looking around in the mean time!

Was it helpful?

Solution

Photoshop is scriptable, and AFAIK gimp is as well. Photoshop has scripting references for vbscript, javascript, and apple(script?) as well as samples buried in the installed folders in PDF format. Check the docs.

I cribbed a technique for selecting transparency from a forum post and ported it to vbscript. It creates a temporary Action which then selects the transparency of the current layer in the (passed) current application reference. The basics of opening files, saving files etc is covered in the references.

The vbscript sample below will find photoshop, bring it to the front, and then attempt to load the transparency in the currently open document. Obvious Man says that this will fail if you haven't already opened PS and loaded a document, or if your document has no transparency applied. YMMV.

Set appRef = CreateObject("Photoshop.Application")
appRef.BringToFront
loadTransparency appRef

    function loadTransparency(appRef)
        dim desc
        dim ref
        dim ref1

        set desc = CreateObject( "Photoshop.ActionDescriptor" )
        set ref = CreateObject( "Photoshop.ActionReference" )
        ref.putProperty appRef.charIDToTypeID( "Chnl" ), appRef.charIDToTypeID( "fsel" ) 
        desc.putReference appRef.charIDToTypeID( "null" ), ref 

        set ref1 = CreateObject( "Photoshop.ActionReference" )
        ref1.putEnumerated appRef.charIDToTypeID( "Chnl" ), appRef.charIDToTypeID( "Chnl" ), appRef.charIDToTypeID( "Trsp" )
        desc.putReference appRef.charIDToTypeID( "T   " ), ref1 

        appRef.ExecuteAction appRef.charIDToTypeID( "setd" ), desc, 3   '3 = no dialogs

    end function
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top