Hi! Is there a way to calculate image size in mm depending on dpi and print to output filename? Found only width and height in pixels. Maybe with java script? But unfortunately I am not good at it
Thanks and Greetings from a newbie!
If you change the measurement unit from pixels to cm (via control-clicking the ruler (⌘R) or with the Action Bar command “Use Centimeters for Measurement”), Acorn’s ruler will show you what the output will be based on the image size.
You can also use the Measurement tool (https://flyingmeat.com/acorn/docs/measurement_tool.html) to measure out a part of your image and say, “I know this is 100m, so set the resolution based on that”.
I’d try those two options out and let us know how it works for you (or if it doesn’t make sense at all or I’ve completely missed the question).
-gus
My apologies, my brain was on Acorn and I should have seen this was a Retrobatch question.
Yes, you could do this with JavaScript. You can create a JavaScript node and paste the following in (without the print statements if you’d like):
function processAsset(document, jsnode, asset) {
var dpi = asset.dpi();
var width = asset.imageWidth();
var widthInIn = width / dpi;
var widthInMm = widthInIn * 25.4;
print(`widthInIn: ${widthInIn}`)
print(`widthInMm: ${widthInMm}`)
print(`dpi: ${dpi}`)
print(`width: ${width}`)
asset.setOutputFileName(`${widthInMm}.png`)
return true;
}
Wow, cool this works like magic for a non-tech designer… ![]()
I tried to fiddle around, but could not find a way to achieve rounding to full mm, and add height also: “Original-Filename_x” e.g.“This-is-my-filename_200x500.jpg”
This was my try, but returned only “undefined_{widthInMm}x{heightInMm}.jpg”
function processAsset(document, jsnode, asset) {
var dpi = asset.dpi();
var width = asset.imageWidth();
var height = asset.imageHeight();
var filename = asset.outputFilename();
var widthInIn = width / dpi;
var widthInMm = Math.round(widthInIn * 25.4);
var heightInIn = height / dpi;
var heightInMm = Math.round(heightInIn * 25.4);
print(`widthInIn: ${widthInIn}`)
print(`widthInMm: ${widthInMm}`)
print(`dpi: ${dpi}`)
print(`width: ${width}`)
asset.setOutputFileName(`${filename}_{widthInMm}x{heightInMm}.jpg`)
return true;
}
Thank you so much for your help!
Frank
You’ve got a couple of typos in there. You’ll need a capital N in the setOutputFileName method, and you’re missing a $ in front of the {widthInMm} and {heightInMm}.
Here it is with the fixes:
function processAsset(document, jsnode, asset) {
var dpi = asset.dpi();
var width = asset.imageWidth();
var height = asset.imageHeight();
var filename = asset.outputFileName();
var widthInIn = width / dpi;
var widthInMm = Math.round(widthInIn * 25.4);
var heightInIn = height / dpi;
var heightInMm = Math.round(heightInIn * 25.4);
print(`widthInIn: ${widthInIn}`)
print(`widthInMm: ${widthInMm}`)
print(`dpi: ${dpi}`)
print(`width: ${width}`)
asset.setOutputFileName(`${filename}_${widthInMm}x${heightInMm}.jpg`)
return true;
}
Thank you so much for helping! Still learning a lot! Now it’s working almost. Just the output contains now 2 extensions “Filename.jpg_100x200.jpg”. Seems FileName includes the extension".jpg". I managed to fix this with a rename node to replace “.jpg” with nothing…