Skip to content

Commit

Permalink
Merge pull request #1232 from wiredfool/ico-bigendian
Browse files Browse the repository at this point in the history
Ico files are little endian, ref #1204
  • Loading branch information
hugovk committed May 29, 2015
2 parents 4aba749 + 93461e6 commit 022cebd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions PIL/IcoImagePlugin.py
Expand Up @@ -48,7 +48,7 @@ def _save(im, fp, filename):
width, height = im.size
filter(lambda x: False if (x[0] > width or x[1] > height or
x[0] > 255 or x[1] > 255) else True, sizes)
fp.write(struct.pack("H", len(sizes))) # idCount(2)
fp.write(struct.pack("<H", len(sizes))) # idCount(2)
offset = fp.tell() + len(sizes)*16
for size in sizes:
width, height = size
Expand All @@ -57,7 +57,7 @@ def _save(im, fp, filename):
fp.write(b"\0") # bColorCount(1)
fp.write(b"\0") # bReserved(1)
fp.write(b"\0\0") # wPlanes(2)
fp.write(struct.pack("H", 32)) # wBitCount(2)
fp.write(struct.pack("<H", 32)) # wBitCount(2)

image_io = BytesIO()
tmp = im.copy()
Expand All @@ -66,8 +66,8 @@ def _save(im, fp, filename):
image_io.seek(0)
image_bytes = image_io.read()
bytes_len = len(image_bytes)
fp.write(struct.pack("I", bytes_len)) # dwBytesInRes(4)
fp.write(struct.pack("I", offset)) # dwImageOffset(4)
fp.write(struct.pack("<I", bytes_len)) # dwBytesInRes(4)
fp.write(struct.pack("<I", offset)) # dwImageOffset(4)
current = fp.tell()
fp.seek(offset)
fp.write(image_bytes)
Expand Down

0 comments on commit 022cebd

Please sign in to comment.