diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py
index 5f9ba59c1..63a0f662b 100644
--- a/src/PIL/GifImagePlugin.py
+++ b/src/PIL/GifImagePlugin.py
@@ -569,8 +569,11 @@ def _write_local_header(fp, im, offset, flags):
 
     if "comment" in im.encoderinfo and 1 <= len(im.encoderinfo["comment"]):
         fp.write(b"!" + o8(254))  # extension intro
-        for i in range(0, len(im.encoderinfo["comment"]), 255):
-            subblock = im.encoderinfo["comment"][i : i + 255]
+        comment = im.encoderinfo["comment"]
+        if isinstance(comment, str):
+            comment = comment.encode()
+        for i in range(0, len(comment), 255):
+            subblock = comment[i : i + 255]
             fp.write(o8(len(subblock)) + subblock)
         fp.write(o8(0))
     if "loop" in im.encoderinfo:

Saving as GIF throws exception when source image has "comment" metadata
### What did you do?
Attempted to open a png image file, and save it as a gif file.

### What did you expect to happen?
The file should have been successfully saved/converted

### What actually happened?
This exception was thrown:
```
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    image.save("out.gif", "gif")
  File "/usr/local/lib/python3.6/site-packages/PIL/Image.py", line 2084, in save
    save_handler(self, fp, filename)
  File "/usr/local/lib/python3.6/site-packages/PIL/GifImagePlugin.py", line 513, in _save
    _write_single_frame(im, fp, palette)
  File "/usr/local/lib/python3.6/site-packages/PIL/GifImagePlugin.py", line 415, in _write_single_frame
    _write_local_header(fp, im, (0, 0), flags)
  File "/usr/local/lib/python3.6/site-packages/PIL/GifImagePlugin.py", line 577, in _write_local_header
    fp.write(o8(len(subblock)) + subblock)
TypeError: can't concat str to bytes
```

### What are your OS, Python and Pillow versions?
* OS: Ubuntu 14.04.5
* Python: 3.6.6
* Pillow: 6.2.1

