# INSTRUCTIONS # Requires ImageMagick 7+ (to confirm your version, type magick -version into terminal, or convert -version for older versions). # Requires Exiftool (mine works with Exiftool 11.88. To confirm your version, type exiftool -ver into terminal. If metadata is not important to you, delete the exiftool commands and it will no longer be required). # Operating System: Tested on Linux Mint 20.3 (Ubuntu 20.04). Should work on most Linux OS. # Purpose: Downsize your image with a number of different outputs in jpg. # Ideal input is 16 bit tiff with an embedded linear colour space (eg. linear rec 2020, linear sRGB, etc...). To confirm the colour space embedded in your image, open terminal, run identify -verbose /path/'image name.tif' and find the category icc:description # In file browser, rename this file Magick-Resize-Width.sh, right click > properties > permissions, tick box 'is executionable', ok. # To edit: right click > open with text editor # To run: Open terminal and enter /path/Magick-Stair-Step-resize-Width.sh # VARIABLES # INFILE: Replace $0 with /path/'your image name.tif' # OUTFILE: Replace $1 ($2, $3, etc...) with /path/'your image name.jpg' (Ensure all OUTFILES have different file names, or they will overwrite the same file) # STEPS: An integer. The number of increments used to downsize. For the filters that benefit, there is little to be gained using more than 10. The number of -distort resize lines should equal the number of steps, so add (using copy/paste) or remove lines accordingly. # proportion=1/STEPS1 [eg. 1/10=0.1 will downsize towards outpx 10% at a time. eg. 1/4=0.25 will downsize towards outpx 25% at a time] # ICCPROFILE: Replace $7 with /path/'profile.icc' # blurvariable: Part of the formula to determine the -gaussian-blur radius. Where Radius=inpx/outpx/blurvariable. Typically a value from 3-5 will be chosen. # outpx: Width in pixels of your desired output # -quiet: Suppresses all warning messages. Helpful if your tif has tags that libTIFF (used by ImageMagick) doesn't recognise. Remove if unnecessary. # -filter: Different artefacts will present depending on the filter chosen, from blur to haloing, and blockiness to aliasing (moire). We try to find a sweet spot giving greatest perceived sharpness with least artefacts. # -define filter: For a comprehensive look at filters, please visit: https://www.imagemagick.org/Usage/filter/ # -intent: Determines how out of gamut colours are mapped back in when converting from a larger colour space to a smaller one. Perceptual will shift hue slightly to retain smooth gradients (best for detail). Relative will maintain hue at the risk of unsmooth gradients, aka posterisation (best for hue accuracy). # -black-point-compensation: Ensures your darkest shadows do not get crushed to black during colour space conversion. Remove if undesired. # -profile: converts your colour space to that chosen. sRGB is standard for web display. A large selection of profiles are available here: https://github.com/ellelstone/elles_icc_profiles/tree/master/profiles (From that list, sRGB-elle-V2-srgbtrc.icc is the standard for web display. Note that they are matrix profiles, thus do not support Perceptual intent) # -quality: Applies to both jpeg and mpeg ouput formats. Accepts values from 1-100, where smaller values increase compression, thus reducing both file size and quality. When quality is >90 the chroma channels are not downsampled, making this optimal. # exiftool -TagsFromFile copies metadata from INFILE, while "all>exif:all" pastes only exif metadata to OUTFILE, preventing your xmp metadata from being overwritten. If you wish to paste all metadata, replace it with "-all>all". -overwrite_original prevents a duplicate from being created. If you don't wish to copy/paste any metadata, put a # in front of the line. (Reason to include this line is that ImageMagick cannot read/write all tiff metadata, so we use Exiftool to recover that which ImageMagick doesn't handle) # rm will delete the file listed, which is INFILE by default. If you do not wish for this to be deleted, put a # in front of the line. # The above are suggested variables. For a complete list, please visit: https://imagemagick.org/script/command-line-options.php and https://exiftool.org/ # SCRIPT INFILE=$0 OUTFILE1=$1 STEPS1=10 OUTFILE2=$2 STEPS2=1 OUTFILE3=$3 STEPS3=1 OUTFILE4=$4 STEPS4=1 OUTFILE5=$5 STEPS5=1 OUTFILE6=$6 STEPS6=1 ICCPROFILE=$7 blurvariable=4 outpx=1600 echo INFILE="${INFILE}" OUTFILE1="${OUTFILE1}" OUTFILE2="${OUTFILE2}" OUTFILE3="${OUTFILE3}" OUTFILE4="${OUTFILE4}" OUTFILE5="${OUTFILE5}" OUTFILE6="${OUTFILE6} "STEPS1=${STEPS1} STEPS2=${STEPS2} STEPS3=${STEPS3} STEPS4=${STEPS4} STEPS5=${STEPS5} STEPS6=${STEPS6} ICCPROFILE="${ICCPROFILE}" inpx=$(magick -quiet "${INFILE}" -format %w info:) proportion1=1/${STEPS1} proportion2=1/${STEPS2} proportion3=1/${STEPS3} proportion4=1/${STEPS4} proportion5=1/${STEPS5} proportion6=1/${STEPS6} echo inpx=${inpx} outpx=${outpx} blurvariable=${blurvariable} proportion1=${proportion1} proportion2=${proportion2} proportion3=${proportion3} proportion4=${proportion4} proportion5=${proportion5} proportion6=${proportion6} # OUTFILE1: STAIR STEP LANCZOS # note: if this output gives moire, use -distort resize instead magick -quiet "${INFILE}" \ -filter Lanczos \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize "%[fx:w-(${inpx}-${outpx})*${proportion1}]" \ -distort resize ${outpx} \ -intent Perceptual -black-point-compensation -profile "${ICCPROFILE}" \ -quality 92 \ "${OUTFILE1}" exiftool -overwrite_original -TagsFromFile "${INFILE}" "-all>exif:all" "${OUTFILE1}" #OUTFILE2: ROBIDOUXSHARP magick -quiet "${INFILE}" \ -filter RobidouxSharp \ -distort resize ${outpx} \ -intent Perceptual -black-point-compensation -profile "${ICCPROFILE}" \ -quality 92 \ "${OUTFILE2}" exiftool -overwrite_original -TagsFromFile "${INFILE}" "-all>exif:all" "${OUTFILE2}" # OUTFILE3: CATROM SPLINE magick -quiet "${INFILE}" \ -filter Catrom \ -define filter:widow=Spline -define filter:lobes=4 \ -distort resize ${outpx} \ -intent Perceptual -black-point-compensation -profile "${ICCPROFILE}" \ -quality 92 \ "${OUTFILE3}" exiftool -overwrite_original -TagsFromFile "${INFILE}" "-all>exif:all" "${OUTFILE3}" # OUTFILE4: GAUSSIAN-BLUR magick -quiet "${INFILE}" \ -gaussian-blur "%[fx:(${inpx}/${outpx})/${blurvariable}]" \ -resize ${outpx} \ -intent Perceptual -black-point-compensation -profile "${ICCPROFILE}" \ -quality 92 \ "${OUTFILE4}" exiftool -overwrite_original -TagsFromFile "${INFILE}" "-all>exif:all" "${OUTFILE4}" # OUTFILE5: LANCZOSRADIUS magick -quiet "${INFILE}" \ -filter LanczosRadius \ -distort resize ${outpx} \ -intent Perceptual -black-point-compensation -profile "${ICCPROFILE}" \ -quality 92 \ "${OUTFILE5}" exiftool -overwrite_original -TagsFromFile "${INFILE}" "-all>exif:all" "${OUTFILE5}" # OUTFILE6: To do: Combine different results. # DELETE INFILE rm "${INFILE}"