Skip to content

Instantly share code, notes, and snippets.

@JKirchartz
Created July 28, 2018 21:55
Show Gist options
  • Save JKirchartz/33b82c5b55665c8af6c8e7e0094540b3 to your computer and use it in GitHub Desktop.
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
#! /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;
#! /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