Created
December 9, 2021 16:48
-
-
Save ademar111190/c8c3e6a438d036b084a2cb1025317b6c to your computer and use it in GitHub Desktop.
Sips helper to crop android images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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