New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specific ICO file being shifted vertically #3403
Comments
I presume that you have no connection to the site's favicon, and so can't give us permission to use the image as part of our test suite. |
That's right, I'm not associated. Lauren seems like a pretty contactable person though, so you might be able to ask for his permission if it would make a good test: https://www.vortex.com/lauren |
A potential solution to this is to use the "offset" and "size" from Read AND image from end
diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py
index 5634bf8e9..65c73cdb3 100644
--- a/src/PIL/IcoImagePlugin.py
+++ b/src/PIL/IcoImagePlugin.py
@@ -189,15 +189,8 @@ class IcoFile:
d, e, o, a = im.tile[0]
im.tile[0] = d, (0, 0) + im.size, o, a
- # figure out where AND mask image starts
mode = a[0]
- bpp = 8
- for k, v in BmpImagePlugin.BIT2MODE.items():
- if mode == v[1]:
- bpp = k
- break
-
- if 32 == bpp:
+ if mode == BmpImagePlugin.BIT2MODE[32][1]:
# 32-bit color depth icon image allows semitransparent areas
# PIL's DIB format ignores transparency bits, recover them.
# The DIB is packed in BGRX byte order where X is the alpha
@@ -226,8 +219,8 @@ class IcoFile:
# the total mask data is
# padded row size * height / bits per char
- and_mask_offset = o + int(im.size[0] * im.size[1] * (bpp / 8.0))
total_bytes = int((w * im.size[1]) / 8)
+ and_mask_offset = header["offset"] + header["size"] - total_bytes
self.buf.seek(and_mask_offset)
mask_data = self.buf.read(total_bytes) I thought it might be because this is a 1 bit ICO, but comparing it with https://github.com/lordelph/icofileloader/blob/master/tests/assets/1bit-32px-sample.ico, that isn't the case. Maybe the encoder just decided to throw some padding in the middle? |
@laurenweinstein1 hi. In the above posts, a user has found that your site's favicon is an unusual image. Are you happy if we take that image, include it in our test suite, and distribute it under Pillow's license? |
Hi. Interesting that you're seeing that behavior. However, I'd prefer that this favicon not be included in the test suite and not be distributed under Pillow's license. Thanks. -L |
@laurenweinstein1 Sure thing! Do you happen to remember how the favicon was created? |
I was thinking about that. I probably designed it around 2003 when I started my blog. I remember creating it and tweaking it in a bitmap editor but unfortunately today I have no idea which one. |
I've created PR #5667 to resolve this. |
What did you do?
Downloaded this ICO file and used PIL to resave as a PNG: https://lauren.vortex.com/favicon.ico
What did you expect to happen?
PNG result should look the same as the icon does in the browser (and other applications) - an L with a black square around it.
What actually happened?
PNG result seems to have been shifted vertically, with the top part of the image lost:
What are your OS, Python and Pillow versions?
Code to reproduce
The text was updated successfully, but these errors were encountered: