Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

photoshop Change image size JavaScript

// get a reference to the current (active) document and store it in a variable named "doc"
doc = app.activeDocument;  

// change the color mode to RGB.  Important for resizing GIFs with indexed colors, to get better results
doc.changeMode(ChangeMode.RGB);  

// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 320;
var fHeight = 350;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

// Makes the default background white
var white = new SolidColor(); 
white.rgb.hexValue = "FFFFFF";
app.backgroundColor = white;

// Convert the canvas size as informed above for the END RESULT
app.activeDocument.resizeCanvas(UnitValue(fWidth,"px"),UnitValue(fHeight,"px"));

// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'web-'+doc.name+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);
Comment

PREVIOUS NEXT
Code Example
Javascript :: map sord elo 
Javascript :: palindrome short way 
Javascript :: js a || b 
Javascript :: cannot setState in event handler 
Javascript :: css to jss 
Javascript :: array operations = map, filter, find, reduce, some, every, indexOf 
Javascript :: lowercase vs lower locale 
Javascript :: success res node.js 
Javascript :: prisma multiple relation counts 
Javascript :: Toggle image onclicking parent 
Javascript :: How to Solve the Parking Lot Challenge in JavaScript 
Javascript :: send a message in the first channel discord.js 
Javascript :: how to check bot channel permissions 
Javascript :: Backbone View Template 
Javascript :: var sumArray = function(arr) {}; 
Javascript :: javascript variable scope in if statement 
Javascript :: slicer 
Javascript :: file path to blob javascript 
Javascript :: Backbone View In Another View 
Javascript :: get user badge discordjs 
Javascript :: redirect router v6 
Javascript :: javascript invert number 
Javascript :: moment max 
Javascript :: multiple path names for a same component in react router v6 
Javascript :: javascript buffer to file 
Javascript :: adonisjs char 
Javascript :: check for null 
Javascript :: array of numbers to array of objects 
Javascript :: sign changely api 
Javascript :: JavaScript Code Blocks 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =