#!/bin/sh ## ## Nautilus ## SCRIPT: 00_multi-img-files_CONVERT_TOjpg_convert-quality-100.sh ## ## PURPOSE: Converts a selected set of image files --- '.png' or '.gif' ## or whatever --- to '.jpg' files. ## ## METHOD: Uses ImageMagick 'convert' with option '-quality 100'. ## ## Shows the (last) new image file in an image viewer (or editor) ## of the user's choice. ## ## HOW TO USE: In the Nautilus file manager, navigate to the desired directory ## and select one or more image files. ## Then right-click and choose this script to run (name above). ## ########################################################################## ## Created: 2010feb18 ## Changed: 2011jul07 Changed to handle filenames with embedded spaces. ## (Removed use of FILENAMES var and use a 'for' loop ## WITHOUT the 'in' phrase. Ref: man bash ) ## Changed: 2012feb14 Changed name of script. Changed script to allow ## input files other than '.png' or '.gif'. ## Changed: 2012feb29 Touched up the comments above. ## Changed: 2013apr10 Added check for the convert executable. ########################################################################## ## FOR TESTING: (show statements as they execute) # set -x ######################################################### ## Check if the convert executable exists. ######################################################### EXE_FULLNAME="/usr/bin/convert" if test ! -f "$EXE_FULLNAME" then zenity --info --title "Executable NOT FOUND." \ --no-wrap \ --text "\ The convert executable $EXE_FULLNAME was not found. Exiting. If the executable is in another location, you can edit this script to change the filename. OR, install the ImageMagick package." exit fi ########################################### ## Get the filenames of the selected files. ########################################### ## OLD WAY: (failed on names with embedded spaces) # FILENAMES="$@" ## FILENAMES="$NAUTILUS_SCRIPT_SELECTED_URIS" ## FILENAMES="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ################################### ## START THE LOOP on the filenames. ################################### ## OLD WAY: (failed on names with embedded spaces) # for FILENAME in "$@" for FILENAME do ########################################################### ## Get the file extension, such as 'png' or 'gif'. ## Assumes one dot (.) in the filename, at the extension. ########################################################### FILEEXT=`echo "$FILENAME" | cut -d\. -f2` ########################################################### ## Check that the file extension is 'png' or 'gif'. ## COMMENTED for now. Instead we allow any image file type. ########################################################### # if test "$FILEEXT" != "png" -a "$FILEEXT" != "gif" # then # continue # # exit # fi ########################################################### ## Get the 'midname' of the filename by removing the ## extension --- such as '.png' or '.gif'. ## Assumes one dot (.) in the filename, at the extension. ########################################################### # FILENAMECROP=`echo "$FILENAME" | sed 's|\..*$||'` FILENAMECROP=`echo "$FILENAME" | cut -d\. -f1` ############################################################## ## Make the name of the output '.jpg' file. If the file ## already exists, skip processing this file. ## (We could use 'zenity --info' to pop a notice to the user.) ############################################################## OUTFILE="${FILENAMECROP}.jpg" if test -f "$OUTFILE" then continue # exit fi ######################################################################## ## Use 'convert' to make the 'jpg' file --- high-quality (near lossless). ######################################################################## # convert "$FILENAME" -quality 100 "$OUTFILE" $EXE_FULLNAME "$FILENAME" -quality 100 "$OUTFILE" done ## END OF LOOP: for FILENAME ############################################################# ## Show the LAST new image file. ## NOTE: The viewer may be able to go back through the other ## image files if multiple image files were resized. ############################################################# ## . $HOME/.gnome2/nautilus-scripts/.set_VIEWERvars.shi . $HOME/.freedomenv/feNautilusScripts/set_DIR_NautilusScripts.shi . $DIR_NautilusScripts/.set_VIEWERvars.shi $IMGVIEWER "$OUTFILE" & # $IMGEDITOR "$OUTFILE" &