Created
April 22, 2021 15:22
-
-
Save quantixed/5fb869227563ce2288dfd868090514b5 to your computer and use it in GitHub Desktop.
Deduce the page width size needed for a 300 dpi png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Figure out the width of png images for Overleaf | |
* png are 300 dpi and page width is 170 mm | |
*/ | |
#@ File (label = "Input directory", style = "directory") input | |
#@ String (label = "File suffix", value = ".png") suffix | |
setBatchMode(true); | |
processFolder(input); | |
// function to scan folders/subfolders/files to find files with correct suffix | |
function processFolder(input) { | |
list = getFileList(input); | |
list = Array.sort(list); | |
for (i = 0; i < list.length; i++) { | |
if(File.isDirectory(input + File.separator + list[i])) | |
processFolder(input + File.separator + list[i]); | |
if(endsWith(list[i], suffix)) | |
processFile(input, list[i]); | |
} | |
} | |
function processFile(input, file) { | |
print("Processing: " + file); | |
open(input + File.separator + file); | |
getDimensions(width, height, channels, slices, frames); | |
pagefrac = ((width / 300) * 25.4) / 170; | |
print("Image is: " + d2s(width,0) + "pixels. Page width is: " + d2s(pagefrac,2)); | |
close(); | |
} | |
setBatchMode(false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment