24 lines
849 B
Python
24 lines
849 B
Python
#!/usr/bin/env python3
|
|
"""Prepare a reference for feature matching without changing its artwork."""
|
|
import argparse
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('--input', required=True)
|
|
p.add_argument('--output', required=True)
|
|
p.add_argument('--target', type=int, default=1024)
|
|
a = p.parse_args()
|
|
im = Image.open(a.input).convert('RGBA')
|
|
longest = max(im.width, im.height)
|
|
if longest < a.target:
|
|
scale = a.target / longest
|
|
size = (max(1, round(im.width * scale)), max(1, round(im.height * scale)))
|
|
# Nearest-neighbour preserves pixel-art edges and transparency.
|
|
im = im.resize(size, Image.Resampling.NEAREST)
|
|
im.save(a.output)
|
|
print(f'Reference prepared: {im.width}x{im.height}')
|
|
|
|
if __name__ == '__main__': main()
|