diff --git a/src/PIL/Image.py b/src/PIL/Image.py
index 4e1cff312..30f0c2aac 100644
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -578,7 +578,12 @@ class Image(object):
         return self
 
     def __exit__(self, *args):
-        self.close()
+        if hasattr(self, "_close__fp"):
+            self._close__fp()
+        if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp')
+           and self.fp and self._exclusive_fp):
+            self.fp.close()
+        self.fp = None
 
     def close(self):
         """
@@ -610,12 +615,7 @@ class Image(object):
 
     if sys.version_info.major >= 3:
         def __del__(self):
-            if hasattr(self, "_close__fp"):
-                self._close__fp()
-            if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp')
-               and self.fp and self._exclusive_fp):
-                self.fp.close()
-            self.fp = None
+            self.__exit__()
 
     def _copy(self):
         self.load()

File descriptor closed after with block despite _exclusive_fp being False
### What did you do?
```python
import PIL.Image

file = open('r.png', 'rb')
with PIL.Image.open(file) as image:
    print('Exclusive FP =', image._exclusive_fp)

try:
    file.read()
    print('OK')
except ValueError as e:
    print('BAD', e)
```

### What did you expect to happen?
```
Exclusive FP = False
OK
```

### What actually happened?
```
Exclusive FP = False
BAD read of closed file
```
### What are your OS, Python and Pillow versions?

* OS: Windows 10
* Python: 3.7
* Pillow: 5.4.1

---

I believe this is what's causing https://github.com/LonamiWebs/Telethon/issues/1121. I can work around it by not using the `with` block:

```python
file = open('r.png', 'rb')
image = PIL.Image.open(file)
print('Exclusive FP =', image._exclusive_fp)

try:
    file.read()
    print('OK')
except ValueError as e:
    print('BAD', e)
```
...which shows OK, but it sounds like an issue here. Sorry if it's a duplicate, couldn't find anything similar.
diff --git a/Tests/test_image_load.py b/Tests/test_image_load.py
index d8f323eb8..9937218cd 100644
--- a/Tests/test_image_load.py
+++ b/Tests/test_image_load.py
@@ -28,3 +28,10 @@ class TestImageLoad(PillowTestCase):
             os.fstat(fn)
 
         self.assertRaises(OSError, os.fstat, fn)
+
+    def test_contextmanager_non_exclusive_fp(self):
+        with open("Tests/images/hopper.gif", "rb") as fp:
+            with Image.open(fp):
+                pass
+
+            self.assertFalse(fp.closed)

pip install -e .[dev]
parse_log_pytest
requirements.txt
apt-get update apt-get install -y gcc libjpeg-dev zlib1g-dev libtiff5-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev libharfbuzz-dev libfribidi-dev libxcb1-dev
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.16
babel==2.17.0
blessed==1.20.0
build==1.2.2.post1
certifi==2025.1.31
charset-normalizer==3.4.1
check-manifest==0.50
cov-core==1.15.0
coverage==7.8.0
coveralls==4.0.1
docopt==0.6.2
docutils==0.21.2
exceptiongroup==1.2.2
idna==3.10
imagesize==1.4.1
importlib_metadata==8.6.1
iniconfig==2.1.0
jarn.viewdoc==2.7
Jinja2==3.1.6
MarkupSafe==3.0.2
olefile==0.47
packaging==24.2
-e git+https://github.com/python-pillow/Pillow.git@81946775166e0331f53ab130741683f0153e2ad1#egg=Pillow
pluggy==1.5.0
pycodestyle==2.13.0
pyflakes==3.3.1
Pygments==2.19.1
pyproject_hooks==1.2.0
pyroma==4.2
pytest==8.3.5
pytest-cov==6.0.0
pytz==2025.2
requests==2.32.3
six==1.17.0
snowballstemmer==2.2.0
Sphinx==7.4.7
sphinx-rtd-theme==3.0.2
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
tomli==2.2.1
trove-classifiers==2025.3.19.19
urllib3==2.3.0
wcwidth==0.2.13
zipp==3.21.0

name: Pillow
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.16
      - babel==2.17.0
      - blessed==1.20.0
      - build==1.2.2.post1
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - check-manifest==0.50
      - cov-core==1.15.0
      - coverage==7.8.0
      - coveralls==4.0.1
      - docopt==0.6.2
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - jarn-viewdoc==2.7
      - jinja2==3.1.6
      - markupsafe==3.0.2
      - olefile==0.47
      - packaging==24.2
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.1
      - pygments==2.19.1
      - pyproject-hooks==1.2.0
      - pyroma==4.2
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - pytz==2025.2
      - requests==2.32.3
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==7.4.7
      - sphinx-rtd-theme==3.0.2
      - sphinxcontrib-applehelp==2.0.0
      - sphinxcontrib-devhelp==2.0.0
      - sphinxcontrib-htmlhelp==2.1.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==2.0.0
      - sphinxcontrib-serializinghtml==2.0.0
      - tomli==2.2.1
      - trove-classifiers==2025.3.19.19
      - urllib3==2.3.0
      - wcwidth==0.2.13
      - zipp==3.21.0
prefix: /opt/conda/envs/Pillow

Tests/test_image_load.py::TestImageLoad::test_contextmanager_non_exclusive_fp
Tests/test_image_load.py::TestImageLoad::test_close Tests/test_image_load.py::TestImageLoad::test_contextmanager Tests/test_image_load.py::TestImageLoad::test_sanity
src/PIL/Image.py
src/PIL/Image.py