Skip to content

Commit

Permalink
resolve changelog conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton committed Jan 31, 2023
2 parents e537128 + 4aa7d8d commit f6419a8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Upcoming Release

## New Features:

### iOS image rotation fixed 🔄

Previously photos uploaded via iOS would be rotated after processing. This has been fixed by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3091)

#### Before
![image](https://user-images.githubusercontent.com/41651716/215846507-a36e9d05-1ac2-4867-8ab3-ce045a9415d9.png)

#### After
![image](https://user-images.githubusercontent.com/41651716/215846554-e41773ed-70f0-491a-9952-6a18babf91ef.png)

* Run on kaggle notebooks via sharelinks by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3101](https://github.com/gradio-app/gradio/pull/3101)

## Bug Fixes:
Expand All @@ -16,7 +27,7 @@ No changes to highlight.
No changes to highlight.

## Full Changelog:
No changes to highlight.
* Set minimum `markdown-it-py` version to `2.0.0` so that the dollar math plugin is compatible by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3102](https://github.com/gradio-app/gradio/pull/3102)

## Contributors Shoutout:
No changes to highlight.
Expand Down
7 changes: 6 additions & 1 deletion gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def to_binary(x: str | Dict) -> bytes:
def decode_base64_to_image(encoding: str) -> Image.Image:
content = encoding.split(";")[1]
image_encoded = content.split(",")[1]
return Image.open(BytesIO(base64.b64decode(image_encoded)))
img = Image.open(BytesIO(base64.b64decode(image_encoded)))
exif = img.getexif()
# 274 is the code for image rotation and 1 means "correct orientation"
if exif.get(274, 1) != 1 and hasattr(ImageOps, "exif_transpose"):
img = ImageOps.exif_transpose(img)
return img


def encode_url_or_file_to_base64(path: str | Path, encryption_key: bytes | None = None):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ aiohttp
altair>=4.2.0
fastapi
ffmpy
markdown-it-py[linkify,plugins]
markdown-it-py[linkify,plugins]>=2.0.0
markupsafe
matplotlib
numpy
Expand Down
8 changes: 8 additions & 0 deletions test/test_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def test_encode_pil_to_base64_keeps_pnginfo(self):

assert decoded_image.info == input_img.info

@patch("PIL.Image.Image.getexif", return_value={274: 3})
@patch("PIL.ImageOps.exif_transpose")
def test_base64_to_image_does_rotation(self, mock_rotate, mock_exif):
input_img = Image.open("gradio/test_data/test_image.png")
base64 = processing_utils.encode_pil_to_base64(input_img)
processing_utils.decode_base64_to_image(base64)
mock_rotate.assert_called_once()

def test_resize_and_crop(self):
img = Image.open("gradio/test_data/test_image.png")
new_img = processing_utils.resize_and_crop(img, (20, 20))
Expand Down

0 comments on commit f6419a8

Please sign in to comment.