diff --git a/chertex.sh b/chertex.sh index 52732fb..7a3bc45 100755 --- a/chertex.sh +++ b/chertex.sh @@ -93,7 +93,7 @@ if [ $# -eq 1 ]; then echo " -------------------------------" echo " Getting external assets" echo " -------------------------------" - # summary of operations in this if-clause: + # summary of operations in this if-clause: # trawl the assets/ subdirectories looking for a file "external.assets", if found, # read its contents line-by-line (each line is a path) and copy that file at that path to the current assets/ subdir # note that we only look for assets.external inside the subdirectories, and not in assets/ itself @@ -150,16 +150,24 @@ if [ $# -eq 1 ]; then largephototype=${largephotobase#*.} # file extension only largephotoname=${largephotofilename%.*} # path without extension largephotobasename=${largephotobase%.*} # basename without extension - if [ ! "$largephototype" == "jpg" ] && [ ! "$largephototype" == "jpeg" ] && [ ! "$largephototype" == "JPG" ] && [ ! "$largephototype" == "JPEG" ]; then - echo " Converting $largephotobase to JPG format" - mogrify -format jpg $largephotofilename - # remove the now unnecessary non-jpg file from .lowres/ - rm "$largephotofilename" + # some filetypes don't fare well when converted to jpeg, so we will only run the + # forced conversion and shrinking unless the file extension is one of the following: + # "" (empty string, ie no file extension) + # SVG + # PDF + if [ ! "$largephototype" == "" ] || [ ! "$largephototype" == "svg" ] || [ ! "$largephototype" == "SVG" ] || [ ! "$largephototype" == "pdf" ] || [ ! "$largephototype" == "PDF" ]; then + # if the photo is not already jpeg, convert it to jpeg + if [ ! "$largephototype" == "jpg" ] && [ ! "$largephototype" == "jpeg" ] && [ ! "$largephototype" == "JPG" ] && [ ! "$largephototype" == "JPEG" ]; then + echo " Converting $largephotobase to JPG format" + mogrify -format jpg $largephotofilename + # remove the now unnecessary non-jpg file from .lowres/ + rm "$largephotofilename" + fi + # convert photo in-place (overwrite) with new one roughly 300kb in size + # https://stackoverflow.com/questions/6917219/imagemagick-scale-jpeg-image-with-a-maximum-file-size + echo " Shrinking $largephotobasename.jpg" + convert $largephotoname.jpg -define jpeg:extent=300kb $largephotoname.jpg fi - # convert photo in-place (overwrite) with new one roughly 300kb in size - # https://stackoverflow.com/questions/6917219/imagemagick-scale-jpeg-image-with-a-maximum-file-size - echo " Shrinking $largephotobasename.jpg" - convert $largephotoname.jpg -define jpeg:extent=300kb $largephotoname.jpg done # update the modification and access time on the photosastrun file touch "$photoslastrun"