Skip navigation
Currently Being Moderated

Determine of a PNG image contains transparent pixels

Sep 19, 2012 11:11 AM

Tags: #cs4 #cs5 #transparent #script #cs5.5 #export #png #transparency #javascript #indesign #images #pageitem #jpg #export_option

Hi,

 

I'm exporting lots of PageItems to images using pageItem.export() method. I want the exported image to be a PNG if it contains transparent pixels, otherwise it should be a JPG.

 

So is there anyway to determine whether an exported PNG contains transparent pixels or not?

 
Replies
  • Currently Being Moderated
    Sep 19, 2012 2:29 PM   in reply to Hoang_Huynh

    You might be able to check against a certain alpha channel. Not sure, but might be a decent starting point.

     

    http://jongware.mit.edu/idcs4js/pc_ClippingPathSettings.html

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 19, 2012 11:44 PM   in reply to Hoang_Huynh

    clippingPathSettings does not help with pngs. It's for images with "real" clipping paths (such as psd files).

     

    There's no easy answer to your problem.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 20, 2012 6:23 AM   in reply to Harbs.

    You can try something like this.... This is in C# though, I'm sure the main methods that make this work aren't supported through javascript, but this might help you see how it is done in other languages. 

     

    Image img = Image.FromFile ( "...", true );

    if ( (img.Flags & 0x2) != 0)

    {

     

      bool ContainsTransparent(Bitmap image)

        {

            for (int y = 0; y < image.Height; ++y)

            {

                for (int x = 0; x < image.Width; ++x)

                {

                    if (image.getPixel(x, y).A != 255)

                    {

                        return true;

                    }

                }

            }

            return false;

        }

     

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 20, 2012 6:47 AM   in reply to Hoang_Huynh

    If PhotoShop is available, you could test for alpha through BridgeTalk in opening the png in PhotoShop and running a PhotoShop snippet, returning the result to the InDesign part of the script.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 27, 2012 3:47 AM   in reply to Hoang_Huynh

    Umm...

     

    That's all about ActionScript. Nowhere in your post did you indicate that you were using ActionScript. If you had, I might have suggested something similar.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points