Repository: streamlit/streamlit

Issue:
[Requirements] Pillow Version Issue (`Image.Resampling.BILINEAR`)
### Checklist

- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.

### Summary

In the Streamlit, the code ([this line](https://github.com/streamlit/streamlit/blob/b3e4ee6c14bc992790ad084acd07e7dbc4412a61/lib/streamlit/elements/image.py#L300)) uses `Image.Resampling.BILINEAR`, which is only available in `PIL` versions `>=9.1.0`. Here are the results of testing with different versions of Pillow:

```python
$ pip install pillow==9.0.0
>>> from PIL import Image
>>> Image.Resampling.BILINEAR
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/agilesoda/anaconda3/lib/python3.9/site-packages/PIL/Image.py", line 65, in __getattr__
    raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
AttributeError: module 'PIL.Image' has no attribute 'Resampling'

$ pip install pillow==9.1.0
>>> from PIL import Image
>>> Image.Resampling.
Image.Resampling.BICUBIC   Image.Resampling.BOX       Image.Resampling.LANCZOS   Image.Resampling.mro(      
Image.Resampling.BILINEAR  Image.Resampling.HAMMING   Image.Resampling.NEAREST   
>>> Image.Resampling.BILINEAR
<Resampling.BILINEAR: 2>
```

Based on this, it appears that the Pillow requirement in the [Streamlit requirements](https://github.com/Zerohertz/streamlit-contrib/commit/deca3bd4dd6d43b21adb9ab965a6542c79e1a28a) should be updated to reflect the correct minimum version.
Should I submit a pull request to update this?

### Reproducible Code Example

_No response_

### Steps To Reproduce

_No response_

### Expected Behavior

_No response_

### Current Behavior

_No response_

### Is this a regression?

- [ ] Yes, this used to work in a previous version.

### Debug info

- Streamlit version:
- Python version:
- Operating System:
- Browser:


### Additional Information

_No response_


Discussion:
**If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.**

Your feedback helps us prioritize which bugs to investigate and address first.

![Visits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fstreamlit%2Fstreamlit%2Fissues%2F8486&title=visits&edge_flat=false)

Thanks for pointing this out @Zerohertz! Looking at the pillow documentation, `Image.Resampling.BILINEAR` used to be `Image.BILINEAR` until it was deprecated, but the deprecation ended up being reversed in version 9.4.0 (before the constant was scheduled to be fully removed), so using `Image.BILINEAR` should just work with all supported versions. I think switching back to using it would be preferable to changing the version pins since I don't think there's any reason we can't support older pillow versions as well.

I'll go ahead and make this change myself while I'm looking at this issue since it's a pretty trivial one-liner.

Resolving patch:
diff --git a/lib/streamlit/elements/image.py b/lib/streamlit/elements/image.py
--- a/lib/streamlit/elements/image.py
+++ b/lib/streamlit/elements/image.py
@@ -296,9 +296,11 @@ def _ensure_image_size_and_format(
     if width > 0 and actual_width > width:
         # We need to resize the image.
         new_height = int(1.0 * actual_height * width / actual_width)
-        pil_image = pil_image.resize(
-            (width, new_height), resample=Image.Resampling.BILINEAR
-        )
+        # pillow reexports Image.Resampling.BILINEAR as Image.BILINEAR for backwards
+        # compatibility reasons, so we use the reexport to support older pillow
+        # versions. The types don't seem to reflect this, though, hence the type: ignore
+        # below.
+        pil_image = pil_image.resize((width, new_height), resample=Image.BILINEAR)  # type: ignore[attr-defined]
         return _PIL_to_bytes(pil_image, format=image_format, quality=90)
 
     if pil_image.format != image_format:


Test patch: