fake-thumbnails.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # high="$1" # High image (full-size original view)
  4. # low="$2" # Low image (thumbnail) (should be the same size)
  5. # output="output.png"
  6. # [ ! -z "$3" ] && output="$3" # Output image
  7. # size=$(convert "$high" -format "%wx%h" info:)
  8. # convert "$high" -alpha off +level 3.5%,100% -gamma 20 high_gamma.png
  9. # low_gamma="-alpha off -gamma 0.8 +level 0%,77%"
  10. # convert \( "$low" $low_gamma \) high_gamma.png \
  11. # -compose Mathematics -define compose:args='0,-0.33,1,0.33' \
  12. # -composite low_adjusted.png
  13. # convert low_adjusted.png high_gamma.png -size $size pattern:gray25 -composite \
  14. # -set gamma 0.022727 -define png:include-chunk=none,gAMA "$output"
  15. # rm high_gamma.png low_adjusted.png
  16. # this autoscales image or some shit (better than the above)
  17. [ -z "$1" -o -z "$2" ] && echo "Need 2 input images." && exit 1
  18. [ -z "$3" ] && out="out.png" || out="$3"
  19. ffmpeg \
  20. -loglevel 'error' \
  21. -y \
  22. -i "$1" \
  23. -i "$2" \
  24. -filter_complex \
  25. "`echo \
  26. 'color=c=black[mask];' \
  27. '[mask][0:v]scale2ref[mask][main];' \
  28. '[1:v][main]scale2ref[scnd][main];' \
  29. '[mask]drawgrid=w=2:h=2:c=white,format=rgb24[mask];' \
  30. '[main]colorlevels=romin=0.01:gomin=0.01:bomin=0.01' \
  31. ':romax=0.21:gomax=0.21:bomax=0.21,eq=gamma=10.0,eq=gamma=1.4' \
  32. ',format=rgb24,split[main][temp];' \
  33. '[scnd]colorlevels=romin=0.0:gomin=0.0:bomin=0.0' \
  34. ':romax=0.8:gomax=0.8:bomax=0.8,eq=gamma=0.7,format=rgb24[scnd];' \
  35. '[temp][scnd]blend=all_expr='"'B - 0.33*A + 84'"',format=rgb24[scnd];' \
  36. '[main][scnd][mask]maskedmerge[vout]'`" \
  37. -frames:v 1 \
  38. -c:v png \
  39. -f image2 \
  40. -map '[vout]' \
  41. - | \
  42. convert \
  43. - \
  44. -set 'gamma' '0.027' \
  45. -define 'png:include-chunk=none,gAMA' \
  46. "$out"