Home > Design - Imagery, Banners & Landers >

[SCRIPT] Photoshop Script to save different sizes of same banner (12)


09-19-2011 11:45 AM #1 tijn (Moderator)
[SCRIPT] Photoshop Script to save different sizes of same banner

Heres another present.

Ive started doing some mobile marketing and got fed up of manually saving each banner in the different ad sizes.

Luckily Photoshop comes with handy automation tools.

Create a file with the extension .jsx

Save the file in your Photoshop Presents/Scripts folder.

Windows: C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts
OsX: Applications\Adobe Photoshop CS5\Presets\Scripts

Then just add the following code to that file:

Code:
preferences.rulerUnits = Units.PIXELS; 
displayDialogs = DialogModes.NO;

// reference the current document open
var doc = app.activeDocument;

//get the filename
var x = separateFileName(doc.name);
var filename = doc.path + "/" + x['filename'];

// set the options you want to use on export
var options = new ExportOptionsSaveForWeb();
options.format = SaveDocumentType.COMPUSERVEGIF;
//options.dither = 0;

// resize
resizeSave(300,50);

// resize
resizeSave(216,36);

// resize
resizeSave(168,28);

// resize
resizeSave(120,20);

function resizeSave(width, height) {
doc.resizeImage(width,height,72,ResampleMethod.BICUBICSHARPER);

doc.exportDocument(new File( filename + "-"+width+"x"+height+".gif" ), ExportType.SAVEFORWEB, options);
}

function separateFileName(theFileName){ 
    if (/\.\w+$/.test(theFileName)) { 
        var m = theFileName.match(/([^\/\\]+)\.(\w+)$/); 
        if (m) 
            return {filename: m[1], ext: m[2]}; 
        else 
            return {filename: 'no file name', ext:null}; 
    } else { 
        var m = theFileName.match(/([^\/\\]+)$/); 
        if (m) 
            return {filename: m[1], ext: null}; 
        else 
            return {filename: 'no file name', ext:null}; 
    } 
}
You can customize or add different export sizes. Just change or add the following lines:

Code:
// resize
resizeSave(300,50);
Just make sure the ratio's of your original image and the resizing dimensions are all the same.

Rather then creating the largest image, and scale down, i would create your banner in medium size and scale both ways.

To "execute" the script you just go to File > Scripts > [Name of Your Script File]

If you cant see the name then you need to restart Photoshop.

If you have done that and you still can not see it then you probably have saved the file in the wrong place.



Hope this helps you save some time!!


09-19-2011 11:46 AM #2 tijn (Moderator)

Oh - almost forgot

The files will be saved wherever your main PSD is saved. If the resized filenames already exist, then the script will exit with an error.


09-19-2011 03:58 PM #3 shanktank (Member)

I'm getting this error.


09-14-2013 06:42 AM #4 2 Live (Senior Member)

this looks like an awesome tool but i keep getting the following error: http://cl.ly/image/0j421h0e2K00

any clue how to fix?


09-14-2013 12:13 PM #5 caurmen (Administrator)

Are you running Photoshop CS5, or a later version?


12-21-2013 12:26 AM #6 bravenewworld (Member)

Does this automatically save the banner as PSD or JPG? Because if its PSD, then I would have to save it as a JPG because most traffic sources that I work with only accept JPEG/GIF.


12-21-2013 09:10 AM #7 caurmen (Administrator)

It saves as a gif.


12-21-2013 01:33 PM #8 bravenewworld (Member)

So when you use this script, then photoshop automatically saves the banner is each size that you request (315x300 300x250 etc.)?

And can it save automatically as a JPG?


12-22-2013 01:09 AM #9 Mr Green (Administrator)

^^ yep correct. You can also make it save in any file format you wish by tweaking the script.


12-22-2013 02:05 AM #10 Rosebudd (Member)

You sir are my hero!! Thank you so much!


12-22-2013 10:48 AM #11 infiniti108 (Member)

Do you have any idea if it is possible to integrate it with Adobe Fireworks?


12-23-2013 11:16 AM #12 caurmen (Administrator)

I don't think so, I'm afraid. I believe Photoshop and Fireworks have different scripting languages.


Home > Design - Imagery, Banners & Landers >