0

I developed this simple bash script:

#!/bin/bash


for img in `find ./to_upload -iname "*.jpg" -type f`
do
    mogrify ‑resize 1024 ‑sample 70 ${img}
done

When I run it, the script return:

...
mogrify: unable to open image `‑resize': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: unable to open image `1024': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: unable to open image `‑sample': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: unable to open image `70': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
...

for each file. What is wrong? I am using debian testing.

It is not the script:

$ mogrify ‑resize 1024 ‑sample 70 image.jpg
mogrify: unable to open image `‑resize': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: unable to open image `1024': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: unable to open image `‑sample': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: unable to open image `70': No such file or directory @ error/blob.c/OpenBlob/2658.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.

I am using gnome terminal. I do not understand maybe is it a debian bug?

mogrify -resize 1024 -sample 70 image.jpg

mogrify ‑resize 1024 ‑sample 70 image.jpg

I solved but I do not understand why, the first line works but the second line does not work. Please can someone try (copy-paste in command line)?

3 Answers 3

1

I suspect that the problem is that you have copied and pasted the command into Microsoft Word (or some similar text processor) and then copied and pasted it back to the terminal.  In your

mogrify ‑resize 1024 …

command, the character before resize is a Unicode U+2011 character, which is a non-breaking hyphen (see the Unicode chart).  Try retyping it as a plain dash (a.k.a. minus sign).

1
  • thank you, I am using geany on Debian as I wrote, maybe I copied the Unicode U+2011 character from imagemagick online docs
    – Appost
    Oct 7, 2014 at 15:14
0

I assume you have filenames with spaces. Use a for loop to iterate over words, and a while read loop to iterate over lines

find ./to_upload -iname "*.jpg" -type f -print0 |
while IFS= read -r -d "" img; do
    mogrify ‑resize 1024 ‑sample 70 "$img"
done

Also, crucial to use double quotes around the variable name.

3
  • thank you but the files are without spaces, only underscore, I tried with the quotes but the result is the same
    – Appost
    Oct 6, 2014 at 16:23
  • Does the command have a -- option that you can use before the file name?
    – slhck
    Oct 6, 2014 at 16:34
  • like git? no, it haven't
    – Appost
    Oct 6, 2014 at 16:38
0
find ./to_upload -iname "*.jpg" -type f -exec mogrify ‑resize 1024 ‑sample 70 {} \;

Note the weird \; at the end - ';' is part of the -exec option syntax of find, so it must be prefixed with a '\' to avoid being interpreted by the shell. It tells find to invoke the subcommand exactly once for each file it finds.

You can also do this, if mogrify accepts multiple files per invocation (find also ensures it doesn't exceed maximum number of arguments allowed by the shell):

find ./to_upload -iname "*.jpg" -type f -exec mogrify ‑resize 1024 ‑sample 70 {} +

P.S. I just noticed your comment "it's not the script" - I have ImageMagick on cygwin and it works fine using the forms you showed. Try using double dashes perhaps?

P.S.S. Ahah I found the problem! I copied your two lines and checked the ascii codes and found that the '-' (dash,hyphen) character in the second line is not the standard ascii character, it's a unicode character, probably because the script was copied from a word processor which often translates hyphens or quotes into special characters which look nicer printed, but don't work in any programming language (that I know of)

P.S.S.S. Then I found that G-Man already noticed this, d'oh!

1
  • like this: $ mogrify ‑resize 1024 ‑sample 70 -- image.jpg mogrify: unable to open image `‑resize': No such file or directory @ error/blob.c/OpenBlob/2658. ... Same result
    – Appost
    Oct 6, 2014 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .