Skip to content

Instantly share code, notes, and snippets.

@ylxdzsw
Created November 30, 2018 05:45
Show Gist options
  • Save ylxdzsw/e4af41a8e8882a452be3364c5b7d5546 to your computer and use it in GitHub Desktop.
Save ylxdzsw/e4af41a8e8882a452be3364c5b7d5546 to your computer and use it in GitHub Desktop.
pack several .png files into an .ico flie in Julia.
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