I need to know the size (dimensions) of images placed in an InDesign 5.5 document.
I have made the following script by combining different code. It gets the metadata OK, but the witdh and height are empty. Am I using getProperty wrong?
// Refr
// https://forums.adobe.com/thread/288764
// https://forums.adobe.com/thread/2288546 var scriptName = "Get description from selected link", doc; PreCheck(); //exif:PixelXDimension tiff:ImageWidth //===================================== FUNCTIONS ====================================== function Main(image) { var link = image.itemLink, metadata = link.linkXmp, description = metadata.description, format = metadata.format, author = metadata.author, modificationDate= metadata.modificationDate, creator = metadata.creator, myLinkWidth = metadata.getProperty("http://ns.adobe.com/tiff/1.0/", "tiff:ImageWidth"), myLinkLength = metadata.getProperty("http://ns.adobe.com/tiff/1.0/", "tiff:ImageLength"), Width = metadata.getProperty("http://ns.adobe.com/exif/1.0/", "exif:PixelXDimension"), Height = metadata.getProperty("http://ns.adobe.com/exif/1.0/", "exif:PixelYDimension"); alert("Description is: '" + description + "'\nFormat: " + format + "\nAuthor: " + author + "\nDate modified: " + modificationDate + "\nCreator: " + creator, scriptName, false); alert("Pixel dimentions of image:\nWidth: " + myLinkWidth + Width + " pixels\nHeight: " + myLinkLength + Height +" pixels"); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function PreCheck() { var image; if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true); doc = app.activeDocument; if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true); if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true); if (app.selection.length == 0 || app.selection.length > 1) ErrorExit("One image should be selected.", true); if (app.selection[0].constructor.name == "Image") { // image selected with white arrow image = app.selection[0]; } else if (app.selection[0].images.length > 0) { // container selected with black arrow image = app.selection[0].images[0]; } else { ErrorExit("No image in the selection.", true); } Main(image); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ErrorExit(error, icon) { alert(error, scriptName, icon); exit(); } //--------------------------------------------------------------------------------------------------------------------------------------------------------
I'll explain why I'm doing this:
I'm making a magazine and the photos we get are in all different sizes and quality. In a layer called "picName" I have text frames on top of images with information from Text Variables such as name of file, PPI, actual PPI, dimensions, and scale. I make a pdf of the magazine and while my editor proof reads and edits the document I fix the photos (I cannot use InDesign at same time as she.). I use the information from the picName-layer and an Excel-sheet to determine the right size of the images, and then I edit the images in Photshop.
It would be a lot easier to have the calculation in the pdf itself. What I hope to achive is:
- Get the width (W) of the linked image.
- Get the PPI (P) of the linked image.
- Get the scale (S) of the image in the frame (percent).
- Calculate the width the image should have: W * S * 300 / P
- Insert the width the image should have in a text frame in the picName-layer on top of the image.