Monday, April 29, 2024
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 9811  / 2 Years ago, mon, september 5, 2022, 12:56:28

I have 3 files in a directory:


aaa.jpg    
bbb.jpg
ccc.jpg

I can scale down an image using ImagkMagick convert:


convert aaa.jpg -resize 1200x900 aaa-small.jpg  

I want to do all the images in the directory, something like:


convert *.jpg -resize 1200x900 *-small.jpg  

but this results in files named like so:


*-small-0.jpg  
*-small-1.jpg
*-small-2.jpg

What I want is:


aaa-small.jpg  
bbb-small.jpg
ccc-small.jpg

How do I do this?


More From » command-line

 Answers
6

It's frustratingly opaque in the documentation, but you can pass a quoted shell glob to convert (quoted to prevent the shell from expanding it prematurely), and use Filename Percent Escapes to construct output filenames in the form %[filename:label] (where label is an arbitrary user-specified label), using the input basename escape %[basename] or its legacy equivalent %t:


$ ls ???.jpg
aaa.jpg bbb.jpg ccc.jpg

then


$ convert '*.jpg' -set filename:fn '%[basename]-small' -resize 1200x900 '%[filename:fn].jpg'

resulting in


$ ls ???-small.jpg
aaa-small.jpg bbb-small.jpg ccc-small.jpg

[#1309] Monday, September 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oreera

Total Points: 472
Total Questions: 121
Total Answers: 116

Location: Mayotte
Member since Thu, Dec 17, 2020
3 Years ago
;