diff --git a/gdal_wrapper.py b/gdal_wrapper.py new file mode 100644 index 0000000000000000000000000000000000000000..152ab4caef138909cfbeea7ec027eee8926b60c9 --- /dev/null +++ b/gdal_wrapper.py @@ -0,0 +1,25 @@ +import sys +import argparse +import subprocess + + +def gdal_translate(input_filename, output_filename, reduction_percent): + gdal_cmd = ["gdal_translate", "-outsize", f"{reduction_percent}%", f"{reduction_percent}%", + input_filename, output_filename] + proc = subprocess.Popen(gdal_cmd, stdout = subprocess.PIPE, stderr=subprocess.STDOUT) + out, err = proc.communicate() + print(out) + return proc.returncode, output_filename + + +if __name__ == "__main__": + parse = argparse.ArgumentParser(description="Runs gdal_translate -outsize to reduce input size by n%") + parse.add_argument("--input_file", help="Input file to use", required=True) + parse.add_argument("--output_file", help="Output file to write", required=True) + parse.add_argument("--outsize", help="Reduction size", required=True) + args = parse.parse_args() + exit_code, output = gdal_translate(args.input_file, args.output_file, args.outsize) + if exit_code != 0: + print(f"gdal_translate failed with a non-zero exit code: {exit_code}") + exit(exit_code) + \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..3de2df71e21ba8261a68fa4bdd53b25d30f22f3b --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +INPUT_FILENAME=$(ls -d input/*) +OUTPUT_FILENAME=$1 +REDUCTION_SIZE=$2 + +# Get path to this run.sh script +basedir=$( cd "$(dirname "$0")" ; pwd -P ) + +python ${basedir}/gdal_wrapper.py --input_file ${INPUT_FILENAME} --output_file output/${OUTPUT_FILENAME} --outsize ${REDUCTION_SIZE}