Created
November 30, 2018 05:45
-
-
Save ylxdzsw/e4af41a8e8882a452be3364c5b7d5546 to your computer and use it in GitHub Desktop.
pack several .png files into an .ico flie in Julia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pack_ico(io::IO, pngs::Bytes...) | |
# all values are in little endian | |
# header | |
write(io, 0x0000) # reserved to be 0 | |
write(io, 0x0001) # 1 for .ico, 2 for .cur | |
write(io, length(pngs) % UInt16) # number of images | |
# image directory | |
c = 6 + 16length(pngs) # offsets of current image, initial value is the header length | |
for png in pngs | |
write(io, png[20], png[24]) # width, height, big-endian | |
write(io, 0x0000) # color platte and reserved | |
write(io, 0x0001) # color planes | |
write(io, 0x0020) # bits per pixel | |
write(io, length(png) % UInt32) # size | |
write(io, c % UInt32) | |
c += length(png) | |
end | |
# content | |
for png in pngs | |
write(io, png) | |
end | |
end | |
pack_ico(pngs::Bytes...) = let io = IOBuffer() | |
pack_ico(io, pngs) | |
take!(io) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment