• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Xml work flow - fit to text frame width for images

Contributor ,
Mar 18, 2016 Mar 18, 2016

Copy link to clipboard

Copied

Dear java script kings,

I was checking the scripting for based on the xml work flow. Here with i faced the problem, images not fixed in the text frame width (attached screenshot for your reference).


@ I needed: All images automatically fit to text frame width and resizing images also.

Text frame width: 325.984 pt

Text frame hight: 535.748 pt

This passable to script?.

Screen Shot 2016-03-17 at 6.04.15 PM.png

Advance Thanks

TOPICS
Scripting

Views

681

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Mar 18, 2016 Mar 18, 2016

HTH,

function main(){

  var doc = app.properties.activeDocument,

  rects, rect, n =0, columnWidth, ratio, rectBounds;

  if(!doc) return;

  rects = doc.stories.everyItem().rectangles.everyItem().getElements();

  n = rects.length;

  while ( n-- ) {

  rect = rects;

  if ( rect.parent.parentTextFrames.length ) {

  columnWidth = rect.parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;

  rectBounds = rect.visibleBounds;

  ratio = columnWidth/(Math.abs(rectBounds[3]-rectBounds[1])

...

Votes

Translate

Translate
People's Champ ,
Mar 18, 2016 Mar 18, 2016

Copy link to clipboard

Copied

HTH,

function main(){

  var doc = app.properties.activeDocument,

  rects, rect, n =0, columnWidth, ratio, rectBounds;

  if(!doc) return;

  rects = doc.stories.everyItem().rectangles.everyItem().getElements();

  n = rects.length;

  while ( n-- ) {

  rect = rects;

  if ( rect.parent.parentTextFrames.length ) {

  columnWidth = rect.parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;

  rectBounds = rect.visibleBounds;

  ratio = columnWidth/(Math.abs(rectBounds[3]-rectBounds[1]));

  rect.resize ( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, [ratio,ratio] );

  }

  }

}

app.doScript( "main();", u,u, UndoModes.ENTIRE_SCRIPT, "Fit images to column" );

Loïc

www.ozalto.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 18, 2016 Mar 18, 2016

Copy link to clipboard

Copied

Dear Loic.Aigon

Thanks so match for your response.

I try your coding and get back to you. one more thanks Loic.Aigon‌.

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 22, 2016 Mar 22, 2016

Copy link to clipboard

Copied

HI Loic.Aigon

First, sorry for the late replay.

I have run your above coding. That coding showed some error comment "u is undefined" (attached screen shot for your reference). I don't now how to clear this type problem friends.

Screen Shot 2016-03-22 at 2.39.09 PM.png

One question: what is meaning for "u".

Advance Thanks,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 22, 2016 Mar 22, 2016

Copy link to clipboard

Copied

My bad. You need to add this line prior to call doScript:

var u;

app.doScript…

u stands for undefined as it is actually…undefined.

Loic

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 22, 2016 Mar 22, 2016

Copy link to clipboard

Copied

HI Loic.Aigon,

Thank you so match friend.  Your script working good.

One quick question: It is possible to reduced the image size in the java script? based no the text width frame. Please advice friend.

Advance Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 22, 2016 Mar 22, 2016

Copy link to clipboard

Copied

It's sure possible. Images are children of the rectangle object and have geometric properties you can take advantage of:

rect.graphics[0].geometricBounds = …

or rect.graphics[0].absoluteHorizontalScale = …

or rect.graphics[0].resize (…

or rect.graphics[0].transform (…

etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 22, 2016 Mar 22, 2016

Copy link to clipboard

Copied

LATEST

Hi Loic.Aigon,

OK, i will try your suggestion and get back to you.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines