import PIL.Image
import base64
import json
import sys

base64_string = sys.argv[1]
base64_bytes = base64_string.encode("ascii")
sample_string_bytes = base64.b64decode(base64_bytes) 
sample_string = sample_string_bytes.decode("ascii")
json_str = json.loads(sample_string)
total_image=len(json_str)
img_dir_path="ScanedImagesTemp/"

def resize_image(name):
    img = PIL.Image.open(name)
    width, height = img.size
    new_size = (width//2, height//2)
    resized_image = img.resize(new_size)
    resized_image.save(name, optimize=True, quality=15)
  
for i in range(1, total_image+1):
    resize_image(img_dir_path+json_str[str(i)])

print("done")