• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Lower quality until certain file size using 'save for web'

Guest
Jan 30, 2016 Jan 30, 2016

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

TOPICS
Actions and scripting

Views

320

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Jan 30, 2016 Jan 30, 2016

Copy link to clipboard

Copied

LATEST

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:

  • What if setting quality=0 does not satisfy limit
  • I'm not sure if File-objects are "realtime", the .length property updates the size after you save. If this happens, you need to create file_target after saving

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines