DPChallenge: A Digital Photography Contest You are not logged in. (log in or register
 

DPChallenge Forums >> Hardware and Software >> Automate Save for Web, Optimize Filesize
Pages:  
Showing posts 1 - 11 of 11, (reverse)
AuthorThread
03/06/2008 07:59:05 PM · #1
Does anyone know (in CS2) how to automate the Save for Web AND Optimize to Filesize as a batch process? A simple action does not cut it since the action is written with a predetermined compression value which is not the same for every file.

I can do with with a SendKey .VBS script, but if there was another way, within CS2, I'd like to know.

Thanks,
Paul
03/06/2008 09:12:15 PM · #2
Bump....maybe?
03/06/2008 10:18:05 PM · #3
I don't know if it can be done with actions or by another way from within Photoshop itself but it appears that Photoshop DOM does not provide a way to calculate the output file size for a given JPEG compression rate. So even if you decide to write a script or an application, such as one written in .NET using Photoshop automation, you'll still have to do the calculation yourself so as to determine the compression rate that results in the desired file size. And as far as I know (mind you, I'm no expert in this area, so don't just take my word for it), that requires quite a bit of programming work, no to mention intimate knowledge of the nuts and bolts of JPEG file structure, huffman tables and DCT quantization and what not. I don't think the "SendKeys" method will work very well either, but of course you can always give it a try and see if you can get it to work. I'm thinking that a little bit better, yet still clunky, apporach might be to send messages with the calculated parameters from your application to Photoshop. If you have Spy++ or any other application that hooks into the Windows messaging, you can find out about those messages that you need.
03/06/2008 10:34:41 PM · #4
The SendKeys should work, in theory as long as all commands are accessible by key strokes and not a mouse. I haven't tried to see that yet.

I've done long SendKeys scripts before and it works well, a little slow, but works.

Hmmm.....since it seems as though I have a lot of problems finding things on the web, and the limited response here....I may have to look at more creative ways....

Thanks for the response.
03/06/2008 11:33:37 PM · #5
you could write some javascript to do it. Adobe provide good developer info on how to script photoshop. If you know any sort of programming, it is pretty easy to do.


Message edited by author 2008-03-06 23:52:33.
03/06/2008 11:55:04 PM · #6
Originally posted by Gordon:

you could write some pretty trivial javascript to do it. Adobe provide pretty good developer info on how to script photoshop. If you know any sort of programming, it is pretty easy to do.


The problem is not in writing a script. Heck, you don't even need to know any programming language or write a single line of code. Just put the ScriptListener plug-in that comes with Photoshop in the Plug-ins folder, open PS, do your stuff and PS will generate both JavaScript and VB Script for everyting you've done. Open any one of them, delete the parts you don't need and voila! Your script is ready. The problem, in OP's case, is in determining the compression ratio for a desired file size or vice versa, and in my initial tests I noticed that PS DOM provides no way to do that (i.e. it just uses a fixed compression rate, which was keyed in by the user while recording the script, to be passed as parameter to the ActionDescriptor instance. And my quick search through the whole PS object model did not reveal any useful method either). Therefore it seems that one has to sit down and do some advanced programming so as to determine the correct compression ratio for each file in the batch. But I might be wrong, as I have not messed with it long enough to see if there's an easier way to accomplish that. But I'm pretty sure that no "trivial" script will do he job.

Message edited by author 2008-03-06 23:59:13.
03/07/2008 07:09:39 AM · #7
So the question is this...in the Save for Web dialog box, you can selection Optimize for File Size. The trick is getting the script to run that part of the dialog box every time. That is what an action simply can't do.

I'll look into that plug in you're talking about...thanks.
03/07/2008 07:10:37 AM · #8
Ah....Perhaps I should read the content of:

Adobe Photoshop CS2\Scripting Guide
03/07/2008 08:28:44 AM · #9
You can create an action within photoshop but as far a the file size you will have to tpye that in each time unless you want to select the same amount each time but that could be a bad thing as each picture has a different amount of pixels in it.

Open a picture in CS2

Click on your actions tab. (If it’s not up click ALT+F9 )

At the bottom of the actions tab there is a create new action button right next to the trash can.

Once the dialog box pops up type in a name for the action “SFW action” would work. You can create your action in the default actions set. If you want to move it later you can.

Click record

Once the box closes you are recording so do these steps exactly.

On the menu bar go to >IMAGE >IMAGE SIZE and set the image size that you like. I choose 640 for my width and let CS2 change the other number automatically. For this to work you have to have the “constraint proportions” box at the bottom checked.

After choosing a image size click ok.

Then on the actions pallet in the top right hand corner there is a little triangle that points to the right. Click on this button and a pop up window will come up. Go down to >INSERT MENU ITEM.

Another popup box will come up. Leave it alone until you have chosen your menu item..
Go to >FILE >SAVE FOR WEB
Then click OK on the pop up box

You’re box should close. From there click on the STOP button right next to the red record button on the actions pallet.

If you want to close the picture you can, OR you can leave it open and close it manually each time you run the action.
If you DO want to have the action close the picture for you click on the record button again and then just close the picture. Make sure you choose NO when it asks you to save your image.

Click Stop

To batch this file click on >FILE >AUTOMATE >BATCH
Choose your action and the folder you want to batch, the destination you want it to go to and click ok


Message edited by author 2008-03-07 08:32:40.
03/07/2008 08:34:06 AM · #10
If you don't want to have to do any manual input you can do the same action but instead of using SFW you can just use the save option and choose a file size from the pop up menu.
03/07/2008 08:40:57 AM · #11
Originally posted by Tycho:

Originally posted by Gordon:

you could write some pretty trivial javascript to do it. Adobe provide pretty good developer info on how to script photoshop. If you know any sort of programming, it is pretty easy to do.


The problem is not in writing a script. Heck, you don't even need to know any programming language or write a single line of code. Just put the ScriptListener plug-in that comes with Photoshop in the Plug-ins folder, open PS, do your stuff and PS will generate both JavaScript and VB Script for everyting you've done. Open any one of them, delete the parts you don't need and voila! Your script is ready. The problem, in OP's case, is in determining the compression ratio for a desired file size or vice versa, and in my initial tests I noticed that PS DOM provides no way to do that (i.e. it just uses a fixed compression rate, which was keyed in by the user while recording the script, to be passed as parameter to the ActionDescriptor instance. And my quick search through the whole PS object model did not reveal any useful method either). Therefore it seems that one has to sit down and do some advanced programming so as to determine the correct compression ratio for each file in the batch. But I might be wrong, as I have not messed with it long enough to see if there's an easier way to accomplish that. But I'm pretty sure that no "trivial" script will do he job.


The script listener doesn't record the 'optimise to file size' setting in the save for web dialog. It also produces nasty code.

But the trivial script looks something like:

save at 50% and get file size

(the ExportOptionsSaveForWeb quality setting is a percentage and accessable)
(the file object provides a length property for files on the disk)

check file size - too big at 50%, try 25%, too small at 50%, try 75%

at 75% too big ? try 62%, too small at 75%, try 87% and so on,
standard binary search, takes a few minutes to write.

Tidy up the temp files you create along the way. No need to know anything about how to predict JPEG compression ratios, just save them and look at the results.

It is somewhat annoying that you have to write your own binary search, as photoshop already has this built in to find the correct compression ratio for a given file size in the save for web dialog, but it isn't difficult to put it together. You could just lift the algorithm from wikipedia and modify it if you aren't comfortable writing your own search algorithm, modifying the A[mid] array lookup to be a ftn call returning the file size when saved at 'mid' quality.

BinarySearch(A[0..N-1], value, low, high) {
if (high < low)
return -1 // not found
mid = (low + high) / 2
if (A[mid] > value)
return BinarySearch(A, value, low, mid-1)
else if (A[mid] < value)
return BinarySearch(A, value, mid+1, high)
else
return mid // found
}

SizeAtQual(val) {
saveForWeb.quality=val;
saveForWeb.filename = 'tempdel.jpg';
save it;

len = filename.length;
delete filename;
return len;
}

At most you'd need to save 6ish files and they'll be small (it's save for web after all) so it should be pretty quick.

Message edited by author 2008-03-07 09:10:12.
Pages:  
Current Server Time: 12/28/2025 05:28:24 PM

Please log in or register to post to the forums.


Home - Challenges - Community - League - Photos - Cameras - Lenses - Learn - Help - Terms of Use - Privacy - Top ^
DPChallenge, and website content and design, Copyright © 2001-2025 Challenging Technologies, LLC.
All digital photo copyrights belong to the photographers and may not be used without permission.
Current Server Time: 12/28/2025 05:28:24 PM EST.