4 Replies Latest reply on Apr 30, 2013 9:06 PM by JJMack

    JSX to Extract Full Resolution Image From Layered PSD

    hackcess

      I'm somewhat perplexed that this has never come up but here's the issue:

       

      Imagine you have a 2000x2000 image and you import/place that image into a PSD whose document resolution is 800x600.  When you export the document as a tif, jpg, png etc the result is an image with a dimension of 800x600.  That's fine.  But I'd like to use JSX to export the original image at its full 2000x2000 and I can't seem to find a way to do this programatically.

       

      Is it possible to use JSX to recover the dimensions and XY coords of the content on a specific layer in the image stack?  If I had those then I could possibly resize the canvas, perform the export, then return the canvas to its original state.

       

      Cheers,

      Simon

        • 1. Re: JSX to Extract Full Resolution Image From Layered PSD
          Michael L Hale Level 5

          You can use Action Manager to export the embedded image in a smart object. If you are talking about normal art layers, then no there is no way I know to determine the original size of the image.

          • 2. Re: JSX to Extract Full Resolution Image From Layered PSD
            hackcess Level 1

            Just posted the same question on ps-scripts and you answer here.    I will investigate your suggestion Mike, thank you very much!

            • 3. Re: JSX to Extract Full Resolution Image From Layered PSD
              Michael L Hale Level 5

              If you are working with smart object you can use this function to get the embedded image filename.

               

              function getSmartObjectlayerFilename(){
                  try {
                      var ref = new ActionReference(); 
                      ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                      var smartDesc = executeActionGet(ref).getObjectValue(stringIDToTypeID( "smartObject" )) 
                      return smartDesc.getString(charIDToTypeID("FilR"));
                  } catch (e) {}   
              }
              

               

              After you have the filename and know what format the embedded image is( from the filename extension ) you can use this function to export the embedded file. You will want to have a full path for the argument.

               

              function exportSmartObject(fileRefStr){
              //saves the current activeDocument.activeLayer
              //file format must match either the object that the smart object was created from
              //or the format of the doc if created in doc. You can't place a tiff and export as psd
                  try {
                      var desc = new ActionDescriptor();
                      desc.putPath( charIDToTypeID( "null" ), new File( fileRefStr ) );
                      executeAction( stringIDToTypeID( "placedLayerExportContents" ), desc, DialogModes.NO );
                  } catch (e) {};
              }
              
              • 4. Re: JSX to Extract Full Resolution Image From Layered PSD
                JJMack Most Valuable Participant

                hackcess wrote:

                 

                I'm somewhat perplexed that this has never come up but here's the issue:

                 

                Imagine you have a 2000x2000 image and you import/place that image into a PSD whose document resolution is 800x600.  When you export the document as a tif, jpg, png etc the result is an image with a dimension of 800x600.  That's fine.  But I'd like to use JSX to export the original image at its full 2000x2000 and I can't seem to find a way to do this programatically.

                You have confused me with what you have written. So now its my turn to confuse you...  (import/place) are two different thing which do you mean?  I think you mean Place.  Into a PSD?  A PSD is a file Photoshop can save PSD file however  Photoshop is not a file editor it works on Photoshop Documents. Files can be imported and placed into documents.  Photoshop export! Export can write a sequence of image files of a particular file type PNG, Tiff, Jpg etc for a document.  I think you mean "Save As" not Export.    File formats vary in what they support.  I think only PSD, PSD and TIFF supports layers. These file formats can also house flattened documents. Resolution is 800x600. That is not a document resolution its a documents canvas pixel size.  Layers can be any size they can be canvas size however they can be any other size as well.  Resolution is a pixel density like 300 which is important when printing and when adding canvas using a relative measuring unit like inches.  The resolution need to be used.

                 

                In a composite image document the only layers that contain the full pixel size image are placed smart object layers Their embedded smart object contain a copy of the original image file in it.  Smart object layers pixels are a full size Photoshop rendering of the embedded object and an associated transform for the layers pixels.  So the layers current size may not be the original image size.  In fact by default if the original image is larger then the document the the image is being placed into Photoshop will scale down the smart object layer to fit within the documents canvas size.

                 

                If you have a layered file with placed image smart object layers you can recover those layers full size image. For the embedded smart object contains a copy of the original file and the layer pixels are a rendering of that image with an associated transform, Target one of these layers and use free transform an set both width and height to 100% to insure the layer size is the same as the original image size. There are more then one way to save these full size layer as image files......