Noob Needs Help With Resizing Script

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

zenpowered

Noob Needs Help With Resizing Script

Post by zenpowered »

Greetings, everyone! I used to be a member of this forum and got some awesome help from someone over a year ago concerning a script to resize images. Unfortunately I can't remember who it was and my account looks to have been purged for inactivity. Oh well, no worries. I would thank him again though if I could.

Moving on..
I still work at the same job just trying to put food on the table. This job requires me to process hundreds or thousands of images at once for customer websites and catalogs. That said, all images that leave my workstation have to measure no less than 1500px (squared) at 300dpi, and no more than 2100px (squared) at 300dpi. I've been trying to accomplish this using the script the guy helped me with last year. The script currently makes sure all images are squared and at a minimum of 1500px@300dpi, however I can't figure out how to set the maximum size to 2100px (squared at 300dpi). Please help me with this. Thanks in advance!

Examples of desired script functionality:
1100x1300@XXXdpi image -> 1500x1500px@300dpi image
1750x1400@XXXdpi image -> 1750x1750px@300dpi image
3200x1800@XXXdpi image -> 2100x2100px@300dpi image

The script:
_____
#target photoshop

app.bringToFront();

// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line

doc = activeDocument;

var black = new SolidColor();
black.rgb.red = 0;
black.rgb.green = 0;
black.rgb.blue = 0;
var white = new SolidColor();
white.rgb.red = 255;
white.rgb.green = 255;
white.rgb.blue = 255;
app.foregroundColor = black;
app.backgroundColor = white;

if (doc.height > doc.width) {
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
activeDocument.resizeCanvas(doc.height,doc.height);


}

}
else {
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
activeDocument.resizeCanvas(doc.width,doc.width);
}

}
if (doc.height > 1500) {


doc.resizeImage(doc.height,null,300,ResampleMethod.BICUBIC);


}
else {
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
doc.resizeImage(1500,null,300,ResampleMethod.BICUBIC);
}

}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

david

Noob Needs Help With Resizing Script

Post by david »

between these two lines:
Code: Select all}
if (doc.height > 1500) {

you can paste this:
Code: Select allif (doc.height > 2100) {
    doc.resizeImage(2100,null,300,ResampleMethod.BICUBIC);
}
else
zenpowered

Noob Needs Help With Resizing Script

Post by zenpowered »

Perfect!
Thanks you so much!