Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*-coding:utf-8 -*-
- from PIL import Image
- def resize(png_path, base_width):
- img = Image.open(png_path)
- wpercent = (base_width / float(img.size[0]))
- hsize = int((float(img.size[1]) * float(wpercent)))
- resized_img = img.resize((base_width, hsize), Image.ANTIALIAS)
- return resized_img
- def png_to_jpg(png_path, target_img):
- fill_color = None
- img = target_img
- jpg_path = png_path[:-4]+'.jpg'
- if img.mode in ('RGBA', 'LA'):
- background = Image.new(img.mode[:-1], img.size, fill_color)
- background.paste(img, img.split()[-1])
- img = background
- img.save(jpg_path, 'JPEG')
- def resize_png2jpg(png_path, base_width):
- img = resize(png_path, base_width)
- png_to_jpg(png_path, img)
- # 사용
- resize_png2jpg("people.png", 1600)
Add Comment
Please, Sign In to add comment