Page 1 of 1
-set filename doesn't work
Posted: 2015-09-12T05:07:01-07:00
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.
Re: -set filename doesn't work
Posted: 2015-09-12T05:15:11-07:00
by snibgo
Your convert command is not complete. After the "-set filename=...", you need to put an output filename, as shown on the link.
Re: -set filename doesn't work
Posted: 2015-09-12T06:18:18-07:00
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.
Re: -set filename doesn't work
Posted: 2015-09-12T07:00:52-07:00
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.
Re: -set filename doesn't work
Posted: 2015-09-12T07:04:29-07:00
by schel4ok
And why %f might not include directory?
Re: -set filename doesn't work
Posted: 2015-09-12T07:06:31-07:00
by snibgo
Sorry, I meant $f.
Re: -set filename doesn't work
Posted: 2015-09-12T11:53:22-07:00
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.
Re: -set filename doesn't work
Posted: 2015-09-12T12:49:44-07:00
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.
Re: -set filename doesn't work
Posted: 2015-09-12T13:04:05-07:00
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?
Re: -set filename doesn't work
Posted: 2015-09-14T06:47:17-07:00
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'