Skip to content

Instantly share code, notes, and snippets.

@iotashan
Created August 23, 2021 23:00
Show Gist options
  • Save iotashan/2e9deae8be8bef7c12e383ffc6298026 to your computer and use it in GitHub Desktop.
Save iotashan/2e9deae8be8bef7c12e383ffc6298026 to your computer and use it in GitHub Desktop.
script to change the canvas size to square, making the extra space black
doc = app.activeDocument;
// change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results
doc.changeMode(ChangeMode.RGB);
// Makes the default background white
var black = new SolidColor();
white.rgb.hexValue = "000000";
app.backgroundColor = black;
// new size
var newHeightWidth = Math.max(doc.height,doc.width)
// Convert the canvas size as informed above for the END RESULT
app.activeDocument.resizeCanvas(UnitValue(newHeightWidth,"px"),UnitValue(newHeightWidth,"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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment