-set filename doesn't work

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
schel4ok
Posts: 18
Joined: 2015-08-31T10:38:58-07:00
Authentication code: 1151

-set filename doesn't work

Post by schel4ok »

I try to do file rename just like described here http://www.imagemagick.org/Usage/files/#save_escapes
But I get error

Code: Select all

for f in *.*
do convert -verbose $f  -set filename:mysize"%wx%h";
done

Code: Select all

$ sh test.sh
dush-22.jpg JPEG 640x480 640x480+0+0 8-bit sRGB 61.6KB 0.016u 0:00.010
convert.exe: option requires an argument `-set' @ error/convert.c/ConvertImageCommand/2684.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -set filename doesn't work

Post by snibgo »

Your convert command is not complete. After the "-set filename=...", you need to put an output filename, as shown on the link.
snibgo's IM pages: im.snibgo.com
schel4ok
Posts: 18
Joined: 2015-08-31T10:38:58-07:00
Authentication code: 1151

Re: -set filename doesn't work

Post by schel4ok »

you are right. I didn't notice that.
But what I'm looking for is how to rename files according to this pattern
foldername-001.jpg
foldername-002.jpg
foldername-003.jpg

I still can't understand how to do this.
When I execute this code

Code: Select all

for f in *.*
do convert -verbose $f  -set filename:mysize '%d-%t-%w.%e' '%[filename:mysize]';
done
I get error and output image name is -akva-535.gif

Code: Select all

$ sh test.sh
akva.gif GIF 535x99 535x99+0+0 8-bit sRGB 32c 15KB 0.000u 0:00.002
akva.gif=>-akva-535.gif GIF 535x99 535x99+0+0 8-bit sRGB 32c 15KB 0.016u 0:00.027
convert.exe: unknown image property "%d" @ warning/property.c/InterpretImageProperties/3375.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -set filename doesn't work

Post by snibgo »

Some experimentation shows that %d is taken from the filename as given to IM, not from the file's actual location. As $f doesn't include a directory, that's the problem.
snibgo's IM pages: im.snibgo.com
schel4ok
Posts: 18
Joined: 2015-08-31T10:38:58-07:00
Authentication code: 1151

Re: -set filename doesn't work

Post by schel4ok »

And why %f might not include directory?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -set filename doesn't work

Post by snibgo »

Sorry, I meant $f.
snibgo's IM pages: im.snibgo.com
schel4ok
Posts: 18
Joined: 2015-08-31T10:38:58-07:00
Authentication code: 1151

Re: -set filename doesn't work

Post by schel4ok »

I checked that this works well with convert, but with mogrify I have errors

Code: Select all

mogrify.exe: unable to open image `%[filename:mysize]': No such file or directory @ error/blob.c/OpenBlob/2709.
mogrify.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -set filename doesn't work

Post by fmw42 »

mogrify will not accept such set computations. It is much less functional than convert. You probably will need to write a script loop over each of your images and use convert. What was your exact mogrify command, so we can check your syntax.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -set filename doesn't work

Post by snibgo »

I don't see how it could work in mogrify. Mogrify reads files, and writes files with the same name. The %[filename...] syntax builds an output filename from some data. How can mogrify read a file before it knows what the name is?
snibgo's IM pages: im.snibgo.com
schel4ok
Posts: 18
Joined: 2015-08-31T10:38:58-07:00
Authentication code: 1151

Re: -set filename doesn't work

Post by schel4ok »

my mogrify is like this

Code: Select all

smartresize() {
   mogrify -verbose -path $1 -filter Triangle -define filter:support=2 -thumbnail $2 \
   -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 \
   -define jpeg:fancy-upsampling=off -define png:compression-filter=5 \
   -define png:compression-level=9 -define png:compression-strategy=1 \
   -strip -define png:exclude-chunk=all -interlace none -colorspace sRGB $3
}

smartresize    public/img/foto/        234x180^   'resources/img/foto/*.jpg'
Post Reply