diff --git a/images/dupe_test_images_append_ext/append_fn.sh b/images/dupe_test_images_append_ext/append_fn.sh new file mode 100755 index 0000000..4b2a056 --- /dev/null +++ b/images/dupe_test_images_append_ext/append_fn.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# TODO +# - Make ext var do something +# - Make images go to output dir when run + +# Config +# ------------------------------------------------------------------------------ +input_dir="$HOME/Desktop/append_fn" +ext="png" +output_dir="$HOME/Desktop/append_fn" + +# Utilities +# ------------------------------------------------------------------------------ +esc="\x1b[" +reset=${esc}"39;49;00m" +red=${esc}"31;01m" +sep_color=${esc}"38;5;8m" + +function sep() { + local sized=$(stty size | awk '{print $2}') + local len=${sized} + local ch="-" + local TERM_WIDTH="$(printf '%*s' "${len}" | tr ' ' "${ch}")" + + echo -e "${sep_color}${TERM_WIDTH}${reset}" +} + +# Check if the output folder exists +# ------------------------------------------------------------------------------ +# if [ ! -d "$output_dir" ]; then +# mkdir -p "$output_dir" +# fi + +# Check if the input folder exists. If so, cp and rename the file(s). +# ------------------------------------------------------------------------------ +if [ ! -d "$input_dir" ]; then + sep + echo -e " You don't have an input directory at ${red}${input_dir}${reset}." + echo -e " Create the directory, put your file(s) there and try again." + sep +else + for f in $input_dir/*.png; do + cp "$f" "${f%.png}-x-small.png" + cp "$f" "${f%.png}-small.png" + cp "$f" "${f%.png}-medium.png" + cp "$f" "${f%.png}-large.png" + cp "$f" "${f%.png}-x-large.png" + done +fi diff --git a/images/dupe_test_images_append_ext/convert_images_jpg.sh b/images/dupe_test_images_append_ext/convert_images_jpg.sh new file mode 100755 index 0000000..dda48c1 --- /dev/null +++ b/images/dupe_test_images_append_ext/convert_images_jpg.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +input_dir="$HOME/Desktop/convert" +exts="jpg,jpeg,JPG,png,gif" +output_dir="$HOME/Desktop/convert/processed" + +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" +fi + +for f in $input_dir/*."{$exts}" ; do + convert "$f" \ + -resize 500x \ + -set filename:fname '%t-x-small' \ + "$output_dir"/'%[filename:fname].jpg' + convert "$f" \ + -resize 700x \ + -set filename:fname '%t-small' \ + "$output_dir"/'%[filename:fname].jpg' + convert "$f" \ + -resize 900x \ + -set filename:fname '%t-medium' \ + "$output_dir"/'%[filename:fname].jpg' + convert "$f" \ + -resize 1000x \ + -set filename:fname '%t-large' \ + "$output_dir"/'%[filename:fname].jpg' + convert "$f" \ + -resize 1400x \ + -set filename:fname '%t-x-large' \ + "$output_dir"/'%[filename:fname].jpg' +done + +# Run the mac ImageOptim app via command line +# Slow. as. hell. Try running imageoptim-cli below instead +# ------------------------------------------------------------------------------ +# for f in $output_dir/*.jpg ; do +# "/Applications/ImageOptim.app/Contents/MacOS/ImageOptim" "$f" +# done + +# Run imageoptim-cli +# brew install imageoptim-cli, if you don't already have it +# A little bit faster than running the app, but not much. JPG files are quicker. +# ------------------------------------------------------------------------------ +imageoptim $output_dir + +# Copy the original image to the processed folder AFTER running imageoptim +# ------------------------------------------------------------------------------ +cp $input_dir/*.* $output_dir/ diff --git a/images/dupe_test_images_append_ext/convert_images_png.sh b/images/dupe_test_images_append_ext/convert_images_png.sh new file mode 100755 index 0000000..0a09c63 --- /dev/null +++ b/images/dupe_test_images_append_ext/convert_images_png.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +input_dir="$HOME/Desktop/convert" +exts="jpg,jpeg,JPG,png,gif" +output_dir="$HOME/Desktop/convert/processed" + +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" +fi + +for f in $input_dir/*."{$exts}" ; do + convert "$f" \ + -resize 500x \ + -set filename:fname '%t-x-small' \ + "$output_dir"/'%[filename:fname].png' + convert "$f" \ + -resize 700x \ + -set filename:fname '%t-small' \ + "$output_dir"/'%[filename:fname].png' + convert "$f" \ + -resize 900x \ + -set filename:fname '%t-medium' \ + "$output_dir"/'%[filename:fname].png' + convert "$f" \ + -resize 1000x \ + -set filename:fname '%t-large' \ + "$output_dir"/'%[filename:fname].png' + convert "$f" \ + -resize 1400x \ + -set filename:fname '%t-x-large' \ + "$output_dir"/'%[filename:fname].png' +done + +# Run the mac ImageOptim app via command line +# Slow. as. hell. Try running imageoptim-cli below instead +# ------------------------------------------------------------------------------ +# for f in $output_dir/*.png ; do +# "/Applications/ImageOptim.app/Contents/MacOS/ImageOptim" "$f" +# done + +# Run imageoptim-cli +# brew install imageoptim-cli, if you don't already have it +# A little bit faster than running the app, but not much. JPG files are quicker. +# ------------------------------------------------------------------------------ +imageoptim $output_dir + +# Copy the original image to the processed folder AFTER running imageoptim +# ------------------------------------------------------------------------------ +cp $input_dir/*.* $output_dir/ diff --git a/images/dupe_test_images_append_ext/fileext_rename.sh b/images/dupe_test_images_append_ext/fileext_rename.sh new file mode 100755 index 0000000..240977f --- /dev/null +++ b/images/dupe_test_images_append_ext/fileext_rename.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# CP and rename files in place, adding site specific extensions + +for f in *.png; do + cp "$f" "${f%.png}-x-small.png" + cp "$f" "${f%.png}-small.png" + cp "$f" "${f%.png}-medium.png" + cp "$f" "${f%.png}-large.png" + cp "$f" "${f%.png}-x-large.png" +done