Skip to content

Instantly share code, notes, and snippets.

@ademar111190
Created December 9, 2021 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademar111190/c8c3e6a438d036b084a2cb1025317b6c to your computer and use it in GitHub Desktop.
Save ademar111190/c8c3e6a438d036b084a2cb1025317b6c to your computer and use it in GitHub Desktop.
Sips helper to crop android images
#!/usr/bin/env python3
import subprocess
path_prefix = "/Users/…/src/main/res"
configs = [
(648, 648, "drawable-xxhdpi"),
(432, 432, "drawable-xhdpi"),
(324, 324, "drawable-hdpi"),
(216, 216, "drawable-mdpi")
]
files = [
"file.jpeg"
]
for width, height, folder in configs:
for file in files:
file_in_path = "{prefix}/drawable-xxxhdpi/{file}".format(prefix = path_prefix, file = file)
file_out_path = "{prefix}/{folder}/{file}".format(prefix = path_prefix, file = file, folder = folder)
bashCommand = "sips -z {width} {height} {file_in} -o {file_out}".format(
width=width, height=height, file_in=file_in_path, file_out=file_out_path)
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
print(output, error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment