# Pastebin MRYusVcs #!/usr/bin/env python3 #Android Screenshot Margin Cropper from os import listdir, path from PIL import Image class Nexus5(): #pixels axis_long = 1920 axis_short = 1080 landscape = (1920, 1080) portrait = (1080, 1920) class Margin(): #pixels top = 72 bottom = 144 ebaybanner = 144 #+72=216 dropshadow = 16 #+216=232 for file in listdir(directory): if file.endswith('.png'): filepath = path.join(directory, file) original = Image.open(filepath) width, height = original.size if width > height: orientation = 'landscape' if width < height: orientation = 'portrait' if width==height: orientation = 'square' def margin_crop(original, margin='both'): if margin == 'both': if orientation == 'landscape': cropped = original.crop((0+0, 0+72, width-144, height-0)) cropped.save('/sdcard/Pictures/Crops/'+file) if orientation == 'portrait': cropped = original.crop((0+0, 0+72, width-0, height-144)) cropped.save('/sdcard/Pictures/Crops/'+file) if margin == 'top': if orientation == 'landscape': cropped = original.crop((0+0, 0+72, width, height)) cropped.save('/sdcard/Pictures/Crops/'+file) if orientation == 'portrait': cropped = original.crop((0+0, 0+72, width, height)) cropped.save('/sdcard/Pictures/Crops/'+file) if margin == 'bottom': if orientation == 'landscape': cropped = original.crop((0+0, 0+0, width-144, height-0)) cropped.save('/sdcard/Pictures/Crops/'+file) if orientation == 'portrait': cropped = original.crop((0+0, 0+0, width-0, height-144)) cropped.save('/sdcard/Pictures/Crops/'+file) if margin == 'ebay': if orientation == 'landscape': cropped = original.crop((0+0, 0+216, width-144, height-0)) cropped.save('/sdcard/Pictures/Crops/'+file) if orientation == 'portrait': cropped = original.crop((0+0, 0+216, width-0, height-144)) cropped.save('/sdcard/Pictures/Crops/'+file) if __name__ == '__main__': main() ''' # ↓NOTES↓BELOW↓ # # REPL tested variations and scraps # ###################################### from os import listdir, path from PIL import Image test_dir = '/sdcard/Pictures/Test/' for x in listdir(test_dir): y = path.join(test_dir, x) z = Image.open(y) if z.size == (1920,1080): w, h = z.size z = z.crop((0, 72, w-144, h-0)) z.save(y) ###################################### #!/usr/bin/env python3 #landscape ebay screenshot cropper from os import listdir, path from PIL import Image test_dir = '/sdcard/Pictures/Screenshots/' for x in listdir(test_dir): if x.endswith('.png'): y = path.join(test_dir, x) z = Image.open(y) if z.size == (1920,1080): w, h = z.size z = z.crop((0+0, 0+216, w-144, h-0)) z.save(y) ###################################### #!/usr/bin/env python3 #portrait ebay screenshot cropper from os import listdir, path from PIL import Image test_dir = '/sdcard/Pictures/Screenshots/' for x in listdir(test_dir): if x.endswith('.png'): y = path.join(test_dir, x) z = Image.open(y) if z.size == (1920,1080): w, h = z.size z = z.crop((0+0, 0+216, w-0, h-144)) z.save(y) ###################################### '''