letmaik / rawpy

📷 RAW image processing for Python, a wrapper for libraw
https://pypi.python.org/pypi/rawpy
MIT License
587 stars 67 forks source link

CR2 Thumbnail is rotated 90 degrees #186

Closed dc-vin closed 1 year ago

dc-vin commented 1 year ago

When executing the following code, the image will be rotated 90 degrees

thumb = raw.extract_thumb()
if thumb.format == rawpy.ThumbFormat.JPEG:
    with open(save_path, 'wb') as f:
        f.write(thumb.data)

CR2 image Thumbnail
image

Changing to the following code will get the correct result

  thumb = raw.extract_thumb()
  if thumb.format == rawpy.ThumbFormat.JPEG:
      img_data = imageio.v2.imread(thumb.data)
      imageio.imsave(save_path, img_data)
dc-vin commented 1 year ago

It's my fault, I did resize, and I should execute ImageOps.exif_transpose() img = Image.open(img_path) img = ImageOps.exif_transpose(img) img = img.resize(size=(int(img.width / resize_ratio), int(img.height / resize_ratio))) img.save(save_path, quality=100, optimize=True)