Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

How to resize Graphic to specific inches ?

Return to Member Forum

  • Author
    Posts
    • #90595
      Kathy Cote
      Member

      Hi,

      I would like the height of the image to be of the same height as the box image. I want to be able to write a value in inches for the width and that the vertical stay proportional. (Like when you Enter a data in inch in the scale X Percentage.)

      I think I’m almost there but I need your help to complete.

      Would anyone have the solution? I use Indesign 2015.
      Let me know if you need more information.

      Thanks for your help!

      Kathy

      //Part of my code

      //I tried this, but it works only with % and does not resize proportionately.
      with (myGraphic){
      geometricBounds = [-0.25,-0.25,11.25,8.75];
      var myBounds = myGraphic.geometricBounds;
      myGraphic.horizontalScale = myBounds[50]; //I dont want to use % scale, I want inches.
      }

      //I tried this
      myFrame.geometricBounds = [-0.25,-0.25,11.25,8.75]; //Image Frame

      //I need myGraphic to be the same height as: myBounds[2], but the default measurement is in points and is not proportional.
      //I would like to use variables instead of 648 and 828 and I want to keep the vertical proportional.
      myGraphic.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [648, 828]);
      var myBounds = myFrame.geometricBounds;
      var myHeight = myBounds[2];
      alert(myHeight);

    • #90596
      Anonymous
      Inactive

      Hi,

      If the performance is bearable, why not simply require some fitting ?

      app.selection[0].fit ( FitOptions. PROPORTIONALLY );

      ?

    • #90598
      Kathy Cote
      Member

      Hi,
      No because I want the image to be the same height as my box image but the width can vary.
      Once the correct height, I center the image in the box. The image may be wider than the box itself.

      Thanks ;-)

    • #90599
      Anonymous
      Inactive

      Sorry to insist but what about:

      app.selection[0].fit ( FitOptions.PROPORTIONALLY );
      app.selection[0].fit ( FitOptions.CENTER_CONTENT );

      ?

      But to be helpful, as resize require points, an easy way out with delaing with units is using an UnitValue Object:

      var w = new UnitValue ( “3in” ).as(‘pt’);
      var h = new UnitValue ( “2in” ).as(‘pt’);

      myGraphic.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [w, h]);

      FWIW

    • #90600
      Kathy Cote
      Member

      Hi,

      We almost succeeded. If I use the code as below, it works.
      I only want to change the value of the variable w, I would like to have the height of my page (which is variable).

      /////

      var myHeight = myDocument.documentPreferences.pageHeight;

      //Instead of 3in, I would like to have height of my page. Is it possible ?
      var w = new UnitValue (“3in”).as(“pt”);

      myGraphic.resize(CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,ResizeConstraints.KEEP_CURRENT_PROPORTIONS]);

      Thanks again ;-)

      Kathy

    • #90601
      Kathy Cote
      Member

      Hi,

      We almost succeeded. If I use the code as below, it works.
      I only want to change the value of the variable w, I would like to have the height of my page (which is variable).

      /////

      var myHeight = myDocument.documentPreferences.pageHeight;

      //Instead of 3in, I would like to have height of my page. Is it possible ?
      var w = new UnitValue (“3in”).as(“pt”);

      myGraphic.resize(CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,ResizeConstraints.KEEP_CURRENT_PROPORTIONS]);

      Thanks again ;-)

      Kathy

    • #90602
      Kathy Cote
      Member

      Hi,
      ok this code works

      var PWidth = myDocument.documentPreferences.pageWidth;
      var myNumber = parseFloat(PWidth);
      var FinalWidth = myNumber + “in”;
      alert (FinalWidth);
      var w = new UnitValue(FinalWidth).as(“pt”);

      myGraphic.resize(CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,ResizeConstraints.KEEP_CURRENT_PROPORTIONS])

    • #90603
      Kathy Cote
      Member

      Hi,
      ok to do fit image depending on the width of the document.

      And now if I want the picture fit height of the Height size?

      I cannot use: app.selection[0].fit ( FitOptions.PROPORTIONALLY );
      Because it adjusts the image to be fully visible in the frame.
      If I use a fit proportionally in height, the image may be wider than the Frame and it’s ok. It’s what I want.

      ///////////

      var PHeight = myDocument.documentPreferences.pageHeight;
      var myHeight = parseFloat(PHeight);
      var FinalHeight = myHeight + “in”;
      alert (FinalHeight);
      var h = new UnitValue(FinalHeight).as(“pt”);

      //How to do not have the value w? I want a fit Height and not width. Width is forced to be there?
      myGraphic.resize(CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h,ResizeConstraints.KEEP_CURRENT_PROPORTIONS])

    • #90616
      Anonymous
      Inactive

      ok what about this :

      //Given that myGraphic is a Graphic instance

      var frame = myGraphic.parent;
      frame.visibleBounds = frame.parentPage.bounds;
      frame.fit ( FitOptions.PROPORTIONALLY ); //OR FILL_PROPORTIONALLY if you don’t mind cropped data
      frame.fit ( FitOptions.CENTER_CONTENT);

      ?

      Also see this :

      var main = function() {
      var doc = app.properties.activeDocument;
      if ( !doc || app.selection.length!=1 ) return;
      if ( ! ( app.selection[0] instanceof Rectangle ) ){
      alert(“Please select some container”);
      return;
      }

      var rect =app.selection[0];
      if ( !rect.graphics.length ) {
      alert(“The item needs a placed graphic”);
      return;
      }

      var graphic = rect.graphics[0];
      var page = rect.properties.parentPage;

      if ( !page ) {
      alert(“The item is not placed on a page”);
      return;
      }

      var pageBounds = page.bounds;

      var itemBounds = graphic.geometricBounds;
      var itemHeight = Math.abs ( itemBounds[2]-itemBounds[0] );
      var pageHeight = Math.abs ( pageBounds[2]-pageBounds[0] );
      var pageWidth = Math.abs ( pageBounds[3]-pageBounds[1] );

      var ratio = pageHeight/itemHeight;
      const cs = CoordinateSpaces.INNER_COORDINATES,
      ap = AnchorPoint.TOP_LEFT_ANCHOR,
      rm = ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY;

      graphic.resize ( cs, ap, rm, [ratio,ratio] );
      itemBounds = graphic.geometricBounds;
      var itemWidth = Math.abs ( itemBounds[3]-itemBounds[1] );
      graphic.move([(pageBounds[1]-(Math.max (itemWidth, pageWidth)-Math.min(itemWidth, pageWidth))/2),0]);

      rect.visibleBounds = page.bounds;

      }

      var u;

      app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

    • #90627
      Kathy Cote
      Member

      Hi,
      oh wow, you’re like a Jeidi ;-) It works very well.
      There is just a small part that I tried to modify but I am not able to because I’m just a padawan.

      Is not exactly : var pageBounds = page.bounds; that I need because the image size frame must also include bleed.
      Do you think this can be done?

      Thanks a lot for your help. This is very much appreciated.

    • #90628
      Anonymous
      Inactive

      Here you are:

      var main = function() {
      var doc = app.properties.activeDocument;
      if ( !doc || app.selection.length!=1 ) return;
      if ( ! ( app.selection[0] instanceof Rectangle ) ){
      alert(“Please select some container”);
      return;
      }
      var rect =app.selection[0];
      if ( !rect.graphics.length ) {
      alert(“The item needs a placed graphic”);
      return;
      }
      var graphic = rect.graphics[0];
      var page = rect.properties.parentPage;
      if ( !page ) {
      alert(“The item is not placed on a page”);
      return;
      }
      var pageBounds = page.bounds;
      var docPrefs = doc.documentPreferences;
      var facingPages = docPrefs.facingPages;
      var side = page.side;
      var right = side = PageSideOptions.RIGHT_HAND;
      var insideBleed = docPrefs.documentBleedInsideOrLeftOffset;
      var outsideBleed = docPrefs.documentBleedOutsideOrRightOffset;
      pageBounds = [
      pageBounds[0] – (docPrefs.documentBleedTopOffset ),
      pageBounds[1] – (facingPages? (right? insideBleed : outsideBleed) : insideBleed ),
      pageBounds[2] + ( docPrefs.documentBleedBottomOffset ),
      pageBounds[3]+ ( facingPages? (right? outsideBleed : insideBleed) : outsideBleed )
      ];

      var itemBounds = graphic.geometricBounds;
      var itemHeight = Math.abs ( itemBounds[2]-itemBounds[0] );
      var pageHeight = Math.abs ( pageBounds[2]-pageBounds[0] );
      var pageWidth = Math.abs ( pageBounds[3]-pageBounds[1] );
      var ratio = pageHeight/itemHeight;
      const cs = CoordinateSpaces.INNER_COORDINATES,
      ap = AnchorPoint.TOP_LEFT_ANCHOR,
      rm = ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY;
      graphic.resize ( cs, ap, rm, [ratio,ratio] );
      itemBounds = graphic.geometricBounds;
      var itemWidth = Math.abs ( itemBounds[3]-itemBounds[1] );
      rect.visibleBounds = pageBounds;
      graphic.move([(pageBounds[1]-(Math.max (itemWidth, pageWidth)-Math.min(itemWidth, pageWidth))/2),pageBounds[0]]);

      }
      var u;
      app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

    • #90629
      Anonymous
      Inactive

      Please find here a revised version

      var main = function() {
      var doc = app.properties.activeDocument;
      if ( !doc || app.selection.length!=1 ) return;
      if ( ! ( app.selection[0] instanceof Rectangle ) ){
      alert(“Please select some container”);
      return;
      }
      var rect =app.selection[0];
      if ( !rect.graphics.length ) {
      alert(“The item needs a placed graphic”);
      return;
      }
      var graphic = rect.graphics[0];
      var page = rect.properties.parentPage;
      if ( !page ) {
      alert(“The item is not placed on a page”);
      return;
      }
      var pageBounds = page.bounds;
      var docPrefs = doc.documentPreferences;
      var facingPages = docPrefs.facingPages;
      var side = page.side;
      var right = side == PageSideOptions.RIGHT_HAND;
      var insideBleed = docPrefs.documentBleedInsideOrLeftOffset;
      var outsideBleed = docPrefs.documentBleedOutsideOrRightOffset;
      pageBounds = [
      pageBounds[0] – (docPrefs.documentBleedTopOffset ),
      pageBounds[1] – (facingPages? (right? 0 : outsideBleed) : insideBleed ),
      pageBounds[2] + ( docPrefs.documentBleedBottomOffset ),
      pageBounds[3]+ ( facingPages? (right? outsideBleed : 0) : outsideBleed )
      ];

      var itemBounds = graphic.geometricBounds;
      var itemHeight = Math.abs ( itemBounds[2]-itemBounds[0] );
      var pageHeight = Math.abs ( pageBounds[2]-pageBounds[0] );
      var pageWidth = Math.abs ( pageBounds[3]-pageBounds[1] );
      var ratio = pageHeight/itemHeight;
      const cs = CoordinateSpaces.INNER_COORDINATES,
      ap = AnchorPoint.TOP_LEFT_ANCHOR,
      rm = ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY;
      graphic.resize ( cs, ap, rm, [ratio,ratio] );
      itemBounds = graphic.geometricBounds;
      var itemWidth = Math.abs ( itemBounds[3]-itemBounds[1] );
      rect.visibleBounds = pageBounds;
      graphic.move([(pageBounds[1]-(Math.max (itemWidth, pageWidth)-Math.min(itemWidth, pageWidth))/2),pageBounds[0]]);

      }
      var u;
      app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

    • #90633
      Kathy Cote
      Member

      Hi,
      This is exactly what I needed.

      Another big thank you for your help so precious.

      Thanks!

      Kathy

Viewing 12 reply threads
  • You must be logged in to reply to this topic.
Forum Ads