diff --git a/src/PIL/IcnsImagePlugin.py b/src/PIL/IcnsImagePlugin.py index 930131a68..0a02658f1 100644 --- a/src/PIL/IcnsImagePlugin.py +++ b/src/PIL/IcnsImagePlugin.py @@ -300,13 +300,12 @@ class IcnsImageFile(ImageFile.ImageFile): self.load_end() -def _to_int(s): - b = s.encode("ascii") +def _to_int(b): return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3] -MAGIC = _to_int("icns") -TOC = "TOC " +MAGIC = b"icns" +TOC = b"TOC " def _save(im, fp, filename): @@ -319,7 +318,7 @@ def _save(im, fp, filename): # Size sizes = [128, 256, 512, 32, 64, 256, 512, 1024] - size_str = ["ic07", "ic08", "ic09", "ic11", "ic12", "ic13", "ic14", "ic10"] + size_str = [b"ic07", b"ic08", b"ic09", b"ic11", b"ic12", b"ic13", b"ic14", b"ic10"] file_size = 0 entries = [] provided_images = {im.width: im for im in im.encoderinfo.get("append_images", [])} @@ -331,11 +330,15 @@ def _save(im, fp, filename): temp = temp_sizes[s] file_size += len(temp.getvalue()) entries.append( - {"type": size_str[index], "size": len(temp.getvalue()), "stream": temp} + { + "type": _to_int(size_str[index]), + "size": len(temp.getvalue()), + "stream": temp, + } ) # Header - fp.write(struct.pack("