Pardon me if this is a duplicated question even though I could not find a solution yet. I have about 1000s images. I need to resize them, each to a specific size. There are no patterns to those sizes. They are different. I have the file names and the sizes in an excel file. Manually it will take a lot of time. I was wondering if this can be done in a batch process. Maybe Photoshop Scripting or something else.

I do not know how to script but have the general idea of how it works.

What I want to do is indicate the folder and the excel/csv/text file and the batch will run and resize each file to the given height keeping the proportion.


1000s of Image files.

Named: file1, file2, file3, file4. etc...

file1 will have 975 px height

file2 will have 486 px height

file3 will have 846 px height

All keeping the proportions.

Hope that clarifies what I'm trying to achieve.

  • Leave this one open, it is not a duplicate, the data is on a csv file, which makes the question interesting.
    – Rafael
    Mar 22 '19 at 18:09
  • @Danielillo : No, it is not. My problem is say I have file 1, file 2, file 3. file 1 will have 905 px height, file 2 will have 826 px height, and so on. Mar 22 '19 at 18:09
  • 1
    Scripting time. Or you can just learn to use imagemagic as its easier to find how to do this in imagemagick forums ;)
    – joojaa
    Mar 22 '19 at 18:45
  • 2
    @joojaa: Thanks for your reply. Can you kindly be more elaborate. I would like to avoid scripting as I am not used to it. Will Imagemagick allow me to accomplish what I am looking for? Mar 22 '19 at 18:50
  • 1
    @CrimsonCape well its not really possible to avoid it.
    – joojaa
    Mar 22 '19 at 19:08

That's going to be quite a simple script actually. You need only to know the basics of JavaScript (if you don't know those, taking a free CodeAcademy or similar web course on basics will only take you several hours)

Then Google will be your best friend. You need to read your file and get all the lines (first link from google on "photoshop script how to read file"), to get an array of lines (in the example above it's not an array, but we already learned the basics of JS and can easily modify it, right?).

You'll loop through this array and for every element (aka line from .csv file) you'll want to split it by , or ; or whatever you use in your csv — this way you'll get another array that will contain file name and sizes — let's call it myCSVData.

Next you'll be just opening your files and resizing them. To get Photoshop specific JavaScript functions and methods you'll use this document — for example from it we can learn that to open a file we'll need app.open(File) function. And to resize we'll use Document.resizeImage().

Here's an algorithm how I'd do that (I'm not a real coder so it might be not the most efficient one):

// I also first save current ruler units
// and next make sure they're in pixels or we'll have a disaster 
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

// I presume csv file consists of lines similar to this (second number is height):
var b = new File("/c/test.csv");

// open file for reading
var lines = [];
while (!b.eof)
    lines.push(b.readln()); // got an array of lines

// looping through lines array
for (var i = 0; i < lines.length; i++)
    // creating an array from the line: [filename,height]
    var myCSVData = lines[i].split(',');

    // opening a file
    var docToResize = app.open(new File('/c/imagesFolder/' + myCSVData[0]));

    // resizeImage accept several different arguments but first two are width and height. 
    // if width is undefined and only height is there, width will be proportional to new height.
    // also currently myCSVData[1] is a string, not number, so I convert it to number first
    docToResize.resizeImage(undefined, parseInt(myCSVData[1]));

    docToResize.save(); // saving to the same file
    docToResize.close(); // closing it      

// restoring original ruler units
app.preferences.rulerUnits = originalUnits;
  • Thanks for the script. I copied it into a text file, renamed the extension to .jsx and trying now. So far it is not doing anything. I am tweaking the script to make it work for me. As I am not a programmer it is of course taking quite some trial and error however thanks a lot for giving me this boost up. I will post update once I can make it work. Mar 24 '19 at 2:35
  • By not doing anything, do you mean it doesn't even show any errors? Maybe you're not running it? It's supposed to work or show an error if something isn't right Mar 24 '19 at 9:25
  • It does not show me any error, which is good but I am not being able to make it work yet. I am tweaking and trying some trial and error. Will post back when I have something. Thanks for the Script of course. Mar 24 '19 at 17:31
  • Hi, I have tried myriad ways. I changed the folder paths in different ways, tried the way you have arranged it, everything I could think of. From Photoshop I run the script from File > Script > Browse and show where the script is, and that's it. It does not do anything at all. When I tried to modify it, it showed some errors which probably was my fault but other than that nothing. Mar 24 '19 at 18:37
  • I have been able to open the file and resize it now however, the resizing is not working properly. It is now shrinking the image to 1 x 1. In the code, how am I storing the Height data to the array? Also, I am getting another error of 1233 saying "Expected a reference to an existing File/Folder". It is due to the app.open command. I put together some codes from here and there. Not sure how to post it though. Just copy pasting. Mar 24 '19 at 19:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.