8 Replies Latest reply on Jun 3, 2016 4:22 AM by Marc Autret

    [JS] Resize textframe with image


      Hi There,


      quick brief of what I am trying to achieve.


      I am using .place to put a barcode.eps file into a textframe, none of the .fit options properly fit the barcode into the space available comfortably without looking stretched.


      the plan is to create the textframe at double the height required, insert the image with .fit(FitOptions.proportionally); and then resize the textframe back to the height required which should "chop" off the top half of the barcode which is perfectly fine.


      alas, upon doing this via .geometricBounds the image is disappearing from the frame.


      does anyone have any ideas how to not make the image disappear or even a better way of resizing the image? (without user interaction)




      here is my block for the barcode frame


        barcodeFrame = addFrame(307, 325.5, 36, 36, '123');
        barcodeFrame.place(File("barcodepiece+".eps"), false);
        barcodeFrame.name = "imgFrameGCS["+index+"]";
        barcodeFrame.fillColor = myDocument.swatches.item("None");
        barcodeFrame.geometricBounds = [ 307, 338, 36, 13.5 ]
        • 1. Re: [JS] Resize textframe with image
          vinothr Level 3

          Can you provide some snapshots of how it looks, and how it should look (desired) in the layout...?

          Would be better to provide better solution. I will see what help I can provide.

          • 2. Re: [JS] Resize textframe with image
            pauls983716 Level 1

            please see below graphic example.


            the first graphic is how I am placing it prior to changing the geometric bounds.


            the black rectangle is the rectangle border for the area i'm placing it in, the green rectangle is the textframe in question




            what i want to do is resize the textframe down in height so that the graphic stays in place but it essentially chops off the top half and looks like the below



            I am open to other ways to achieve the same goal.



            • 3. Re: [JS] Resize textframe with image
              vinothr Level 3

              What you have done...

              1. Created text frame with predefined size

              2. Placed image into text frame

              3. Fill content proportionally and center content


              Now instead of resizing the text frame you can try below:

              The placed image is child of the rectangle...so you can resize the image proportionally and adjust its coordinates...


              var placedImage = rectangle.images.item(0);


              Now, set geometricBounds of placedImage as per your needs.

              • 4. Re: [JS] Resize textframe with image
                pauls983716 Level 1

                Thanks for the help,


                I'm not sure the image is a child of the rectangle as they are placed independently.


                i've used the following lines


                var placedImage = myRectangle.images.item(0);

                placedImage.geometricBounds = [300, 300, 310, 310];

                and unfortunately received the following error "Object is invalid" relating to the geometrics bound line.


                any ideas?

                • 5. Re: [JS] Resize textframe with image
                  vinothr Level 3

                  I do not know how you got the "myRectangle".

                  But try this...


                  Use the Selection Tool to select the rectangle that contains the placed image...



                  app.selection[0] // gives you rectangle

                  app.selection[0].images.item(0) // gives you image inside the rectangle


                  So, after you select the rectangle using Selection Tool, run the following...

                  app.selection[0].images.item(0).geometricBounds = [y1, x1, y2, x2];


                  You can also check the current geometricBounds value of image by $.writeln(app.selection[0].images.item(0).geometricBounds)

                  And then supply values of y1, x1, y2 and x2 as per your needs.

                  • 6. Re: [JS] Resize textframe with image
                    pauls983716 Level 1

                    this is the line used to define the rectangle myRectangle = myDocument.rectangles.add({geometricBounds:[337, 306, 364.4, 343.9]});


                    Unfortunately I am unable to use the selection tool as the script is to create a document and layout the necessary info without any user interaction.


                    calling .geometricBounds on placedImage returns the same issue.

                    • 7. Re: [JS] Resize textframe with image
                      vinothr Level 3

                      ok...can you try the code in a new document and using ExtendScript check the above code.

                      First, do the R&D in your document and then apply the required code where you need.

                      • 8. Re: [JS] Resize textframe with image
                        Marc Autret Level 5



                        As far as I understand the issue, it's all about changing the TOP bound of the container (Rectangle) without repositioning the content (EPS object.) Make sure the frameFittingOptions.autoFit property is set to FALSE, as follows


                        // YOUR SETTINGS
                        // ---
                        var INIT_BOUNDS = [337, 306, 364.4, 343.9],
                            REDUCE_HEIGHT_BY = 15;
                        var bcFrame = doc.rectangles.add({
                            geometricBounds: INIT_BOUNDS,
                            fillColor: 'None',
                            strokeColor: 'None',
                            frameFittingOptions: { autoFit: false }, // important!
                        var eps = bcFrame.place(File("~/barcode.eps"), false)[0];
                        bcFrame.geometricBounds = [INIT_BOUNDS[0]+REDUCE_HEIGHT_BY].concat(INIT_BOUNDS.slice(1));
                        // etc.


                        Hope that helps.