PDA

View Full Version : My "Prepare for Web" script for Photoshop CS


Jesper
3rd of July 2004 (Sat), 13:16
Recently (http://photography-on-the.net/forum/showthread.php?t=36230) someone asked for a way to resize lots of images to a certain fixed size on the long end. I posted my "Prepare for Web" script, which I use to prepare my photos for publishing on the web.

My script had one flaw: it always resized photos to 720 x 480 (or 480 x 720), stretching the width / height ratio if it wasn't 3 : 2.

Here's a new version of my script which keeps the width / height ratio intact. This is what the script does:

1. Flattens the currently active document (i.e. combines all layers).
2. Converts the image to the sRGB colour space if necessary.
3. Converts the image to 8 bits per channel if necessary.
4. Resizes the image so that the longest side will be 720 pixels wide or high.

How to use it: The script is written in JavaScript. With a text editor (Notepad, for example) save it somewhere on your hard drive with the extension ".js". In Photoshop, choose File / Scripts / Browse and navigate to the file. You can also put the script in the folder C:\Program Files\Adobe\Photoshop CS\Presets\Scripts. If you do that, the script will appear in the File / Scripts menu the next time you start Photoshop.

Have fun...

// Prepare for Web script for Photoshop CS
// Copyright (C) 2004, Jesper de Jong (jespdj@hotmail.com)

var targetSize = 720

doc = app.activeDocument

doc.flatten()

if (doc.colorProfileName.substring(0,4) != "sRGB")
doc.convertProfile("sRGB IEC61966-2.1", Intent.PERCEPTUAL, true, false)

if (doc.bitsPerChannel != BitsPerChannelType.EIGHT)
doc.bitsPerChannel = BitsPerChannelType.EIGHT

var startRulerUnits = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS

if (doc.width > doc.height) {
doc.resizeImage(targetSize, doc.height * targetSize / doc.width, doc.resolution, ResampleMethod.BICUBIC)
}
else {
doc.resizeImage(doc.width * targetSize / doc.height, targetSize, doc.resolution, ResampleMethod.BICUBIC)
}

app.preferences.rulerUnits = startRulerUnits

neil_r
3rd of July 2004 (Sat), 13:27
jesper,

This is excellent, many thanks, you are a star.

N

scottbergerphoto
3rd of July 2004 (Sat), 16:41
You can also:
File>Save for Web
Set the Quality to 80/ JPEG / Optimized
Set the longest side to 800 pixels
I leave the ICC profile checked ( I believe it is ignored by web applications).

That's how I post all my pictures. If I'm losing something by doing this, let me know.

Regards,
Scott

Jesper
3rd of July 2004 (Sat), 17:33
You can also:
File>Save for Web
Set the Quality to 80/ JPEG / Optimized
Set the longest side to 800 pixels
I leave the ICC profile checked ( I believe it is ignored by web applications).

That's how I post all my pictures. If I'm losing something by doing this, let me know.

Regards,
Scott

Ofcourse there are multiple ways of preparing your images for the web... On most of my photos I'm doing some post processing (sharpening) after I resize them - with your method, you're resizing and saving in one step, so you can't do sharpening in between. I also use Save for Web and I uncheck the ICC profile (that's probably what you meant but you typed the opposite?) - an embedded ICC profile only makes the file larger and 99.9% of the Internet browsers that people use ignore it.

scottbergerphoto
3rd of July 2004 (Sat), 18:56
Good point. I have to sharpen after resizing.
Scott

Aylwin
3rd of July 2004 (Sat), 19:38
Dang! I didn't realise the ICC profile is useless on the web. Thanks for the info! :)

Aylwin

Scottes
5th of July 2004 (Mon), 10:42
Jesper, this is great.

I would, however, recommend the order resize, sRGB, then 8-bit. The interpolation process for resizing will beneft from 16-bit space - slightly, but it will.

Another thing you could do is over-sharpen as the last step, thus allowing you to use Edit... Fade Unsharp Mask to bring the sharpening down to an acceptable level for each image. This isn't perfect though - just an idea.


I must say that you are convincing me to get a book on scripting PS.

PacAce
5th of July 2004 (Mon), 11:48
...I must say that you are convincing me to get a book on scripting PS.

Scott, you should find all the info you need on PS scripting here (assuming you're already versed in VB or JavaScript).

http://partners.adobe.com/asn/photoshop/scripting.jsp

Scottes
5th of July 2004 (Mon), 14:44
Yes, I have those, but I don't think they're too great as a learning tool. It might be just me, but I don't like learning a new language using a reference manual, and their examples aren't too extensive.

PacAce
5th of July 2004 (Mon), 16:37
Yes, I have those, but I don't think they're too great as a learning tool. It might be just me, but I don't like learning a new language using a reference manual, and their examples aren't too extensive.

Yes, you're right. And it'd not just you. If one doesn't have any real experience with VB or Java Script, trying to learn it from an API reference doc could really be tough (and hence the reason I qualified my previous post with "assuming you're already versed in VB or JavaScript").

arumdevil
5th of July 2004 (Mon), 19:03
Dang! I didn't realise the ICC profile is useless on the web. Thanks for the info! :)

Aylwin

not totally useless - anyone using safari on a mac will get the benefit of the profile be it sRGB or Adobe RGB or whatever (as long as the profile is on the user's machine).

someone correct me if this is wrong

Scottes
5th of July 2004 (Mon), 20:38
I like to leave it in for anything except thumbnails. The 1/2 KB doesn't make much difference, and I think browsers will soon start supporting it. OK, eventually they'll support it. But I know that Mozilla is working on it. Safari seems to support it already - I've seens several sites that say it does. IE since 4.0 apparently supports it, too.

Some interesting, though short, reading here (http://www.ekdahl.org/kurs/colormanage.htm)

So I think it's well worth the extra 1/2 KB to include it.

Jesper
6th of July 2004 (Tue), 01:11
Jesper, this is great.

I would, however, recommend the order resize, sRGB, then 8-bit. The interpolation process for resizing will beneft from 16-bit space - slightly, but it will.

Another thing you could do is over-sharpen as the last step, thus allowing you to use Edit... Fade Unsharp Mask to bring the sharpening down to an acceptable level for each image. This isn't perfect though - just an idea.


I must say that you are convincing me to get a book on scripting PS.

Thanks for the tips! I already knew JavaScript and I used the PDF reference manuals to find out how it works in Photoshop CS. There are ofcourse lots of tutorials etc. about JavaScript on the web. Here's a nice one:

http://www.w3schools.com/js/default.asp - it's geared toward use on the web and HTML, but shows the basics of the language.