Jump to content

Need help scaling images from url link


rkury14

Recommended Posts

Hi,

 

I have a "CreateResource" rule here that seems to work on a URL Link with https://, but the images are coming in at different sizes. Too small or too big.

How can I add a scaling code into the rule to make the images uniform?

 

Here is the js rule.

 

var baseName = Field("URL");

 

var extensions = [".tif", "gif", ".png", ".jpg"];

for (var i in extensions)

 

{ var pic = CreateResource(Field ("URL") + extensions, + "graphic", true);

if (pic.exists)

return pic;}

 

Print("http://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-12/256/thumbs-up" + Field ("URL") + " not found.");

return CreateResource(Field ("URL"))

return NullResource();

 

Thank you,

Link to comment
Share on other sites

You don't do the scaling in the rule. You do the scaling in the graphic frame, using the controls on the Graphic Frame palette. You probably want the Scaling set to Best Fit.

 

Once again, I would need to look at your template and your data to be able to make more specific suggestions.

Link to comment
Share on other sites

I am using a Text Frame window to apply the url from the list. There is only shrink to fit, but that doesn't work in this instance. Should I be using a graphic window? Because that would be asking for a path source which I don't have. I have attached the zip of the fusionpro template. I am looking for the best way to resize the image. Thank you,

20302_Shift_Mailer.zip

Link to comment
Share on other sites

Should I be using a graphic window?

Yes, absolutely.

Because that would be asking for a path source which I don't have.

I don't understand what you mean by "a path source". Who is asking for that?

 

You can create a Graphic rule with exactly the same code as in your Text rule, and assign the rule to a Graphic frame. From the New Rule dialog, select the Graphic radio button at the top, then select Empty Rule and click Next. You can literally copy the content from your Text rule into the Graphic rule.

I have attached the zip of the fusionpro template.

Thanks. I've attached a modified version with a Graphic rule and a Graphic frame, which I think does basically what you want.

 

I did make a few changes to your rule to clean up some unnecessary code.

 

I also changed it to first look for "png". The first record doesn't find the graphic without this change. The reason is that, when it looks for the URL with a "tif" extension, the web server returns an XML document with an error instead of the graphic, but because it's returning the XML, FusionPro thinks that it did successfully download the file, but it errors when trying to handle that XML as a graphic. (At least it works this way on Mac; it might still find the right graphic when composed on Windows, such as when you submit it to Producer.)

 

The moral of the story here is, you shouldn't really "test" for files downloaded from the Internet by extension, the way you can for local files. Your data should include the fully-resolved URL for each graphic, with the filename extension. Then your Graphic rule can be just the one-liner I mentioned in the previous thread:

return CreateResource(Field("URL"));

Also, in FusionPro 11 and later, you can accomplish this without any rule at all, by simply changing the field type to Graphic. From the menu in Acrobat, select FusionPro -> Data Definition -> Input Options, click Edit Fields, select the field and click Edit, then set the type to Graphic and the Subtype to File name. Then you can insert assign that field directly as the variable for a graphic frame, again, without any rule at all.

20302_Shift_Mailer-graphic-rule.pdf

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...