## Code to Reproduce
```python
from PIL import Image
image = Image.open("example.png")
image.save("out.gif", "gif")
```
Have this image in the directory while running the code:
![example.png](https://user-images.githubusercontent.com/3231343/71637322-bc562c00-2bf4-11ea-8198-7712d87eda23.png)

## My diagnosis
It appears that it is erroring because when it tries to write the "comment" field from the encoderinfo of the image, the "comment" field is a string instead of bytes. I'm guessing either that should be checked here, or it should be read in differently when `Image.open` is called. I checked this by checking the metadata of the image via `identify -verbose example.png`. When I stripped the metadata from the image using `mogrify -strip example.png`, the issue went away and the conversion was successful.

Heres the stripped version of the image that has no issues when converted using the code above:
![example_stripped.png](https://user-images.githubusercontent.com/3231343/71637362-42bf3d80-2bf6-11ea-8931-45482fc05116.png)

I'd create a pull request for this myself, except I'm not sure if the fix needs to be on reading it in, or attempting to write it when writing the gif.

diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py
index bbd589ada..61c3d8f78 100644
--- a/Tests/test_file_gif.py
+++ b/Tests/test_file_gif.py
@@ -565,14 +565,18 @@ class TestFileGif(PillowTestCase):
                 im.info["comment"], b"File written by Adobe Photoshop\xa8 4.0"
             )
 
-            out = self.tempfile("temp.gif")
-            im = Image.new("L", (100, 100), "#000")
-            im.info["comment"] = b"Test comment text"
-            im.save(out)
+        out = self.tempfile("temp.gif")
+        im = Image.new("L", (100, 100), "#000")
+        im.info["comment"] = b"Test comment text"
+        im.save(out)
         with Image.open(out) as reread:
-
             self.assertEqual(reread.info["comment"], im.info["comment"])
 
+        im.info["comment"] = "Test comment text"
+        im.save(out)
+        with Image.open(out) as reread:
+            self.assertEqual(reread.info["comment"], im.info["comment"].encode())
+
     def test_comment_over_255(self):
         out = self.tempfile("temp.gif")
         im = Image.new("L", (100, 100), "#000")

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
black==25.1.0
blessed==1.20.0
build==1.2.2.post1
certifi==2025.1.31
charset-normalizer==3.4.1
check-manifest==0.50
click==8.1.8
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
mypy-extensions==1.0.0
olefile==0.47
packaging==24.2
pathspec==0.12.1
-e git+https://github.com/python-pillow/Pillow.git@94ec95c571777cf5188c5b791957220d723194a1#egg=Pillow
platformdirs==4.3.7
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
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
typing_extensions==4.13.0
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
      - black==25.1.0
      - blessed==1.20.0
      - build==1.2.2.post1
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - check-manifest==0.50
      - click==8.1.8
      - 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
      - mypy-extensions==1.0.0
      - olefile==0.47
      - packaging==24.2
      - pathspec==0.12.1
      - platformdirs==4.3.7
      - 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
      - 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
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - wcwidth==0.2.13
      - zipp==3.21.0
prefix: /opt/conda/envs/Pillow

Tests/test_file_gif.py::TestFileGif::test_comment
Tests/test_file_gif.py::TestFileGif::test_append_images Tests/test_file_gif.py::TestFileGif::test_background Tests/test_file_gif.py::TestFileGif::test_bbox Tests/test_file_gif.py::TestFileGif::test_closed_file Tests/test_file_gif.py::TestFileGif::test_comment_over_255 Tests/test_file_gif.py::TestFileGif::test_context_manager Tests/test_file_gif.py::TestFileGif::test_dispose2_background Tests/test_file_gif.py::TestFileGif::test_dispose2_diff Tests/test_file_gif.py::TestFileGif::test_dispose2_palette Tests/test_file_gif.py::TestFileGif::test_dispose_background Tests/test_file_gif.py::TestFileGif::test_dispose_none Tests/test_file_gif.py::TestFileGif::test_dispose_previous Tests/test_file_gif.py::TestFileGif::test_duration Tests/test_file_gif.py::TestFileGif::test_eoferror Tests/test_file_gif.py::TestFileGif::test_extents Tests/test_file_gif.py::TestFileGif::test_getdata Tests/test_file_gif.py::TestFileGif::test_headers_saving_for_animated_gifs Tests/test_file_gif.py::TestFileGif::test_identical_frames Tests/test_file_gif.py::TestFileGif::test_identical_frames_to_single_frame Tests/test_file_gif.py::TestFileGif::test_invalid_file Tests/test_file_gif.py::TestFileGif::test_iss634 Tests/test_file_gif.py::TestFileGif::test_lzw_bits Tests/test_file_gif.py::TestFileGif::test_multiple_duration Tests/test_file_gif.py::TestFileGif::test_n_frames Tests/test_file_gif.py::TestFileGif::test_number_of_loops Tests/test_file_gif.py::TestFileGif::test_optimize Tests/test_file_gif.py::TestFileGif::test_optimize_correctness Tests/test_file_gif.py::TestFileGif::test_optimize_full_l Tests/test_file_gif.py::TestFileGif::test_palette_434 Tests/test_file_gif.py::TestFileGif::test_palette_handling Tests/test_file_gif.py::TestFileGif::test_palette_save_ImagePalette Tests/test_file_gif.py::TestFileGif::test_palette_save_L Tests/test_file_gif.py::TestFileGif::test_palette_save_P Tests/test_file_gif.py::TestFileGif::test_rgb_transparency Tests/test_file_gif.py::TestFileGif::test_roundtrip Tests/test_file_gif.py::TestFileGif::test_roundtrip2 Tests/test_file_gif.py::TestFileGif::test_roundtrip_save_all Tests/test_file_gif.py::TestFileGif::test_sanity Tests/test_file_gif.py::TestFileGif::test_save_I Tests/test_file_gif.py::TestFileGif::test_save_dispose Tests/test_file_gif.py::TestFileGif::test_seek Tests/test_file_gif.py::TestFileGif::test_seek_info Tests/test_file_gif.py::TestFileGif::test_seek_rewind Tests/test_file_gif.py::TestFileGif::test_transparent_optimize Tests/test_file_gif.py::TestFileGif::test_unclosed_file Tests/test_file_gif.py::TestFileGif::test_version Tests/test_file_gif.py::TestFileGif::test_zero_comment_subblocks
src/PIL/GifImagePlugin.py
src/PIL/GifImagePlugin.py