Skip to content
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

can gdip save as ".ico"? #21

Open
hyaray opened this issue Nov 5, 2022 · 4 comments
Open

can gdip save as ".ico"? #21

hyaray opened this issue Nov 5, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@hyaray
Copy link

hyaray commented Nov 5, 2022

GdipSaveImageToFile seems not support the filetype...
is there any other method to do this?
thanks very much!!!

@iseahound
Copy link
Owner

iseahound commented Nov 5, 2022 via email

@hyaray
Copy link
Author

hyaray commented Nov 5, 2022

sorry, I think GdipSaveImageToFile may not able to do this.
I'm tring python instead.

import os,sys
from PIL import Image

fp0 = r"c:\1.png"
fp1 = os.path.splitext(fp0)[0] + ".ico"
size = (16,16)
im = Image.open(fp0).resize(size)
im.save(fp1)

@iseahound
Copy link
Owner

Depending on your use case, you can actually change the *.png extension to *.ico, and it should work.

@iseahound
Copy link
Owner

Just a little update: This needs some more investigation. In general, an *.ico file contains about 9 resolutions. These are mostly encoded as a bitmap and stored sequentially.

So something like generating:

  • 16 x 16
  • 64 * 64
  • 256 x 256
    could be done automatically. I should also allow passing an array of sizes as well.

Here's the interesting part: An ICO file can host embedded PNGs. Since the IconDirEntry header uses a UCHAR for storage of width and height, the maximum width and height is 256 x 256 which is the maximum value for an unsigned char (one byte). But it will recognize one special PNG with an icon size of 256 x 256 and will use the width and height embedded inside the PNG instead. So theoretically, the size limit inside an ICO can be bigger than 256 x 256.

@iseahound iseahound added the enhancement New feature or request label Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants