0

I have a bit of a difficult problem to solve.

I have a folder that contains a large amount of image files, and new image files are added daily (all JPG) that are named in a way that ensures there are no duplicates. The file names never change.

I need a way to have three separate copies of each image placed into a new folder, whereby the first copy is 100x100px, the second 200x200px and the third 400x400px, and lastly I need each image of a different size to be named 100-filename.jpg, 200-filename.jpg and 400-filename.jpg respectively.

I'm using Windows 11, and also aspect ratio isn't a problem as they are all square images and cropped correctly.

I know this could be done using a script and possibly Imagemagick/Irfanview, but I am unsure how I would set it up so that it is fully automated, and exactly how I'd do such a thing, being new to scripting.

The only things I could find were how to do it for one image rather than all images in a folder, and the other didn't suggest how I could also rename the files respectively.

Any help would be greatly appreciated.

Thanks!

  • Please clarify the missing details. Your images are named in a specific way... what specific way? Where's the new folder? Does its name change daily? What happens to the input images after the resized copies are created... otherwise you will just get more and more input images forever? – Mark Setchell May 10 '22 at 12:02
  • The format for naming the image is "CHARACTERNAME_SUPPLIER_DESIGNERINITIALS_DESIGNNUMBER.jpg" Works out something like "BATMAN_TU_JO_00005A.jpg" The new folder is just a location we specify (Images folder on one of our Windows servers) The names never change, any new images are given unique values so there are never duplicates. The input images are not needed once they have been made into copies - the originals are saved in our bespoke system. – Spicy Joseph May 10 '22 at 12:26

1 Answers1

0

In Imagemagick 6 on Windows, you can do a FOR loop over each file in your folder and do:

convert image.suffix ^
( +clone -resize 400x400 +write path_to_folder1/image.suffix ) ^
( +clone -resize 200x200 +write path_to_folder2/image.suffix ) ^
( +clone -resize 100x100 +write path_to_folder3/image.suffix ) ^
null:

Which will resize successively from the previously resize version

Or

convert image.suffix ^
( -clone 0 -resize 400x400 +write path_to_folder1/image.suffix ) ^
( -clone 0 -resize 200x200 +write path_to_folder2/image.suffix ) ^
( -clone 0 -resize 100x100 +write path_to_folder3/image.suffix ) ^
null:

which will resize from the original for each size.

For Imagemagick 7, replace "convert" with "magick" and you can then make the output automatic.

magick path_to_infolder/image.suffix ^
-set filename:name "%t" ^
( -clone 0 -resize 400x400 +write "path_to_outfolder/400-%[filename:name].jpg" ) ^
( -clone 0 -resize 200x200 +write "path_to_outfolder/200-%[filename:name].jpg" ) ^
( -clone 0 -resize 100x100 +write "path_to_outfolder/100-%[filename:name].jpg" ) ^
null:
fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Hi, Thanks for your reply. I'm quite new to this but I have just tried this with the path to the folder placed in the script. Would this not just target the one image, how would I get it to do the entire folder? – Spicy Joseph May 10 '22 at 15:31
  • Where you write "image.suffix" what should be typed here? If it's the file name that won't work, I need this to target hundreds of different images at once. – Spicy Joseph May 10 '22 at 15:54
  • It is the input image from your directory. You have loop over each image in the directory or list of directories. I only provided the code to process any given image in the directory. image.suffix could be replace by path_to_folder/image.suffix, if you need to loop over many directories. – fmw42 May 10 '22 at 16:38
  • I got it to work but it renamed the images "100-1.jpg" "100-2.jpg" How do I make it keep the original file names but append 100-, 200- and 400- to the beginning of each ? – Spicy Joseph May 11 '22 at 09:09
  • See my edits at the bottom of my answer above – fmw42 May 11 '22 at 15:21
  • Thanks, ran that but it didn't keep the original file names, it named them "100-%[name]-79.jpg" – Spicy Joseph May 11 '22 at 15:58
  • Sorry, I made a mistake and forgot to add filename: before the name. See my edits in the answer again. – fmw42 May 11 '22 at 16:31