I saw the awesome thing at r/unixporn and wanted to make it lock faster and run it with sway, so here it is.
nix run https://gist.github.com/yorickvP/70cecb02096379b2f7a3510fb726f2ff/archive/master.tar.gz -c glitchlock
I saw the awesome thing at r/unixporn and wanted to make it lock faster and run it with sway, so here it is.
nix run https://gist.github.com/yorickvP/70cecb02096379b2f7a3510fb726f2ff/archive/master.tar.gz -c glitchlock
| with import <nixpkgs> { }; | |
| let | |
| pypkg = python37.pkgs; | |
| pillow_simd = (pypkg.pillow.overridePythonAttrs (old: rec { | |
| pname = "Pillow-SIMD"; | |
| version = "6.0.0.post0"; | |
| src = pypkg.fetchPypi { | |
| inherit pname version; | |
| sha256 = "1jla56zidgh9dscl5ndi025rvzsbn4zz5aqas0rgw60plpzzdfsr"; | |
| }; | |
| postPatch = ""; | |
| NIX_CFLAGS_COMPILE = "-mavx2 -msse4"; | |
| doCheck = false; | |
| })).override { libjpeg = libjpeg_turbo; }; | |
| in stdenv.mkDerivation { | |
| name = "glitchlock"; | |
| nativeBuildInputs = [ makeWrapper ]; | |
| buildInputs = [ (python37.withPackages (o: [ pillow_simd ])) ]; | |
| src = ./.; | |
| installPhase = '' | |
| mkdir -p $out/bin $out/libexec | |
| patchShebangs . | |
| cp glitchlock.sh $out/bin/glitchlock | |
| cp glitchlock.py $out/libexec | |
| chmod +x $out/bin/glitchlock | |
| chmod +x $out/libexec/glitchlock.py | |
| wrapProgram $out/bin/glitchlock --suffix PATH : ${ | |
| lib.makeBinPath [ sox grim swaylock ] | |
| }:$out/libexec | |
| ''; | |
| } |
| #!/usr/bin/env python | |
| # run with <(grim -t ppm -) | |
| from PIL import Image | |
| import subprocess, sys, os | |
| from io import BytesIO | |
| def pixelate(src, scale=10): | |
| dstsize = tuple(map(lambda x: x//scale, src.size)) | |
| iS = src.resize(dstsize, resample=Image.BILINEAR) | |
| return iS.resize(src.size, resample=Image.NEAREST) | |
| def glitch(src, dst): | |
| # Glitch it with sox FROM: https://maryknize.com/blog/glitch_art_with_sox_imagemagick_and_vim/ | |
| # src cannot be dst | |
| subprocess.check_call(["sox", "-t", "ul", "-c", "1", "-r", "48k", src, "-t", "ul", dst, "trim", "0", "100s", ":", "echo", "0.9", "0.9", "15", "0.9"]) | |
| def lock(filename): | |
| os.execlp('swaylock', 'swaylock', '-i', filename) | |
| screenshot = "/tmp/glitchlock.bmp" | |
| screenshot2 = "/tmp/glitchlock_glitched.bmp" | |
| pixelate(Image.open(sys.argv[1]), scale=7).save(screenshot) | |
| glitch(screenshot, screenshot2) | |
| Image.open(screenshot2).transpose(Image.ROTATE_90).save(screenshot) | |
| glitch(screenshot, screenshot2) | |
| Image.open(screenshot2).transpose(Image.ROTATE_270).save(screenshot) | |
| os.remove(screenshot2) | |
| lock(screenshot) |
| #/bin/sh | |
| glitchlock.py <(grim -t ppm -) |