Hello again, community!
I need help with my script. I use this script to batch process hundreds or thousands of files at once for my job.
WHAT IT CURRENTLY DOES:
It squares every canvas with white space. The DPI is set to 300. The image is resized to 1500x1500 if it is smaller than 1500px. It also resizes each image to 2100x2100 if it is larger than 2100px.
WHAT I WANT IT TO DO:
1. I want it to be set to 400dpi instead of 300dpi.
2. I want the minimum size (to be resized to 1500px) to be 1000px. I want anything below that size to be ignored.
3. Stop pausing to "save as a copy". I think this is due to alpha channels but I'm not sure how to work around it. Every so often I get a few other errors that I can't always get to in a timely fashion. I want the batch to be fully automated with no pauses, etc. I also don't want to change the filename of any files (as saving a copy will do unless I manually delete "copy" from the file name before it's saved.)
Thanks in advance for your help!
Here is the script in its current iteration:
____
#target photoshop
// in case we double clicked the file
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 id3 = charIDToTypeID( "Dlt " );
var desc2 = new ActionDescriptor();
var id4 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id5 = charIDToTypeID( "Gd " );
var id6 = charIDToTypeID( "Ordn" );
var id7 = charIDToTypeID( "Al " );
ref1.putEnumerated( id5, id6, id7 );
desc2.putReference( id4, ref1 );
executeAction( id3, desc2, DialogModes.NO );
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 > 2100) {
doc.resizeImage(2100,null,300,ResampleMethod.BICUBIC);
}
else
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);
}
}
Help With My Resize Script?
-
christopherjohnson
Help With My Resize Script?
change 300 to 400.
modify your if statements to reflect the new sizes. Do you need someone to write the javascript size check and new sizes for you?
I don't see where it saves as copy unless that is in the funny code at the top ( script listener right?)
modify your if statements to reflect the new sizes. Do you need someone to write the javascript size check and new sizes for you?
I don't see where it saves as copy unless that is in the funny code at the top ( script listener right?)
-
zenpowered
Help With My Resize Script?
Yeah I'm not too good at scripting. Every time I tried editing this thing in the past it does weird stuff..
It doesn't save as a copy by default, but it tries to do it every time it processes certain images, all of which have alpha channels).
It doesn't save as a copy by default, but it tries to do it every time it processes certain images, all of which have alpha channels).
-
Mike Hale
Help With My Resize Script?
Both your post and your script are unclear. I am not clear about what sizes you want. Anything less than 1000px does not resize? 1000 to 2100 resize to 1500? Larger than 2101 resize to 2100?
The script doesn't have a save step. It would help if you told us what format you are saving the file. The saveAs copy could be the alpha channels. But it could also be the bit depth or number of layers depending what the format supports. Also it might help to know which version of Photoshop you are using. It also has poorly structured if statements and repeated code that is not necessary. For example you should first check that there is an open document before making a variable reference, deleting the guides, or resizing the canvas.
Is the save being done by an action? With a script you can name the saved file anything you want. It doesn't have to have the word 'copy' in the filename even if the script saveAs a copy.
Code: Select all#target photoshop
// in case we double clicked the file
app.bringToFront();
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
// make sure there is a document open
if (documents.length > 0) {
doc = activeDocument;
// delete all guides
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( charIDToTypeID( "Gd " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al " ) );
desc2.putReference( charIDToTypeID( "null" ), ref1 );
executeAction( charIDToTypeID( "Dlt " ), desc2, DialogModes.NO );
// reset color to default black and white
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(app.charIDToTypeID('Clr '), app.charIDToTypeID('Clrs'));
desc1.putReference(app.charIDToTypeID('null'), ref1);
executeAction(app.charIDToTypeID('Rset'), desc1, DialogModes.NO);
// store user ruler unit to restore later
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
// first square the canvas
if (doc.height > doc.width) {
activeDocument.resizeCanvas(doc.height,doc.height);
}
}else {
activeDocument.resizeCanvas(doc.width,doc.width);
}
// now check to see if document is 400ppi
if(doc.resolution != 400) doc.resizeImage(undefined,undefined,400,ResampleMethod.NONE );
// now check to see if document needs resizing
// I am not clear about how you want the document resized
/*
if (doc.height > 2100) {
doc.resizeImage(2100,null,300,ResampleMethod.BICUBIC);
}else 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);
}
}
*/
// restore the user ruler units
app.preferences.rulerUnits = oldRulerUnits;
}
The script doesn't have a save step. It would help if you told us what format you are saving the file. The saveAs copy could be the alpha channels. But it could also be the bit depth or number of layers depending what the format supports. Also it might help to know which version of Photoshop you are using. It also has poorly structured if statements and repeated code that is not necessary. For example you should first check that there is an open document before making a variable reference, deleting the guides, or resizing the canvas.
Is the save being done by an action? With a script you can name the saved file anything you want. It doesn't have to have the word 'copy' in the filename even if the script saveAs a copy.
Code: Select all#target photoshop
// in case we double clicked the file
app.bringToFront();
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
// make sure there is a document open
if (documents.length > 0) {
doc = activeDocument;
// delete all guides
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( charIDToTypeID( "Gd " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al " ) );
desc2.putReference( charIDToTypeID( "null" ), ref1 );
executeAction( charIDToTypeID( "Dlt " ), desc2, DialogModes.NO );
// reset color to default black and white
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(app.charIDToTypeID('Clr '), app.charIDToTypeID('Clrs'));
desc1.putReference(app.charIDToTypeID('null'), ref1);
executeAction(app.charIDToTypeID('Rset'), desc1, DialogModes.NO);
// store user ruler unit to restore later
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
// first square the canvas
if (doc.height > doc.width) {
activeDocument.resizeCanvas(doc.height,doc.height);
}
}else {
activeDocument.resizeCanvas(doc.width,doc.width);
}
// now check to see if document is 400ppi
if(doc.resolution != 400) doc.resizeImage(undefined,undefined,400,ResampleMethod.NONE );
// now check to see if document needs resizing
// I am not clear about how you want the document resized
/*
if (doc.height > 2100) {
doc.resizeImage(2100,null,300,ResampleMethod.BICUBIC);
}else 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);
}
}
*/
// restore the user ruler units
app.preferences.rulerUnits = oldRulerUnits;
}
-
zenpowered
Help With My Resize Script?
Ok sorry for not being more clear.
Firstly, all canvases are made square with white space.
<1000px images - These images are left alone. (they will have to be fully replaced later).
1000px-1499px - scaled up to 1500px.
1500px-2100px - no action aside from squaring and saving.
>2100px - scaled down to 2100px
At this point my script sets the image to 300dpi, but I want it to make them 400dpi instead.
After all that, i use an action to save the file, but it would be awesome if I could get that put in the script instead. I prefer .jpg format, but not "save as web/72dpi" .jpg.
I'm using Photoshop CS5 v12.1 x32.
Again, I'm completely noobish at scripting so I understand it looks bad. If someone could edit it to make this all work it would be super..
Firstly, all canvases are made square with white space.
<1000px images - These images are left alone. (they will have to be fully replaced later).
1000px-1499px - scaled up to 1500px.
1500px-2100px - no action aside from squaring and saving.
>2100px - scaled down to 2100px
At this point my script sets the image to 300dpi, but I want it to make them 400dpi instead.
After all that, i use an action to save the file, but it would be awesome if I could get that put in the script instead. I prefer .jpg format, but not "save as web/72dpi" .jpg.
I'm using Photoshop CS5 v12.1 x32.
Again, I'm completely noobish at scripting so I understand it looks bad. If someone could edit it to make this all work it would be super..
-
Mike Hale
Help With My Resize Script?
The save step can be added to the script. But I will need to know where you want the jpeg saved. In the same folder as the current document?
-
zenpowered
Help With My Resize Script?
If possible, I'd like them to be saved in a subdirectory called "Processed"
Thanks!
Thanks!
-
zenpowered
Help With My Resize Script?
Also, would it make sense to have the script flatten the image? It's currently in the action I use right before the script runs.
The raw images are generally multi-layered .PSD, .EPS, or .TIF
You guys know better than me so I'll trust your judgment on this. Thanks!
The raw images are generally multi-layered .PSD, .EPS, or .TIF
You guys know better than me so I'll trust your judgment on this. Thanks!
-
Mike Hale
Help With My Resize Script?
Sorry for the delay, I got sidetracked and forgot about your last request.
Code: Select all#target photoshop
// in case we double clicked the file
app.bringToFront();
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
// make sure there is a document open
if (documents.length > 0) {
if (doc.height.value > 1000 || doc.width.value > 1000) {
doc = activeDocument;
// delete all guides
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( charIDToTypeID( "Gd " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al " ) );
desc2.putReference( charIDToTypeID( "null" ), ref1 );
executeAction( charIDToTypeID( "Dlt " ), desc2, DialogModes.NO );
// reset color to default black and white
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(app.charIDToTypeID('Clr '), app.charIDToTypeID('Clrs'));
desc1.putReference(app.charIDToTypeID('null'), ref1);
executeAction(app.charIDToTypeID('Rset'), desc1, DialogModes.NO);
// store user ruler unit to restore later
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
// first square the canvas
if (doc.height > doc.width) {
activeDocument.resizeCanvas(doc.height,doc.height);
}
}else {
activeDocument.resizeCanvas(doc.width,doc.width);
}
// now check to see if document is 400ppi
if(doc.resolution != 400) doc.resizeImage(undefined,undefined,400,ResampleMethod.NONE );
// now check to see if document needs resizing
if (doc.height < 1500) {
doc.resizeImage(1500,undefined,undefined,ResampleMethod.BICUBIC);
}
if (doc.height > 2101) {
doc.resizeImage(2100,undefined,undefined,ResampleMethod.BICUBIC);
}
var saveFolder = new Folder(doc.fullName.parent+'/Processed');
var saveName = doc.name.match(/(.*)(\.[^\.]+)/) == null ? doc.name:doc.name.match(/(.*)(\.[^\.]+)/)[1];
var saveFile = new File(saveFolder+'/'+saveName);
SaveAsJPG( saveFile, 10 );
// restore the user ruler units
app.preferences.rulerUnits = oldRulerUnits;
}
}
function SaveAsJPG( saveFile, jpegQuality ){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; // 0 - 12
activeDocument.saveAs( saveFile, jpgSaveOptions, true,Extension.LOWERCASE );
}
Code: Select all#target photoshop
// in case we double clicked the file
app.bringToFront();
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
// make sure there is a document open
if (documents.length > 0) {
if (doc.height.value > 1000 || doc.width.value > 1000) {
doc = activeDocument;
// delete all guides
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( charIDToTypeID( "Gd " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al " ) );
desc2.putReference( charIDToTypeID( "null" ), ref1 );
executeAction( charIDToTypeID( "Dlt " ), desc2, DialogModes.NO );
// reset color to default black and white
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(app.charIDToTypeID('Clr '), app.charIDToTypeID('Clrs'));
desc1.putReference(app.charIDToTypeID('null'), ref1);
executeAction(app.charIDToTypeID('Rset'), desc1, DialogModes.NO);
// store user ruler unit to restore later
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
// first square the canvas
if (doc.height > doc.width) {
activeDocument.resizeCanvas(doc.height,doc.height);
}
}else {
activeDocument.resizeCanvas(doc.width,doc.width);
}
// now check to see if document is 400ppi
if(doc.resolution != 400) doc.resizeImage(undefined,undefined,400,ResampleMethod.NONE );
// now check to see if document needs resizing
if (doc.height < 1500) {
doc.resizeImage(1500,undefined,undefined,ResampleMethod.BICUBIC);
}
if (doc.height > 2101) {
doc.resizeImage(2100,undefined,undefined,ResampleMethod.BICUBIC);
}
var saveFolder = new Folder(doc.fullName.parent+'/Processed');
var saveName = doc.name.match(/(.*)(\.[^\.]+)/) == null ? doc.name:doc.name.match(/(.*)(\.[^\.]+)/)[1];
var saveFile = new File(saveFolder+'/'+saveName);
SaveAsJPG( saveFile, 10 );
// restore the user ruler units
app.preferences.rulerUnits = oldRulerUnits;
}
}
function SaveAsJPG( saveFile, jpegQuality ){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; // 0 - 12
activeDocument.saveAs( saveFile, jpgSaveOptions, true,Extension.LOWERCASE );
}
-
zenpowered
Help With My Resize Script?
Thanks so much Mike!
I'm getting errors now though. I managed to fix two of them on my own, but I can't figure this one out:
___
Error 1220: Illegal Argument
Line: 20
-> ref1.putEnumerated( charIDToTypeID( "Gd " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al " ) );
----
I'm getting errors now though. I managed to fix two of them on my own, but I can't figure this one out:
___
Error 1220: Illegal Argument
Line: 20
-> ref1.putEnumerated( charIDToTypeID( "Gd " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al " ) );
----