code: def test_png(test_images, tmp_path):
      fnamebase = str(tmp_path / "test")
  
      for isfloat in (False, True):
          for crop in (0, 1, 2):
              for colors in (0, 1, 3, 4):
                  fname = fnamebase + "%i.%i.%i.png" % (
                      isfloat,
                      crop,
                      colors,
                  )
                  rim = get_ref_im(colors, crop, isfloat)
                  imageio.imsave(fname, rim, format="PNG-PIL")
                  im = imageio.imread(fname, format="PNG-PIL")
                  mul = 255 if isfloat else 1
                  assert_close(rim * mul, im, 0.1)  # lossless
  
      # Parameters
      im = imageio.imread(
          test_images / "chelsea.png",
          ignoregamma=True,
          format="PNG-PIL",
      )
      imageio.imsave(fnamebase + ".png", im, interlaced=True)
  
      # Parameter fail
      with pytest.raises(TypeError):
          imageio.imread(
              test_images / "chelsea.png",
              notavalidk=True,
              format="PNG-PIL",
          )
  
      with pytest.raises(TypeError):
          imageio.imsave(
              fnamebase + ".png", im, notavalidk=True, format="PNG-PIL"
          )
  
      # Compression
      imageio.imsave(
          fnamebase + "1.png", im, compression=0, format="PNG-PIL"
      )
      imageio.imsave(
          fnamebase + "2.png", im, compression=9, format="PNG-PIL"
      )
      s1 = os.stat(fnamebase + "1.png").st_size
      s2 = os.stat(fnamebase + "2.png").st_size
      assert s2 < s1
      # Fail
      with pytest.raises(ValueError):
          imageio.imsave(
              fnamebase + ".png", im, compression=12, format="PNG-PIL"
          )
  
      # Quantize
      imageio.imsave(
          fnamebase + "1.png", im, quantize=256, format="PNG-PIL"
      )
      imageio.imsave(
          fnamebase + "2.png", im, quantize=4, format="PNG-PIL"
      )
  
      im = imageio.imread(
          fnamebase + "2.png", format="PNG-PIL"
      )  # touch palette read code
      s1 = os.stat(fnamebase + "1.png").st_size
      s2 = os.stat(fnamebase + "2.png").st_size
      assert s1 > s2
      # Fail
      fname = fnamebase + "1.png"
      with pytest.raises(ValueError):
          imageio.imsave(
              fname, im[:, :, :3], quantize=300, format="PNG-PIL"
          )
  
      with pytest.raises(ValueError):
          imageio.imsave(
              fname, im[:, :, 0], quantize=100, format="PNG-PIL"
          )
  
      # 16b bit images
      im = imageio.imread(test_images / "chelsea.png")[:, :, 0]
      imageio.imsave(
          fnamebase + "1.png", im.astype("uint16") * 2, format="PNG-PIL"
      )
      imageio.imsave(fnamebase + "2.png", im, format="PNG-PIL")
      s1 = os.stat(fnamebase + "1.png").st_size
      s2 = os.stat(fnamebase + "2.png").st_size
      assert s2 < s1
      im2 = imageio.imread(fnamebase + "1.png", format="PNG-PIL")
      assert im2.dtype == np.uint16
  
      # issue #352 - prevent low-luma uint16 truncation to uint8
      arr = np.full(
          (32, 32), 255, dtype=np.uint16
      )  # values within range of uint8
      preferences_dtypes = [
          [{}, np.uint8],
          [{"prefer_uint8": True}, np.uint8],
          [{"prefer_uint8": False}, np.uint16],
      ]
      for preference, dtype in preferences_dtypes:
          imageio.imwrite(
              fnamebase + ".png", arr, **preference, format="PNG-PIL"
          )
          im = imageio.imread(fnamebase + ".png", format="PNG-PIL")
          assert im.dtype == dtype
  
imports: import os
  import sys
  import io
  from zipfile import ZipFile
  import numpy
  import pytest
  import imageio
  from imageio import core
  from conftest import deprecated_test
label_desc: Use image node_id 5 for calling a global function with example usage: test_png(test_images, tmp_path) without return types