# Python Image Resize {{tag>Python Image Resize}} ``` from PIL import Image @staticmethod def resize_image(image): max_size = 1200 resize_width = None resize_height = None image_orientation = None try: image_exif = image._getexif() image_orientation = image_exif[274] except Exception as e: print(e) if image_orientation: if image_orientation == 3: image = image.rotate(180) if image_orientation == 6: image = image.rotate(-90, expand=True) if image_orientation == 8: image = image.rotate(90, expand=True) width = image.width height = image.height # width 가 큰 경우만 변환하도록 수정 if width > max_size: resize_width = max_size resize_height = int(max_size * height / width) if resize_width and resize_height: image = image.resize(size=(resize_width, resize_height)) in_mem_file = io.BytesIO() image.save(in_mem_file, format='PNG') return in_mem_file.getvalue() ```