bash - TCropping images with loop in imagemagick -


a pretty basic question i'm new imagemagick (and bash) , i'm having trouble batch cropping images in folder. i've tried using loop:

for image in '/home/donald/desktop/new folder'*.jpg;      convert "$image" -gravity center -crop 95x95% "${image%.jpg}"-modified.jpg done 

but returns:

convert.im6: unable open image `/home/donald/desktop/new folder/*.jpg': no such file or directory @ error/blob.c/openblob/2638. convert.im6: no images defined `/home/donald/desktop/new folder/*-modified.jpg' @ error/convert.c/convertimagecommand/3044." 

what proper way of doing this?

edit: apparently space in folder name causing problems deleted , things seem working.apparently if want use folder space name in bash need escape space.

i believe have no jpg files in /home/donald/desktop/new folder/ directory. shell interpret literal string /home/donald/desktop/new folder/*.jpg if there no files matching wildcard-ed string.

see example:

$ f in *.jpg*; echo $f; done file.jpg file2.jpg $ f in *.jpgg; echo $f; done *.jpgg 

see how last 1 literal string , not real file? should have been displayed first time if (notice trailing asterix symbol in *.jpg*).

you can fix checking if file exists before executing command, using [ -f "${file}" ]. instance:

for image in '/home/donald/desktop/new folder'*.jpg;      [ -f "${image}" ] && convert "$image" -gravity center -crop 95x95% "${image%.jpg}"-modified.jpg done 

this check if file image exists (-f) , execute following statement if true returned &&. had written || instead of && following statement executed when false returned.

note bash doesn't return true or false it's easiest way explain , comprehend notation.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -