Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
batch command experienced an execution error
#2
Plenty of wrong things:
  • The input extension isn't removed when generating the output name, so you get things like foobar.jpg.jpg (note that this also avoid overwriting and input .jpg file).
  • Gimp is started/exited for each image: huge startup overhead
  • When you scale an image it scales canvas and layers, so gimp-image-resize-to-layers image is pointless
  • file-jpeg-save is missing a lot of parameters
Error: /: argument 1 must be: number is likely because (gimp-image-width image) didn't return a number.

Now, why would you use Gimp just to resize images. This is my personal script to create low-res copies of existing images (also gives a subtle contrast boost and some sharpening to compensate the blur from the rescale operation)

Code:
#! /bin/bash

size=3000
quality=85
dir=.
suffix=""


function error {
    >&2 echo "*** $*"
    exit 1
}

function usage {
    echo "$0 [-g <geometry>] [-q quality] [-d dir] [-s suffix] files"
}
        
OPTIND=1         # Reset in case getopts has been used previously in the shell.
while getopts "h?q:g:d:s:" opt; do
    case "$opt" in
    h|\?)
        usage
        exit 1
        ;;
    g)  size="$OPTARG"
        [[ "$size" =~ ^[0-9]+$ ]] || error "Size not a number: $size"
        [[ "$size" -lt 400 ]] && error "Size too small (<400)"
        ;;
    q)  quality="$OPTARG"
        [[ "$quality" =~ ^[0-9]+$ ]] || error "Quality not a number: $quality"
        [[ "$quality" -lt 50 || "$quality" -gt 98 ]] && error "Quality not in [50..98]"
        ;;
    s)  suffix="$OPTARG"
        ;;
    d)  dir="$OPTARG"
        ;;
    esac
done

shift $((OPTIND-1))
[[ "${1:-}" = "--" ]] && shift

mkdir -p "$dir" || error "Can't create directory"

for f in "$@"
do
    outname=$(basename "$f")
    if [[ -z $suffix ]]
    then
        out=$dir/${outname%.*}.jpg
    else
        out=$dir/${outname%.*}-$suffix.jpg
    fi
    echo "Exporting $f to $out"
    [[ -e $out ]] && error "$out already exists"
    convert "$f" -modulate 100,120  -geometry ${size}x${size} -sharpen 0x1.0 -quality $quality "$out"
done
Reply


Messages In This Thread
RE: batch command experienced an execution error - by Ofnuts - 07-17-2023, 09:00 AM

Forum Jump: