3

I have a command line problem - probably a pretty easy one, but it seems I can't enter the right words into google.

So I want to resize all *.png images in the folder using imagemagick - this would be something like "convert -resize 80% " and I want "filename" → "small_filename"

So I tried:

for f in *.png ; convert -resize 80% "$f" "small_$f" ; done

but "syntax error near unexpected token `convert" - I suppose you can't just import imagemagick commands into the bash ?

I would be delighted if you could help.

  • 3
    You are missing a do keyword: for f in *.png; do convert ... – steeldriver Aug 13 '14 at 0:17
  • @steeldriver Shouldn't this be an answer, not a comment? – TheSchwa Aug 13 '14 at 3:19
4

You missed do after for ... string. Here is a slightly modified script, but your version will work also if you add do missing in there.

for f in *.png
do
echo "Converting $f."
convert "$f" -resize 80% "${f/.png/-80%.png}"
done

A name changing here works as follows: for every $f as a text string find its .png part and change it for -80%.png

  • 1
    Your answer has been flagged low quality. Could you please improve it by adding some information on why this works? – kraxor Aug 13 '14 at 6:03
  • 1
    @kraxor yes, sure, I put an explanation to the answer. – Ruslan Gerasimov Aug 13 '14 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.