#!/bin/bash
# opt-png-half 1.0 - Kjell Emanuelsson 2025
# Use in terminal or Thunar/Nemo Custom Action (%F) - Convert, resize 50% and Optimize!
args=( "$@" )
OG_IFS=$IFS
IFS=""
for f in ${args[@]}; do
    # assuming pow2 textures:
    x=$(identify -format "%w" "$f") 
    new_size="2048x2048"
    if [ "$x" -lt "2049" ]; then
        new_size="1024x1024"
    fi
    mogrify -compress none -resize $new_size "$f" && oxipng -v --opt max --alpha --strip all "$f"
    done
IFS=$OG_IFS
