Monday, 5 February 2024

Fix PNG files that are corrupted by Git

From https://stackoverflow.com/questions/55330848/how-to-recover-corrupted-png-files-due-to-improper-gitattributes


 lines=`wc -l < image.corrupted.png`

for x in `seq 1 $((lines+1))`; do 

   echo -n $x ''

   perl -pe 's/$/$1\r/ if ($. == 1 || $. =='$x')' < image.corrupted.png > image.fixed.png

   if pngcheck image.fixed.png; then

      echo Valid file substituting newline numbers 1 and $x

      break

   fi

done


No comments:

Post a Comment