3 ms·
My solution: #!/bin/sh wget https://www.mi5.gov.uk/sites/default/files/u2/puzzle.png convert puzzle.png puzzle.xpm # Convert the image to XPM with ImageM
by networked 10y ago
My solution:
#!/bin/sh
wget https://www.mi5.gov.uk/sites/default/files/u2/puzzle.png
convert puzzle.png puzzle.xpm # Convert the image to XPM with ImageMagick.
# Here is what the contents of puzzle.xpm looks like:
# http://pastebin.com/0PySSAXx. The spaces represent one color and the dots
# the other. We'll replace the spaces with underscores for readability.
<puzzle.xpm tr ' ' _ \
| tr -d "\n" \
| sed -e 's|","||g; s|^.*\*/"||; s|".*$|| # Remove metadata, C framing.' \
| sed -e 's|_\.|_\n.|g; s|\._|.\n_|g # New line on color change. ' \
| awk '{printf "%c", length($0)}' \
| xxd -r -p
The XPM image file format (https://en.wikipedia.org/wiki/X_PixMap https://en.wikipedia.org/wiki/X_PixMap) is great for doing things like this. I find it easier to read and to edit by hand than the Netpbm format family. It seems ImageMagick can't write XPM2, though, which makes extra preprocessing necessary.