#!/bin/zsh 


## D'abord on convertit tous les jpg en png 


for i in $(find . | egrep -i "\.(jpg|jpeg)"); 

	do

		newi=$(echo $i | sed -r 's/\.(jpg|jpeg)/.png/') 
		echo "$i devient $newi"
		magick $i $newi

	; done	


for i in $(find . | egrep -i "\.png"); 


	do 

		newi=$(echo $i | sed -r 's/\.png/-low.png/') 

		echo "On traite $i taille $(ls -lh $i | awk '{print $5}')"

		convert $i -filter Triangle -define filter:support=2 \
		-unsharp 0.25x0.08+8.3+0.045 +dither  -remap ../scripts/Apple_II.png \
		-posterize 136 \
		-quality 82 -define jpeg:fancy-upsampling=off \
		-define png:compression-filter=5 -define png:compression-level=9 \
		-define png:compression-strategy=1 -define png:exclude-chunk=all \
		-interlace none -colorspace sRGB -define png:color-type=3 $newi

		echo "Génération de $newi : $(ls -lh $newi | awk '{print $5}')"

	; done 


#find . | grep low.png | xargs /bin/rm -rf '{}' 