Photoshop Script for Resizing All Photos for Instagram

I like to post my park photography on my Instagram, and Instagram only allows certain crop ratios. As of right now (March 2020) the ratios and their optimal sizes are:

  • Portrait: 1080 x 1350 (4:5)
  • Landscape: 1080 x 566 (1.91:1)
  • Square: 1080 x 1080 (1:1)

I mostly use the 4:5 (I like the landscape in principle, but on a phone app it’s easily overlooked.) But sometimes a photo looks bad cropped at 4:5, in which case I might crop it however I like, then add a little “padding” to each side to make it 4:5. I usually do this with 4:6 photos, but any portrait size could use this trick.

Example of a 1.91:1 landscape photo on an Instagram screen
Landscape (1.91:1) – Easily overlooked on Instagram!
Example of a 4:5 portrait photo on an Instagram screen
Portrait (4:5)
Example of a photo on Instagram padded to fit the 4:5 ratio
Padded portrait (4:5) – Notice the white strips on both sides

But what if you have several photos in multiple ratios (say, a bunch of images you just exported from Lightroom) and want all of them to be optimized from Instagram at once? A Photoshop script can do the trick!

Read below if you don’t know how to install a Photoshop script (it’s very easy!) Otherwise you can download the .jsx file, or copy the code from here:

while (documents.length > 0) {

	var docRef = activeDocument;
	var docName = activeDocument.name;
	var layerRef = docRef.activeLayer;
	var currentWidth = docRef.width;
	var currentHeight = docRef.height;
	var imgRatio = currentWidth / currentHeight;

	
	if (imgRatio < 1.92 && imgRatio > 1.9) { //1.91:1 ratio
		docRef.resizeImage ("1080 pixels", "566 pixels", 72);
	} else if (imgRatio == 0.8) { //4:5 ratio
		docRef.resizeImage ("1080 pixels", "1350 pixels", 72);
	} else if (imgRatio == 1.0) {
		docRef.resizeImage ("1080 pixels", "1080 pixels", 72);
	} else {
		if (currentHeight > currentWidth) {
			var paddedWidth = currentHeight * 0.8 ;
			docRef.resizeCanvas (paddedWidth, currentHeight, AnchorPosition.MIDDLECENTER);
			docRef.resizeImage ("1080 pixels", "1350 pixels", 72);
		} else {
			docRef.resizeImage ("1080 pixels", undefined, 72);
			alert ("The image " + docName + " is too tall for the 1.91:1 ratio. It was resized to 1080 pixels wide, but will need to be cropped when uploaded to Instagram.");
		}
	}

	function saveJPEG( docRef, saveFile, qty ) {
		var saveOptions = new JPEGSaveOptions( );
		saveOptions.embedColorProfile = true;
		saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
		saveOptions.matte = MatteType.NONE;
		saveOptions.quality = qty; 
		docRef.saveAs( saveFile, saveOptions, true );
	}
	
	docName =  docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];
	var suffix = '-insta';
	var saveName = new File(decodeURI(docRef.path)+'/'+docName[1]+suffix+'.jpg');

	saveJPEG( app.activeDocument, saveName, 12 );	
	docRef.close(SaveOptions.DONOTSAVECHANGES);
}

Photoshop Scripts for Beginners

If you ever need to do something repetitive in Photoshop, a script can likely do it for you. It’s similar to the basic automation under Windows > Actions, but it can make more complex decisions based on input (such as the current ratio of your image).

To use my script (or any script, Google “free Photoshop scripts” and go nuts), first download it, then put it in your Scripts directory (mine is at C:\Program Files\Adobe\Adobe Photoshop CC 2019\Presets\Scripts). Restart Photoshop.

My script requires all the photos you want to run it on to already be open in Photoshop. After you’ve done that look for “Instagram Sizing” under File > Scripts and select it.

Screenshot of Photoshop showing a script selected under File > Scripts

Boom, it’s done! The photos will be saved in their original folder with the “-insta” suffix on their filenames.

What the “Instagram Sizing” Script Does

The script I wrote looks at each open document in Photoshop and resizes it to the optimal Instagram size. If it’s already 4:5 or 1.91:1 ratio it only changes the pixel size to 1080 pixels wide; if it’s 4:6 or some other portrait size it first adds padding to make it 4:5. All images are then saved at 72 dpi with the suffix “-insta” added to the filename, and closed.

If it’s a weird landscape size it resizes it to 1080 pixels wide, and an alert pops up to remind me that I’m going to have to crop it again in Instagram (I didn’t want it to crop automatically since the script would have no idea what would look the most visually pleasing.) This case rarely comes up, but I may eventually change it to instead add padding to the top/bottom to make it 4:5 as well.

Please note that this script was written to work on jpgs that I’d just exported out of Lightroom. I’m not a programmer, I just know a little bit of Javascript and wanted to see if I could make something for my particular needs. I did, and it was fun, but I’ve no doubt someone out there could write a broader and more efficient version of this script.

Uploading to Instagram from Your Computer

You may have noticed that, when you go to your Instagram page on your desktop computer, there doesn’t seem to be any way to upload photos (without third-party software, anyway). But there is a way!

Using the Chrome browser, go to your Instagram page and right-click on the background and select Inspect. A frame full of code should show up on the right side of the window; ignore this and look for the little screen resize button near the top.

Screenshot showing the "toggle device" button in Chrome's inspect mode

Toggle this button to switch between desktop Instagram and mobile screen Instagram–the mobile version will have the little upload photo button you’re used to seeing on your phone. You may have to refresh the page first to make the upload button show up.

It’s not perfect–your filters are available, but edit doesn’t seem to do anything. And once you’ve uploaded a photo you can’t go back and change it (you still can on your phone). Still, I’ve found it a lot more convenient than transferring my photos to my phone and then trying to write captions and hashtags without a real keyboard.

Happy Instagramming!