CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
How to resize Graphic to specific inches ?
Tagged: resize graphic
- This topic has 12 replies, 2 voices, and was last updated 8 years, 9 months ago by
Kathy Cote.
-
AuthorPosts
-
-
December 19, 2016 at 8:11 am #90595
Kathy Cote
MemberHi,
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); -
December 19, 2016 at 8:24 am #90596
Anonymous
InactiveHi,
If the performance is bearable, why not simply require some fitting ?
app.selection[0].fit ( FitOptions. PROPORTIONALLY );
?
-
December 19, 2016 at 8:46 am #90598
Kathy Cote
MemberHi,
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 ;-)
-
December 19, 2016 at 9:04 am #90599
Anonymous
InactiveSorry 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
-
December 19, 2016 at 9:34 am #90600
Kathy Cote
MemberHi,
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
-
December 19, 2016 at 9:34 am #90601
Kathy Cote
MemberHi,
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
-
December 19, 2016 at 10:13 am #90602
Kathy Cote
MemberHi,
ok this code worksvar 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])
-
December 19, 2016 at 10:42 am #90603
Kathy Cote
MemberHi,
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]) -
December 19, 2016 at 5:29 pm #90616
Anonymous
Inactiveok 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” );
-
December 20, 2016 at 7:05 am #90627
Kathy Cote
MemberHi,
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.
-
December 20, 2016 at 7:32 am #90628
Anonymous
InactiveHere 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” ); -
December 20, 2016 at 7:43 am #90629
Anonymous
InactivePlease 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” ); -
December 20, 2016 at 11:23 am #90633
Kathy Cote
MemberHi,
This is exactly what I needed.Another big thank you for your help so precious.
Thanks!
Kathy
-
-
AuthorPosts
- You must be logged in to reply to this topic.
