pic.py 758 B

1234567891011121314151617181920212223242526
  1. from PIL import Image
  2. class Picture:
  3. def __init__(self, in_path, im=None):
  4. if im:
  5. self.im = im
  6. else:
  7. self.im = Image.open(in_path)
  8. self.x, self.y = self.im.size
  9. def save_img(self, outpath, quality=90):
  10. # self.im = self.im.convert("RGB")
  11. self.im.save(outpath, quality=quality)
  12. def resize(self, width):
  13. re_x = int(width)
  14. re_y = int(self.y * re_x / self.x)
  15. self.im = self.im.resize((re_x, re_y), Image.BICUBIC)
  16. self.x, self.y = self.im.size
  17. def resize_by_heigh(self, heigh):
  18. re_y = int(heigh)
  19. re_x = int(self.x * re_y / self.y)
  20. self.im = self.im.resize((re_x, re_y), Image.BICUBIC)
  21. self.x, self.y = self.im.size