14 Replies Latest reply on Jan 18, 2015 7:46 AM by rob day

    Fit frame to pixels

    Kaz Till Level 1

      Is there a way to automatically fit a frame to the actual content of a psd file?

      I'm importing a lot of images that are smaller that the whole page, and I don't want their frame taking all of it. So far I'm doing it by hand, dragging the four corners of the frame to fit the image. But I imagine there has to be a better way, or even a plug in.

      If I use Fit Frame to Content, because the actual PSD file occupies the whole page, the frame doesn't move. So it'd have to be able to detect the actual content of the file.

      Thanks.

        • 1. Re: Fit frame to pixels
          Steve Werner Adobe Community Professional & MVP

          I've never had a problem with Fit Frame to Content working so I don't understand. Perhaps you could provide a screen capture to illustrate what you're trying to do because I don't understand. You can attach it with the camera icon in the editor window.

          • 2. Re: Fit frame to pixels
            Kaz Till Level 1

            I have this is PS.

            screen1.jpg

            When I import it to InDesign, it shows like this:

            screen2.jpg

            I'd like for the frame to be scaled down to only cover the black square. If I use Fit Frame to Content, the frame stays the same. Because I think it uses the imported size of the image as "content". Not the actual pixels of the image.

            • 3. Re: Fit frame to pixels
              Steve Werner Adobe Community Professional & MVP

              That makes it clear, thanks. I can replicate that issue.

               

              InDesign can recognize the layers in the PSD file but it has no way of actually reading the position of the pixels in the PSD. I doubt that a script do it either.

              • 4. Re: Fit frame to pixels
                John Mensinger Adobe Community Professional & MVP

                Kaz Till wrote:

                 

                I have this is PS.

                screen1.jpg

                If I use Fit Frame to Content, the frame stays the same. Because I think it uses the imported size of the image as "content". Not the actual pixels of the image.

                But of course.

                 

                What is the point of having all that transparent real estate in the .psd? Why not just crop it to the non-transparent pixels? That not only renders the Fitting features useless, it also adds a lot of needless byte-weight to any process undergone by the file.

                • 5. Re: Fit frame to pixels
                  Kaz Till Level 1

                  It's a file with a lot of pieces. I import it like this in InDesign so the elements will have the same position they have in PS.

                  • 6. Re: Fit frame to pixels
                    Willi Adelberger Most Valuable Participant

                    Why are you not importing a single file with different layers. Set up layer comps in Photoshop. Place it into InDesign, duplicate it on the same place (best in different layers) and use different layer comps for each instance.

                    • 7. Re: Fit frame to pixels
                      BobLevine MVP & Adobe Community Professional

                      +1 for Willi's response. I just did something similar yesterday and it took just a few minutes to get everything the way I need it.

                      • 8. Re: Fit frame to pixels
                        rob day Adobe Community Professional & MVP

                        What OS are you using? You should be able to script it by getting the bounds of the non transparent pixels from Photoshop and use them to adjust the ID frame.

                        • 9. Re: Fit frame to pixels
                          rob day Adobe Community Professional & MVP

                          Your screen capture looks like OSX. Try this Applescript, you have to direct select the image before running the script:

                           

                           

                          tell application "Adobe InDesign CC 2014"

                               activate

                              if selection is {} or class of selection is not image then

                                  display dialog "Please select a linked image"

                                  return

                              end if

                              set linkfile to file path of item link of selection

                            

                              --get the bounds of non transparent pixels note PS bounds are {x1,y1,x2,y2} in ID it's {y1,x1,y2,x2}

                              tell application "Adobe Photoshop CC 2014"

                                  set ruler units of settings to inch units

                                  open file linkfile

                                   --work on a copy

                                  set psFile to duplicate current document

                                  tell psFile

                                      merge visible layers

                                      set {a, b, c, d} to bounds of layer 1

                                      close saving no

                                  end tell

                                  close current document saving no

                              end tell

                            

                              tell application "Adobe InDesign CC 2014"

                                  activate

                                  set properties of view preferences of active document to {horizontal measurement units:inches, vertical measurement units:inches}

                                  set myFrame to parent of selection

                                  tell myFrame

                                      fit given frame to content

                                      set {e, f, g, h} to geometric bounds

                                      set geometric bounds to {e + b, f + a, e + d, f + c}

                                      select

                                  end tell

                              end tell

                          end tell

                          • 10. Re: Fit frame to pixels
                            Steve Werner Adobe Community Professional & MVP

                            Good work, Rob. When I was thinking of scripting, I was thinking within InDesign. You thought "outside the box." Not being a scripter, I forgot that AppleScript can script in multiple applications.

                            • 11. Re: Fit frame to pixels
                              Kaz Till Level 1

                              Thanks Rob!

                              I'm on Windows. Is there a way to adapt this to Windows?

                              That would save me a lot of time!

                              Applescript does look pretty cool.

                              • 12. Re: Fit frame to pixels
                                Kaz Till Level 1

                                The issue here is that I need for the frame to be not much bigger that the image. I'm exporting this to html and animating some parts of it. If the frame is as big as the page, it complicates the animation a lot.

                                Thanks!

                                • 13. Re: Fit frame to pixels
                                  rob day Adobe Community Professional & MVP

                                  Sorry I cant do it. You might check in the scripting forum and see if it can be translated into .js. I think with Javascript it isn't as easy to use multiple applications, but there might be a way.

                                  • 14. Re: Fit frame to pixels
                                    rob day Adobe Community Professional & MVP

                                    I forgot that AppleScript can script in multiple applications.

                                    Since the script doesn't reference the Finder, I think it can be done in JavaScript via BridgeTalk—I'm just too slow with JS to knockout a translation.