Copy link to clipboard
Copied
Hey everyone,
I will try to describe the task I am currently trying to automate in Photoshop CS6.
I would like to open a .tiff image (/raw/test.tiff), resize the longest side to 500px and save in one folder with original name (/500/test.jpg), and then resize the longest side to 350px and save to different folder (/350/test.jpg)
The tricky part is that the images in the 350 folder need to be less than 50kb in size. When I do this manually, I use the 'save for web' dialog and lower the quality until the filesize is lower than 50kb.
Is there anyway to automate this? Is there a script that can compare quality and filesize?
I am currently using an action that uses 'automate>fit image' for the first parts, but i have to manually do the final 'save for web' and change the directory.
Any help would be greatly appreciated!
Thanks
Copy link to clipboard
Copied
Should be possible in some way like below (filling in the blanks/fixing the bugs is left as exercise to the reader)
var jpg_options = new JPEGSaveOptions()
var file_original = new File('path to original')
var file_target = new File('path to target')
var w, h = // do some math to calculate what size you need to resize to
var doc = app.open(file_original)
doc.resizeImage(w, h)
for (var quality=12; i>=0; i--) {
jpg_options.quality = quality
doc.saveAs(file_target, jpg_options)
if (file_target.length <= 50*1024) {
break
}
}
doc.close()
Two potential issues: