#!/bin/bash if [[ -z "$1" ]]; then echo "Missing required argument [heif_file]!" exit 1 fi # Set up the python environment if [ ! -f "/tmp/shell-scripts/venv/bin/python" ]; then mkdir -p /tmp/shell-scripts python3 -m venv /tmp/shell-scripts/venv > /dev/null 2>&1 fi # Install reqs /tmp/shell-scripts/venv/bin/pip install pillow pillow-heif > /dev/null 2>&1 # Finally run the script /tmp/shell-scripts/venv/bin/python << EOF from PIL import Image from pillow_heif import register_heif_opener from pathlib import Path from sys import exit path = Path("$1").resolve() if path.suffix.lower() != ".heic": exit(0) register_heif_opener() im = Image.open(path) im.save(path.with_suffix(".jpeg"), quality=100) EOF