iseahound / ImagePut

A core library for images in AutoHotkey. Supports AutoHotkey v1 and v2.
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=76633
MIT License
116 stars 24 forks source link

can gdip save as ".ico"? #21

Open hyaray opened 1 year ago

hyaray commented 1 year ago

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

iseahound commented 1 year ago

Can you provide some working GDI+ code? I will investigate.

On Sat, Nov 5, 2022 at 11:30 hyaray @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/iseahound/ImagePut/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACKTTVBSRQ3OEM4RLHGZZBLWGZ4SNANCNFSM6AAAAAARX7FGAA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hyaray commented 1 year ago

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 commented 1 year ago

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

iseahound commented 1 year ago

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:

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.