Calculate size in mm depending on dpi and print to output filename

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 :sweat_smile: 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ā€¦ :smile:
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ā€¦

1 Like