How to Crop or Resize the Image using python Script
Input - you need to pass input as a file path and save the out on the same path
Ouput - Return True
import os
from PIP import Image
def compress_Me(file):
filepath = os.path.join(os.getcwd(), file)
oldsize = os.stat(filepath).st_size
- picture = Image.open(filepath)
- dim = picture.size
- top = 0
- left = 0
- right = 360
- bottom = dim[1]
- cp = picture.crop((left, top, right, bottom))
- cp.save(file, "PNG")
- newsize = os.stat(os.path.join(os.getcwd(), file)).st_size
- percent = (oldsize - newsize) / float(oldsize) * 100
- print("File compressed from {0} to {1} or {2}%".format(oldsize, newsize, percent))
- return True
Comments
Post a Comment