expqr/converter/nona.py

17 lines
No EOL
712 B
Python

import tempfile
import subprocess
import PythonMagick
def convert(infile, extension):
pto = tempfile.NamedTemporaryFile()
image = tempfile.NamedTemporaryFile(suffix=extension)
image.write(infile.read())
erect = ["erect2cubic", f"--erect={image.name}", f"--ptofile={pto.name}", "--filespec=PNG_m"]
subprocess.run(erect)
tiles = tempfile.TemporaryDirectory()
nona = ["nona", pto.name, "-o", tiles.name + "/out"]
subprocess.run(nona)
image = PythonMagick.Image(tiles.name + "/out0005.png")
geo = PythonMagick.Geometry(int(image.baseColumns() / 3), int(image.baseColumns() / 3), int(image.baseColumns() / 3), int(image.baseColumns() / 3))
image.crop(geo)
return image