I have done a script to convert recursive .jpg files to another size:

echo $re
mkdir "$re"_tmp
for a in *.jpg ; do convert "$a" -resize $re "$re""_tmp/${a%.*} ["$re"].jpg" ; done

I'd like integrate a multi extension support: png, bmp, etc. better with:

FILEFORMAT="jpg, JPG, png, PNG, bmp, BMP"

any idea to build it?

PS: variable re is the new size 1024x768 (or 800x600, etc)

  • 1
    I hope you would consider processing files matching *.jpeg as well. Apparently someone in the distant past thought it should be *.jpg and this misnomer caught on in a big way... but it seems quite wrong: as if the Joint Photographic Experts Group became the Joint Photographic Group, the implication being that they're not experts! – Celada Jul 28 '14 at 0:48

If I understand right, you want to process files with other extension, instead of only jpg. So you can try:

for a in *.{jpg,JPG,png,PNG,bmp,BMP}; do
  printf '%s\n' "$a"
  # do your stuff here

{...} is bash feature called brace expansion.

  • thanks for help. I've added your suggestion but the script process only jpg files... strange... – Pol Hallen Jul 26 '14 at 17:38
  • Are you sure all your file is in the same folder? What is your bash version? – cuonglm Jul 26 '14 at 17:41
  • Hi, version of bash is 4.3-7 (debian testing) and yes, the files are on same folder. I know that the script rename all files to jpg but this is not a problem. Thanks – Pol Hallen Jul 26 '14 at 17:44
  • @PolHallen: With your bash version, brace expansion will work. So does it work now? – cuonglm Jul 26 '14 at 17:47
  • 1
    @Gnouc - are you certain this is not just an interactive shell thing? Also, even if not, it will very likely not work if the #! is for sh. It would be much simpler to do: set -- *.[jJ][pP][gG] *.[bB][mM][pP] *.[pP][nN][gG]; for pic do...;done which would keep the file list in "$@" for multiple process loops as necessary. – mikeserv Jul 26 '14 at 17:58

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.