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

how to check the resolution of the linked images ?

New Here ,
Nov 16, 2009 Nov 16, 2009

Hi all,

Could anyone guide me to write  a illustrator script which will check the resolution of the linked file image file in dpi ?

thanks in advance,

Sanat

TOPICS
Scripting
1.6K
Translate
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

Guide , Nov 23, 2009 Nov 23, 2009

With Sonic's help I was able to get this to work for me. I only tested with .psd .tif & .jpeg

#target illustrator

var docRef = activeDocument;

with (docRef) {

// We are expecting 1 placed item (image) here!!!

var placedWidth = placedItems[0].width;

var placedHeight = placedItems[0].height;

var placedPath = placedItems[0].file;

// The 2 variables below are global

XpixelDimension = 0;

YpixelDimension = 0;

// Call the function

exifDimensions(placedPath);

// Calculate the Height & Width DPI's

var width

...
Translate
Adobe
Guide ,
Nov 19, 2009 Nov 19, 2009

Well I had a go at this and only got part way (still got the 'L' plates on with JavaScript). Im posting where I got to hoping either Sonic or Mark could help and show me too how to do the rest? Depending on what type of image file you have placed there should be the pixel height & width dimensions in the file head. The idea would be to read these out and calculate your DPI. Using Sonic's read function from another post (which is where Im now stuck doh!)

#target illustrator

main(); // Call to the main function

function main() {

with (app) {

if (documents.length > 0) {

var docRef = activeDocument;

with (docRef) {

// We are expecting 1 placed item (image) here!!!

var placedWidth = placedItems[0].width;

var placedHeight = placedItems[0].height;

var placedPath = placedItems[0].file;

// Call the function Im stuck with

var pixelWidth = x(placedPath);

var widthDPI = pixelWidth / (placedWidth / 72);

// var heightDPI = pixelHeight / (placedHeight / 72);

alert(widthDPI);

}

}

else {

alert('Please have a file open?');

return;

}

}

}

function x(y) {

var pixelWidth = null;

var pixelHeight = null;

y.open('r');

try {

while (y.tell() < y.length) {

var line = y.readln();

var idxOf = line.indexOf('<exif:PixelXDimension>');

if (idxOf > 0) {

pixelWidth = line.substring(idxOf+22, idxOf+25);

}

}

}

catch (ex) { alert('Fluff');}

  finally { y.close(); return [pixelWidth]; }

}

// <exif:PixelXDimension>400</exif:PixelXDimension>

// <exif:PixelYDimension>600</exif:PixelYDimension>

Once the first line is found how do you target the next? Also I think a reg ex would be required as the contained numbers could be of any length?

Translate
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 ,
Nov 19, 2009 Nov 19, 2009

a short tip before leaving to work

you dun need a regex for that because you have 2 pairs of  "<>" so something like

var line = y.readln();

var XpixelDimension, YpixelDimension;

var idxOf = (line.indexOf('<exif:PixelXDimension>') > -1) ? line.indexOf('<exif:PixelXDimension>') : line.indexOf('<exif:PixelYDimension>');

if(idxOf > -1) {

if(line.indexOf('<exif:PixelXDimension>') > -1) XpixelDimension = parseInt(line.substring(line.indexOf(">")+1, line.lastIndexOf("<")));

else YpixelDimension = parseInt(line.substring(line.indexOf(">")+1, line.lastIndexOf("<")));

should be enough. i`ll come along with the rest as soon as i have some spare time .

owh and the return of the function can be something like return new Array(XpixelDimension, YpixelDimension);

so you can use it like this:

var dimensions = the_name_of_the_function();

var myXDim = dimensions[0];

var myYDim = dimensions[1];

have a wonderful day;

cheers;

Translate
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
Guide ,
Nov 20, 2009 Nov 20, 2009

Thanks Sonic, for the couple of pointers. I had to go look up 'readIn' again… and 'tell' I had not come across before now all part of the learning process…

Translate
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
New Here ,
Nov 23, 2009 Nov 23, 2009
  • thanks u all.I tried all the codes abhove but its still not showing the exact pixel in dpi.
  • Any suggestions on it ?
Translate
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
Guide ,
Nov 23, 2009 Nov 23, 2009

With Sonic's help I was able to get this to work for me. I only tested with .psd .tif & .jpeg

#target illustrator

var docRef = activeDocument;

with (docRef) {

// We are expecting 1 placed item (image) here!!!

var placedWidth = placedItems[0].width;

var placedHeight = placedItems[0].height;

var placedPath = placedItems[0].file;

// The 2 variables below are global

XpixelDimension = 0;

YpixelDimension = 0;

// Call the function

exifDimensions(placedPath);

// Calculate the Height & Width DPI's

var widthDPI = Math.floor(XpixelDimension / (placedWidth / 72));

var heightDPI = Math.floor(YpixelDimension / (placedHeight / 72));

alert('Width DPI is ' + widthDPI + ' Height DPI is ' + heightDPI);

}

function exifDimensions(imageFilePath) {

imageFilePath.open('r');

try {

while (imageFilePath.tell() < imageFilePath.length) {

var line = imageFilePath.readln();

var idxOf = (line.indexOf('<exif:PixelXDimension>') > -1) ? line.indexOf('<exif:PixelXDimension>') : line.indexOf('<exif:PixelYDimension>');

if(idxOf > -1) {

if(line.indexOf('<exif:PixelXDimension>') > -1) XpixelDimension = parseInt(line.substring(line.indexOf(">")+1, line.lastIndexOf("<")));

else YpixelDimension = parseInt(line.substring(line.indexOf(">")+1, line.lastIndexOf("<")));

}

}

}

catch (ex) { alert('Fluff');}

  finally { imageFilePath.close(); return [XpixelDimension, YpixelDimension]; }

}

Translate
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
Guide ,
Jan 01, 2010 Jan 01, 2010
LATEST

Just incase you or anybody else for that matter still need to do this then I've found another way which is much better.

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

// We are expecting at least 1 placed item

var thisImage = placedItems[0].trace();

redraw();

thisImage.tracing.tracingOptions.resample = false;

var thisRes = thisImage.tracing.imageResolution;

alert(thisRes + ' DPI');

thisImage.tracing.releaseTracing();

}

Translate
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