Pastebin

Paste #15039: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

#!/bin/bash
quality="85"

SRC_FOLDER="_images"
DST_FOLDER="assets/images"

echo "Source folder is: $SRC_FOLDER"


function thumbnail() {
    src="$1"
    res="$2"
    q=$3
    #dst="$(basename "$src" .jpg)-$res.jpg"
    filename="$(basename -- $src)"
    ext="${filename##*.}"
    #dst="$(basename "$filename" .$ext)-$res.$ext"
    dst="$DST_FOLDER/$(basename "$filename" .$ext)-$res.$ext"

    # Only generate thumbnail if source is newer than dest
    [ "$src" -nt "$dst" ] && convert  -verbose -quality "$q" -resize "$res" "$src" "$dst"  # || echo "Skipping $src"
    #convert  -verbose -quality "$q" -resize "$res" "$src" "$DST_FOLDER/$(basename "$image" .jpg)-300x200.jpg"

}

function orig() {
    image="$1"
    filename="$(basename -- $image)"
    ext="${filename##*.}"
    dst="$DST_FOLDER/$(basename "$image" .${filename##*.})-orig.$ext"
    # Only copy file if source is newer than dest
    [ "$image" -nt "$dst" ] && cp -vf "$image" "$dst" # || echo "Skipping $src"
}

for image in $SRC_FOLDER/*.jpg $SRC_FOLDER/*.png $SRC_FOLDER/*.gif $SRC_FOLDER/*.heic ; do
    orig "$image"
    thumbnail "$image" "24x24" $quality
    thumbnail "$image" "32x32" $quality
    thumbnail "$image" "64x64" $quality
    thumbnail "$image" "100x100" $quality
    thumbnail "$image" "150x100" $quality
    thumbnail "$image" "300x200" $quality
    thumbnail "$image" "600x400" $quality
    thumbnail "$image" "900x800" 60
    thumbnail "$image" "1200x900" 50
    thumbnail "$image" "1800x1200" 45
    thumbnail "$image" "2400x1600" 40
    #convert  -verbose -quality $quality -resize 300x200 "$image" "$(basename "$image" .jpg)-300x200.jpg"
    #convert  -verbose -quality $quality -resize 600x400 "$image" "$(basename "$image" .jpg)-600x400.jpg"
done

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.