Created
July 28, 2018 21:55
-
-
Save JKirchartz/33b82c5b55665c8af6c8e7e0094540b3 to your computer and use it in GitHub Desktop.
Convert hpi files into pngs -- based on Ed Halley's Method: http://www.halley.cc/ed/linux/interop/hemera.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# depends on ImageMagick 6.8.9-9 | |
for name in *.hpi; do | |
echo $name | |
# split hpi into component jpg & png | |
./split.py $name | |
wait | |
# clean up jpg | |
convert $name.jpg -type truecolormatte matted.$name.png | |
# use png as mask for jpg (ala hpi's formatting) | |
convert matted.$name.png $name.png \ | |
-alpha off -compose CopyOpacity -composite \ | |
final.$name.png | |
wait | |
# clean up files generated during this process | |
rm -f matted.$name.png $name.jpg $name.png | |
mv final.$name.png ${name%%.*}.png | |
done; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# note: tested with python 2.7, may need tweaked for python 3+ | |
import sys, re | |
name = sys.argv[1] | |
try: | |
if name: | |
# read hpi file | |
f = open(name, "r"); | |
imgs = f.read() | |
# split image with regex | |
imgs = re.search(r"^.{32}(.*)(\211PNG.*)$", imgs, re.S) | |
# write first match as JPG | |
j = open(name + ".jpg", "w"); | |
j.write(imgs.group(1)); | |
# write second match as PNG | |
p = open(name + ".png", "w"); | |
p.write(imgs.group(2)); | |
# close all the files we've opened. | |
j.close() | |
p.close() | |
f.close() | |
else: | |
print name + " not found" | |
except: | |
print "could not split " + name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment