Jump to content

Move a text frame based on the size of a graphic


Ryan_B

Recommended Posts

I was wondering if there is a way to dynamically set the x coordinates of a text frame based on the dimensions of an uploaded graphic.

 

I have a graphic frame that the user uploads a logo to. To the left of said frame I have a text frame that holds the company's slogan. I'm looking for a way to move the text frame so that it always butt's up against the left of the uploaded logo.

 

My original thought was to use FusionProTextMeasure to get the width of the uploaded graphic, using:

var graphic = Field("Logo");

function getGraphicWidth(input){
   var tm = new FusionProTextMeasure;
   tm.useTags = true;
   tm.CalculateTextExtent(input);
   return tm.textWidth;
}
return getGraphicWidth(graphic);

 

Using that returned value and doing some calculations, I would be able to set my x coordinates for my text frame in order for it to butt up against the graphic frame. The problem I'm realizing is that the returned value is the width of the graphic before getting resized to fit in the graphic frame. So hypothetically, if the uploaded image was larger than the graphic frame, or the template itself, the returned value for the width would obviously not be accurate, thus making my text frame not butt up against the logo.

 

In closing, is there a way to get the width of an uploaded image after it's been inserted into a graphic frame? Or, if anyone knows of a simpler/better/more accurate way of doing this, I'm all ears. TIA.

Link to comment
Share on other sites

You're really asking two questions:

  1. Can the position of a frame be modified?
  2. Can the final result of scaling a graphic to a graphic frame be determined?

The answer to both is Yes, with some qualifications.

 

Frames can be moved and resized like so:

FindTextFrame("YourFrameName").x = 7200; // <- value in hundredths of points

But you need to compose with Producer or Server. If you are composing only locally in Creator/Desktop, then you can't move a frame, but you can do things like adjust the left indent, or use a table, or some other tricks, to position text.

 

As for finding the final scaling applied to a graphic, FusionPro won't tell you that exactly, but you can figure it out. Depending on what scaling factor you have applied to the graphic frame, you can do some math to basically duplicate what FusionPro is doing to the graphic, based on the initial width and height of the graphic itself, which you already know how to get using FusionProTextMeasure, and the dimensions of the frame, which you can get by calling FindGraphicFrame and accessing properties such as width and height from the returned object. (You can also interrogate the scaling and positioning set for the graphic frame. Note that you do NOT need a Producer or Server license to get this frame information, only to modify a frame's position or size.)

 

However, depending on how the job is set up, you might just want to use an inline graphic, with a hard-coded height in the <graphic> tag, which will automatically scale the graphic proportionally and line the text up with it.

 

I might be able to offer more specific suggestions if I could see what you're trying to do, even just a picture of the desired output for a couple different variations.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...