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ā¦