'Imagemagick Keep File Names & Add Prefixes
I have a script that resizes all images from a source directory into a destination directory, but I need to keep the original filenames and add "100-", "200-" and "400-" to the beginning of the file names.
Here is what I have currently:
magick C:\Users\joe\Desktop\Source*.jpg ^ ( -clone 0--1 -resize 400x400 +write C:/Users/joe/Desktop/Destination/400.jpg ) ^ ( -clone 0--1 -resize 200x200 +write C:/Users/joe/Desktop/Destination/200.jpg ) ^ ( -clone 0--1 -resize 100x100 +write C:/Users/joe/Desktop/Destination/100.jpg ) ^ null:
This works, but it doesn't keep the original file names it just does "400-1.jpg", "400-2.jpg", "400-3.jpg" and so on.
How would I get it to maintain the file names and add these on to the start of the name?
Thanks.
Solution 1:[1]
Something like this (I'll let you figure out how to replace things in your own incantation:
convert -verbose /tmp/*.png -set filename:out "%[directory]/400-%[basename]" "%[filename:out].jpg"
You can do several variations around this depending on the output directory (explicit, from the input image, or the working directory). The final output substitution can only have a single escape, which is why the name is constructed when setting filename:out.
See this for the gory details.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | xenoid |
