<file_sep>from setuptools import setup, find_packages

def load_requirements():
    try:
        with open("./requirements.txt") as f:
            return [line.strip() for line in f.readlines()]
    except FileNotFoundError:
        print("WARNING: requirements.txt not found")
        return []

setup(
    name="toraw",
    version="0.1.0",
    description="",
    author="<NAME>",
    url="https://github.com/bwulff/toraw",
    packages=["toraw"],
    package_dir={"toraw": "src/toraw"},
    include_package_data=True,
    install_requires=load_requirements(),
    entry_points="""
        [console_scripts]
        toraw=toraw:cli
    """,
)<file_sep># Convert image files to RAW file (e.g. for Unity heightmaps)

This is a small Python script that will take a 1-channel image file (e.g. PNG) and converts it to a `.raw` file compatible for use in Unity e.g. for Terrain heightmaps.

<file_sep>import click
import numpy as np
from PIL import Image
from numpy import asarray

def convert(infile, outfile=None):
	image = Image.open(infile)
	data = asarray(image)
	print(f"Image size: {data.shape}")
	with open(outfile, 'wb') as f:
		for y in range(data.shape[0]):
			for x in range(data.shape[1]):
				v = np.uint16(data[y][x])
				f.write(v)

@click.command()
@click.argument("infile")
@click.option("--outfile", default=None, help="specify output filename (default: replace filename extension with .raw)")
def cli(infile, outfile):
	if outfile is None:
		parts = infile.split('.')
		parts[-1] = "raw"
		outfile = ".".join(parts)
	convert(infile, outfile)