8 Replies Latest reply on Jun 20, 2014 1:07 AM by c.pfaffenbichler

    Fit frame to content but in Photoshop

    Waterbear Level 1

      I feel as if someone out there must have asked for this already but a search didn't find it, so I'm asking. Sorry if it's been done before.

       

      In Indesign, you can select "Fit frame to Content" and the text box will shrink to the size of the text. Has anyone written a script to do that in Photoshop?

       

      (Please don't say something like, "Photoshop is for images, use Indesign for text and layout. Yes, I get that, but that's not the question I was asking.)

       

      Thanks!

        • 1. Re: Fit frame to content but in Photoshop
          matias.kiviniemi Level 3

          In theory you could set artLayer.TextItem.widht/height to the values of the bounding box (have not tried, but docs say it's read-write). However the width and height are a bit challenging because they ignore transforms, i.e. if the text box has been resized. You'd have to fetch scale factors using action descriptors and calculate unscaled size and set that. See below discussion for details

          https://forums.adobe.com/thread/1110456

          • 2. Re: Fit frame to content but in Photoshop
            c.pfaffenbichler Level 9

            Which purpose is this intended to serve?

            • 3. Re: Fit frame to content but in Photoshop
              Waterbear Level 1

              I get PSD files from other people from time to time at work. A few of the other designers think you need a text box that's many hundreds of pixels long and tall to type one word, and other such scenarios. Its a pain to edit these files because I end up grabbing the giant text box instead of something else that's under it.

               

              I would love a way to select the text layers and run something that makes the text boxes fit the words inside them.

              • 4. Re: Fit frame to content but in Photoshop
                c.pfaffenbichler Level 9

                If it is about one-word-Type Layers might converting the Paragraph Text to Point Text not suffice?

                • 5. Re: Fit frame to content but in Photoshop
                  c.pfaffenbichler Level 9

                  It seems to be possible to change a paragraph text’s bounds without affecting the type settings.

                  I have not bothered to evaluate the existing bounds, so you’d have to do quite some work on the Script yet but maybe this can provide a starting point.

                  // 2014, use at your own risk;

                  #target photoshop

                  if (app.documents.length > 0) {

                  var myDocument = app.activeDocument;

                  if (myDocument.activeLayer.kind == LayerKind.TEXT) {

                  // =======================================================

                  var idsetd = charIDToTypeID( "setd" );

                      var desc3 = new ActionDescriptor();

                      var idnull = charIDToTypeID( "null" );

                          var ref2 = new ActionReference();

                          var idTxLr = charIDToTypeID( "TxLr" );

                          var idOrdn = charIDToTypeID( "Ordn" );

                          var idTrgt = charIDToTypeID( "Trgt" );

                          ref2.putEnumerated( idTxLr, idOrdn, idTrgt );

                      desc3.putReference( idnull, ref2 );

                      var idT = charIDToTypeID( "T   " );

                          var desc4 = new ActionDescriptor();

                              var list1 = new ActionList();

                                  var desc8 = new ActionDescriptor();

                                  var idTEXT = charIDToTypeID( "TEXT" );

                                  var idTEXT = charIDToTypeID( "TEXT" );

                                  var idbox = stringIDToTypeID( "box" );

                                  desc8.putEnumerated( idTEXT, idTEXT, idbox );

                                  var idbounds = stringIDToTypeID( "bounds" );

                                      var desc10 = new ActionDescriptor();

                                      var idTop = charIDToTypeID( "Top " );

                                      desc10.putDouble( idTop, 0.000000 );

                                      var idLeft = charIDToTypeID( "Left" );

                                      desc10.putDouble( idLeft, 0.000000 );

                                      var idBtom = charIDToTypeID( "Btom" );

                  // set height;

                                      desc10.putDouble( idBtom, 90 );

                                      var idRght = charIDToTypeID( "Rght" );

                  // set width;

                                      desc10.putDouble( idRght, 154 );

                                  var idRctn = charIDToTypeID( "Rctn" );

                                  desc8.putObject( idbounds, idRctn, desc10 );

                              var idtextShape = stringIDToTypeID( "textShape" );

                              list1.putObject( idtextShape, desc8 );

                          desc4.putList( idtextShape, list1 );

                      var idTxLr = charIDToTypeID( "TxLr" );

                      desc3.putObject( idT, idTxLr, desc4 );

                  executeAction( idsetd, desc3, DialogModes.NO );

                  }

                  };

                  • 6. Re: Fit frame to content but in Photoshop
                    Waterbear Level 1

                    You know, of all the people I discussed this with, no one has ever mentioned trying this out. I did and it works pretty well for me. Thanks!

                    • 7. Re: Fit frame to content but in Photoshop
                      Waterbear Level 1

                      As far as the scripting goes, I have no idea how to make them, just how to use them. Thanks for doing this though. Maybe I can give it to a friend of mine to see if he can finish it up. Thanks again for the help.

                      • 8. Re: Fit frame to content but in Photoshop
                        c.pfaffenbichler Level 9
                        no one has ever mentioned trying this out. I did and it works pretty well for me.

                        Automating this based on whether type layers have just one line or on less than a certain number of characters might be possible.