Find bounds of contiguous transparent pixels

I have the need to find the largest rectangle of ONLY
transparent pixels in a transparent PNG. The transparent region is
non-rectangular, so getColorBoundsRect returns a rectangle that
also contains non-transparent pixels. Is there a way I can check
for a rectangle that contains only the color I set?

Barring finding a method to do this, I hacked together a
solution.
First, I found the bounds of all transparent pixels using
getColorBoundsRect.
Next I iterated from the top-down until I found the first
line with only transparent pixels to revise the top edge
Finally I iterated from the bottom-up until finding the
bottom line of only transparent pixels to revise the bottom edge.
I was able to compensate like as such because I know that the
rectangle is not impeded from the sides at any point, otherwise I
would have had to find the left and right edges as well.
I feel like there should be an easier way (and also a less
processor-intensive way) to do this.

Similar Messages

  • PS CS6 Shows Transparent Pixels Over Image When Zooming Past 50%

    I'm not sure why, but Photoshop just started doing this after I converted my files to a smart object. When I try to zoom in past 50%, it displays these transparent pixel squares over the entire image. I tried rasterizing and flatting the image back, but that didn't do anything. It seems to keep doing this. Any suggestions how I can fix this?

    That sounds like a typical display driver problem.
    If you have a PC, visit the web site of the maker of your video card, seek out and download/install the latest display driver for your hardware and OS, and reboot (even if it doesn't require it).
    If you're on a Mac, you might find that manipulating the graphics processor-specific settings in your Photoshop-Preferences-Performance dialog (and in the Advanced settings) might help.  Make sure to fully Quit and restart Photoshop after making changes there.
    -Noel

  • How do i stop PS from deleting transparent Pixels on layers?

    Hello community,
    i have a problem concering the place-function of Photoshop CS6. I want to include hundreds of png files in a psd file and i want them to keep their original size. Unfortinatly they have transparent borders and PS deletes these borders when you place the images in the PSD-file. For example: I have a square with x=50px and y=50px and it is positioned in an png with the dimensions x=100px and y=100px. I want to have these kind of files in my psd-file an need to keep their full dimensions, because my graphic specifications relate to the 100px/100px size and i need it later in my workflow.
    How do i stop PS from cutting off the tranparent borders of my images?

    Yes Free Transform has what was set during the place and you can see in the option bar if the layer has been scaled or is at 100 % width and height. You can also drag out guide line to the transforms bounding box. Then later measure the size or drop in a low opacity pixel in two diagonal corners to force the bounds to the png's canvas size.   However if you don't add those pixels in a script the bounds you get is that of the bounds of the non transparent pixels and in an action Ctrl|CMD clicking the layers content in the layers palette selects the non transparent pixels.
    My Photoshop Photo Collage populating scripts do not always fill an image area when they resizing odd shaped png images, However if the png is rectangular with transparent borders the script will fill the area with pixel for the scripts gets the bounds of the non transparent pixels, not the png canvas size. So resizing works well. There is a difference between layer size and canvas size in the png file. Layers can also be larger then canvas size in psd files Photoshop support any size layer you have the canvas act like a cropping mask on a document.
    Message was edited by: JJMack

  • Trim Transparent Pixels while placing PSD

    Hi
    Would like to know is there any way of trimming the PSD files when placing them on to InDesign?
    The PSD is of 4000px x 2500px whereas the actual product is only 1200x800px and when i fit the image proportionately, its calculating the transparent pixels, any suggestion on how this needs to be addressed?
    -Bala

    @Bala – there is an explicit UI command for that in PhotoShop: "Trim to Transparent Pixels" (I'm on a German version of PhotoShop, so I cannot tell the exact English phrase).
    Zuschneiden => Trim
    Basiert auf => Based on
    transparenten Pixeln => transparent Pixels
    Entfernen => Cut to
    [x] Above     [x] Left
    [x] Below     [x] Right
    One could script that and use BridgeTalk to launch PhotoShop out of InDesign, do the trimming, and relink to InDesign.
    You'll find some examples of BridgeTalk here around in the forum.
    For scripting PhotoShop there is a different sub-forum.
    Another solution, not recommended:
    InDesign's ability for detect edges in a placed image.
    But using PhotoShop will be far more accurate, not to say: precise…
    Uwe

  • Is there a way to lock transparent pixels for more than one layer at a time?

    I've tried selecting multiple layers to modify but the lock transparent pixels box becomes greyed out once I've selected more than one layer. Apologies in advance if this is deemed to be a stupid question but it would be greatly appreciated if someone knows of a solution. It would be very handy for some of the projects I'm currently developing.
    Thanks.

    I have not had a problem in Photoshop CC 2014 as long as I selected a layer with transparency, in my case the gray checkerboard. The button would dim if I selected an adjustment layer.

  • I want to delete all transparent pixels, how can I? CS6

    I would like to delete all transparent pixels surrounding my irregularly (non-square) image.  The TRIM function only trims to a square surrounding my image and not to the edge of the image itself.  Is there a work around for this?  I have looked around and haven't found one. 
    Thanks,
    JB

    Image have rectangular area they have a width and height boundaries as do layer.  Not all of the rectangular area need to have content or be fully opaque,  However the image boundary is a rectangle.  Some file formats are like a Photoshop Background layer do not support empty area or even transparency so those file formats only contain image that are rectangles and have no transparency. Some file formats support transparency and empty areas so those images can be any shape and contain transparency still the image boundary is rectangular. Then there is the GIF file format an oddball format. It only supports 256 Colors. Pixels are mapped to one of the 256 colors selected for the image.  If you want Transparency in a gif  the number of colors is reduced by 1 to 255  the 256 color now indicate no content its not real transparency it just a no color pixel in other words off or no content.
    So if you have areas that are 100% transparent there is nothing to delete the area is empty.  If you have pixels that contain some transparency and you delete those pixels you delete details are you sure you want to delete all pixels that contain transparency? You will loose things like drop shadows

  • How can I find out the number of pixels a photo has in i photo.

    How can I find out the number of pixels a photo has in iphoto.

    Do you mean in iPhoto on the MacBook Pro?
    The dimensions (width and height iin pixels)are shown in the "Info" panel - multiply the two numbers:
    Regards
    Léonie
    P.S: on an IOS device you see the same information in iPhoto, when you select the photo in an album and click th Info button ( i ).

  • How to edit transparency pixels in a FilterPlugin?

    I want develop a fiter plugin of photoshop. while i am not clearly about some issues:
    (1) how does the photoshop provide the transparency data ( blank data ) to me ?
    in other words, i want obtain the "alpha" channel data, is this provided by the "inData" together with other channels?
    (2) I want to change the pixel's transparency, means i want change totally transparent pixels into
    opaque. how to do it ?
    (3) in the pluginName.r file,there are 7 entries in FilterCaseInfo like following. is there anything i must pay special attention to?
      FilterCaseInfo
        /* Flat data, no selection */
        inWhiteMat, outWhiteMat,
        doNotWriteOutsideSelection,
        filtersLayerMasks,
        worksWithBlankData,
        copySourceToDestination,
    By the way, When i invoke a filter (i develop it 2 yeas ago) on the transparency document , photoshop gives a messagebox said it canot invoke the fiter because the selection area is totally empty.
    if the area has both transparency and opaque pixels, then the plugin cause write access faled and made the photoshop crash ,  why does this happen, how to avoid it.
    Thanks a lot.!

    First off, don't confuse "alpha" with "transparency" they are different.
    If I create a RGB document with one layer and call the Dissolve example I get the following bits of information in the FilterRecord:
    planes = 4
    imageMode = 3 // plugInModeRGBColor
    filterCase = 4 // filterCaseEditableTransparencyNoSelection
    inLayerPlanes = 3
    inTransparencyMask = 1
    plane 0 = red, 1 = green, 2 = blue, 3 = transparency
    See DoFilter, the loop on the planes, and DissolveRectangle, the changing of the data on each plane, in the Dissolve.cpp example file.
    Now flatten the document and create an alpha channel and select all channels via the channels panel. Selecing just the alpha channel or any one channel will have different results.
    planes = 4
    imageMode = 3 // plugInModeRGBColor
    filterCase = 2 // filterCaseFlatImageWithSelection
    inLayerPlanes = 0
    inTransparencyMask = 0
    inNonLayerPlanes = 4
    There is some documentation about FilterCaseInfo in the Plug-in Resource Guide.pdf found in the documentation folder.

  • Crop document by transparent pixels

    Hi,
    I have a question on you. I need crop document by transparent pixels.
    But I don't know, how to do it.
    Document has function crop but it need width and height.
    Do you know function with transparent pixels??
    Than you Domaneni

    Here is an example.
    app.activeDocument.trim ( TrimType.TRANSPARENT );// assumes you want to trim all edges

  • About sprite3D with fully transparent pixels

    I have a image with fully transparent pixels. want to use in a sprite3D object. But all of fully transparent pixels is rendered as white. There is no transparent at all. How can I do it or if the Sprite3D is not support transparent?
    best regards and Thanks any reply.
    The init code is :
    Image sprImg = Image.createImage("/spr.png");
    Appearance sprApp = new Appearance();
    Sprite3D spr3D = new Sprite3D(true,new Image2D(Image2D.RGBA,sprImg),sprApp);
    spr3D.setCrop(sprTexX,0,52,128);
    sprTran.setIdentity();
    sprTran.postTranslate(0.f,2.f,5.f);
    sprTran.postScale(2.f,4.f,1.f);

    Hi Sniper_bat,
    I want to do exactly the same thing, did you ever fix this problem?
    Dan

  • Trim Transparent Pixels

    I cropped the photo to 16x20. With this crop I ended up with some transparent pixels on the right and left edges. I used the Trim tool to remove the transparent pixels. Question - after removing the transparent pixels with the Trim tool do I still have a full 16x20 photo ready for printing OR because I chopped off the transparent pixels my photo has shrunk to a slightly smaller size?

    I started with a photo that I cropped to 16x20. With this 16x20 crop I had some transparent pixels. I trimmed the transparent pixels off. By trimming did I decreased the size of the 16x20? I did NOT recrop after the trimming.

  • Why are my transparent pixels becoming opaque (grey)?

    I have PSE 6, and am using it for digital scrapbooking. Some of the elements have transparent pixels, which allows you to see the background and layers beneath the elements. For some reason, when I drag one of these elements onto a background or another element, the transparent pixels become gray, creating an ugly grey box around the element. Also, I see when the new layer is created (on the background), by dragging the element onto the background, it becomes a "frame layer". Not sure exactly what that means, but I am thinking it might have something to do with this problem.   Hopefully someone has a suggestion
    thanks

    Have a look at  #5 in the link below which describes this "feature" and how to get around it.
    http://blog.hummiesworld.com/2007/10/bugs-and-complaints-of-photoshop.html

  • How to find bounds of textcolumn

    Hello ,
    can anybody tell me ,how to find bounds of textcolumn.

    Text columns don't have a geometricBounds property, so you have to calculate that yourself. Take the bounds of the text frame, check the number of columns (myTextFrame.textFramePreferences.textColumnCount) and the gutter width ((myTextFrame.textFramePreferences.textColumnGutter). Then you can work out the bounds of a text column.
    Peter

  • Photoshop opens dialog box when trying to fill a layer with transparent pixels locked

    This script should set the layer to lock transparent pixels, and then fill the layer with a color. It does that, except when it gets to the fill stage, it opens the fill dialog box, and you have to hit okay.
    If you omit the transparent pixel line, it runs as expected, no dialog box.
    Is there a way to suppress the box? Or am I doing something wrong that's causing the box to open?
    #target photoshop
    app.bringToFront();
    doc = app.activeDocument;
    doc.artLayers[0].isBackgroundLayer = false;
    doc.artLayers[0].transparentPixelsLocked = true;
    app.activeDocument.selection.fill(app.foregroundColor);

    Not sure why that happens.
    But I would recommend foregoing the locking and using the AM code for a Fill that honours the transparency.
    #target photoshop 
    app.bringToFront(); 
    doc = app.activeDocument; 
    doc.artLayers[0].isBackgroundLayer = false; 
    doc.activeLayer = doc.artLayers[0];
    // =======================================================
    var idFl = charIDToTypeID( "Fl  " );
        var desc18 = new ActionDescriptor();
        var idUsng = charIDToTypeID( "Usng" );
        var idFlCn = charIDToTypeID( "FlCn" );
        var idFrgC = charIDToTypeID( "FrgC" );
        desc18.putEnumerated( idUsng, idFlCn, idFrgC );
        var idOpct = charIDToTypeID( "Opct" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc18.putUnitDouble( idOpct, idPrc, 100.000000 );
        var idMd = charIDToTypeID( "Md  " );
        var idBlnM = charIDToTypeID( "BlnM" );
        var idNrml = charIDToTypeID( "Nrml" );
        desc18.putEnumerated( idMd, idBlnM, idNrml );
        var idPrsT = charIDToTypeID( "PrsT" );
        desc18.putBoolean( idPrsT, true );
    executeAction( idFl, desc18, DialogModes.NO );

  • Finding bounds of nested clipping paths...

    This topic has been touched on before, muppet & sonic have pointed me in the right direction, but I'm stuck right now....
    Seeing as how "saveMultipleArtboards = false" is broken in CS4, and scripting any kind of epsSave results in the artboard size being the bounding box, I am trying to see if I can find out if the "visible to the eye" bounds of artwork exceed the artboard size.
    I can easily find non-clipped objects hanging outside the artboard by comparing the document's visible bounds to the artboard size.
    Likewise the "visible to the eye" bounds of clipped objects :
    var docRef = app.activeDocument;
    docRef.rulerOrigin = [0,0];
    ////Get size of artboard
    var myDocsizeArray = [0,0,docRef.width,docRef.height]
    ////Check for items on page
    if(docRef.pageItems.length != 0){
    /////Find out if top item is clipping mask
    if(docRef.pageItems[0].typename == "GroupItem"){
    if(docRef.pageItems[0].pathItems[0].clipping == true){
    ////Compare its bounds to doc bounds
    var myClipArray = docRef.pageItems[0].pathItems[0].visibleBounds
    if((myClipArray[1] >  myDocsizeArray[3]) || (myClipArray[2] >  myDocsizeArray[2]) || (myClipArray[0] < 0) || (myClipArray[3] < 0)){
    alert("Outside of artboard")
    However, this doesn't work if clipping paths are part of a nested groups. Is there a way to see if a clipping path's parent group is within bounds, or parent's parent group etc. is within bounds. I need to find the topmost clipping path that trumps all the others in any nested group.
    Is that what recursive functions are for? ,,,,,,,,,,,
    Something that can keep looking in a loop within itself?  Very instrospective!
    thx

    Does this help? I use these to position and find bounds based upon what is visible.
    function getRealVisibleBounds(grp) {
         var outerBounds = [];
         for(var i = grp.pageItems.length - 1; i >= 0;i--)  {
              var bounds = [];
              if(grp.pageItems[i].typename == 'GroupItem') {
                   bounds =  getRealVisibleBounds(grp.pageItems[i]);
              else if((grp.pageItems[i].typename == 'PathItem' || grp.pageItems[i].typename == 'CompoundPathItem')
                   && (grp.pageItems[i].clipping || !grp.clipped)) {
                   bounds = grp.pageItems[i].visibleBounds;
              if (bounds.length > 0) {
                   outerBounds = maxBounds(outerBounds,bounds);
         return (outerBounds.length == 0) ? null : outerBounds;
    function maxBounds(ary1,ary2) {
         var res = [];
         if(ary1.length == 0)
              res = ary2;
         else if(ary2.length == 0)
              res = ary1;
         else {
              res[0] = Math.min(ary1[0],ary2[0]);
              res[1] = Math.max(ary1[1],ary2[1]);
              res[2] = Math.max(ary1[2],ary2[2]);
              res[3] = Math.min(ary1[3],ary2[3]);
         return res;
    function positionVisible(grp,x,y)
         var bounds = getRealVisibleBounds(grp);
         var newX = x + (grp.left - bounds[0]);
         var newY = y + (grp.top - bounds[1]);
         grp.position = [newX,newY];

Maybe you are looking for

  • Way to extend Satellite Pro R850 memory

    I was just wondering, since i have a lot of stuff in my laptop; is there a way, like a card, to extend my laptop's memory? As i noticed a big slot inside my laptop on the lower left side, so is there something for a memory extension i can put in ther

  • ECC 6.0 Upgrade - Lot of  Custom Objects - How to make it work ???

    Hi , My client is on HR 4.6c and ESS in standalone ITS and upgrading to ECC 6.0 and EP7.  They have lot of custom objects ( Reports, ABAP Queries, Function Modules etc., ) and lot of customization done in ESS ( Std tcodes copied and developed ESS ser

  • Adobe Dreamweaver CS3 with ASP coldfusion and PHP search?

    I am working through Adobe Dreamweaver CS3 with ASP coldfusion and PHP with the intent of creating a data base site that primarily requires a search engine on the index page. The search page in the book uses specific search criteria ensuring that the

  • Is there a way to sync my iphone without losing free music?

    basically, i had an old computer with a great itunes library, with a LOT of mixtapes, which most of were free from the artist, the computer bricked so i couldnt transfer that music to a flash drive, it's still on my phone, but i dont want to sync to

  • Latest NitroX Struts fails with Eclipse 3.1M7, Java 1.5.0_02

    Tried installing NitroX struts (build 417) with Eclipse 3.1M7 running Java 1.5.0_02. When I try to open any JSP file, I'm getting this error. Eclipse 3.1M7 seems great (comes with few new features like support for @suppresswarning annotations,etc)...