Third Party > Other Utilities

Shell script for converting progressive JPEGs to baseline

(1/2) > >>

cereal_killer:
I found this shell script to convert progressive JPEG files to baseline: https://www.codeproject.com/Articles/438021/Shell-script-for-converting-progressive-JPEGs-to-b. This is much quicker than batch converting with irfanview. But unfortunately it won't work with file/folder names with spaces.


--- Code: ---for img in `find . -name "*" | egrep *\.jpe?g$`
do
  idout=`identify -verbose $img | grep -i interlace | grep -i none$`

  if [[ -z $idout ]]
  then
    echo "-------------------------"
    echo "$img is progressive"
    echo "....making copy of original with .prog extension"
    /bin/cp -f $img $img.prog
    echo "....converting to baseline"
    convert $img -interlace none $img
    echo "....done!"
  #else
    #echo "$img is non-progressive"
  fi
done
--- End code ---

I already tried to insert " in line 3, but it still doesn't work. My scripting knowledge is close to none. The Author hasn't responded to my inquiry yet. Does anyone have a fix for this? I think the part with copying the file with a new file extension is unnecessary. This surely would be a helpful tool and is worth to be added to https://www.rockbox.org/wiki/AlbumArt.
I appreciate any help.

Bilgus:
I'm not the most versed with shell scripts but I believe the problem is with what the shell considers a valid field separator
by default I think it is SPACE|TAB|NEWLINE so it needs to be set to just newline



--- Code: ---IFS_ORIG=$IFS #save original IFS will restore at end
set -f #Disable filename expansion (globbing).
IFS=$'\n'
for img in `find . -name "*" | egrep *\.jpe?g$`
do
  idout=`identify -verbose $img | grep -i interlace | grep -i none$`

  if [[ -z $idout ]]
  then
    echo "-------------------------"
    echo "$img is progressive"
    echo "....making copy of original with .prog extension"
    /bin/cp -f $img $img.prog
    echo "....converting to baseline"
    convert $img -interlace none $img
    echo "....done!"
  #else
    #echo "$img is non-progressive"
  fi
done
set +f
IFS=$IFS_ORIG

--- End code ---

cereal_killer:
Thank you so much Bilgus, now it works perfectly. I'll add this to the wiki, maybe someone else will find this usefull.

gevaerts:
Just for the record, newlines are perfectly valid in filenames, so that script is still breakable :)

cereal_killer:

--- Quote from: gevaerts on August 24, 2018, 04:17:08 PM ---Just for the record, newlines are perfectly valid in filenames, so that script is still breakable :)

--- End quote ---

I hope that this isn't the case very often. If there are newlines in filenames, I hope that the user has the knowledge to adjust this script. It is working fine for me and hopefully for many others, so I'll put it on the wiki.

Thank you Bilgus for the help.

Navigation

[0] Message Index

[#] Next page

Go to full version