Skip to content

Instantly share code, notes, and snippets.

@tvc97
Created January 20, 2021 04:23
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 tvc97/16565e1795c48639383c431e18702957 to your computer and use it in GitHub Desktop.
Save tvc97/16565e1795c48639383c431e18702957 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import sys
from PIL import Image
from resizeimage import resizeimage
imagePath = ''
fileName = ''
if len(sys.argv) == 1:
imagePath = input('Input file: ')
fileName = input('Output file name: ')
elif len(sys.argv) == 2:
imagePath = sys.argv[1]
fileName = input('Output file name: ')
elif len(sys.argv) == 3:
imagePath = sys.argv[1]
fileName = sys.argv[2]
androidSize = {
'drawable-mdpi': [229, 480],
'drawable-hdpi': [343, 720],
'drawable-xhdpi': [457, 959],
'drawable-xxhdpi': [686, 1440],
'drawable-xxxhdpi': [914, 1920],
}
iosSize = {
'x1': [375, 813],
'x2': [750, 1625],
'x3': [1125, 2437]
}
directory = os.path.dirname(imagePath)
androidOutput = directory + '/android'
iosOutput = directory + '/ios'
with open(imagePath, 'r+b') as f:
with Image.open(f) as image:
width, height = image.size
for key, value in androidSize.items():
target = androidOutput + '/' + key
os.makedirs(target, exist_ok = True)
print('Writting [android] ', key)
cover = resizeimage.resize_cover(image, value)
cover.save(target + '/' + fileName, image.format, optimize = True, compress_level = 9)
for key, value in iosSize.items():
os.makedirs(iosOutput, exist_ok = True)
print('Writting [ios] ', key)
cover = resizeimage.resize_cover(image, value)
cover.save(iosOutput + '/' + key + '.png', image.format, optimize = True, compress_level = 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment