J-Siu/go-png2ico

go module and command line for PNG to ICO. ICO use PNG format for storage.

30

stars

60

commits

Go

primary language

Jul 24, 2026

updated

go
ico
icon
png

README

go-png2ico

Command line tool to create ICO(favicon) from PNG images.

Table Of Content

Install

Go install

go install github.com/J-Siu/go-png2ico/v2@latest

Download

Usage

go-png2ico -h
Build ICO file from PNGs

Usage:
  go-png2ico <PNG file> <PNG file> ... <ICO file> [flags]

Flags:
  -d, --debug     Enable debug
  -h, --help      help for go-png2ico
  -v, --verbose   Verbose
      --version   version for go-png2ico

What It Does

  • Create ICO file from PNG files
  • Minimum overhead(16byte) per PNG added
  • Only use PNG format in ICO
  • PNG header check for input files
  • PNG header check for output(destination/target) file to avoid overwriting a PNG file

What It Does Not

  • Check file extension
  • Convert PNG to BMP inside ICO
  • Transform PNG

Limitation

  • ICO file always create from scratch or overwrite

    (no append to nor replace existing icon in ICO file)

  • PNG into ICO only, other format/conversion not supported

Module

Install

go get github.com/J-Siu/go-png2ico/v2

Import

import "github.com/J-Siu/go-png2ico/v2/p2i"

Struct

ICO

type ICO struct {
  Debug         bool
  Err           error
  Initialized   bool
  MyType        string
  OnErrContinue bool

  File       string   `json:"File"`
  FileHandle *os.File `json:"FileHandle"`
  pngCount   uint16
  pngs       []*PNG
}
func (t *ICO) New(file string, debug bool) *ICO
func (t *ICO) PngAdd(png *PNG) *ICO
func (t *ICO) PngAddFile(file string) *ICO
func (t *ICO) PngCount() uint16
func (t *ICO) Write() *ICO

PNG

type PNG struct {
  Debug         bool
  Err           error
  Initialized   bool
  MyType        string
  OnErrContinue bool

  Buf    []byte `json:"Buf"`
  Depth  uint16 `json:"Depth"` // bit/pixel
  File   string `json:"File"`  // filename
  Height uint8  `json:"Height"`
  Size   uint32 `json:"Size"`
  Width  uint8  `json:"Width"`
}
func (t *PNG) New(debug bool) *PNG
func (t *PNG) IsPNG() bool
func (t *PNG) Read(file string) *PNG

ICO Usage

// icoFile = ICO file to be created/overwritten
// ICO object must be initialized with New()
ico := new(p2i.ICO).New(icoFile)

// pngFile = PNG file path
// this steps can be repeated multiple times
ico.AddPngFile(pngFile)

// Create ICO file with all PNG loaded
ico.WriteAll()

Full example in root.go

Releases

https://github.com/J-Siu/go-png2ico/releases

Repository

Contributors

License

The MIT License

Copyright (c) 2025 John Siu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors

J-Siu

59 commits

devhindo

1 commits

J-Siu/go-png2ico

go module and command line for PNG to ICO. ICO use PNG format for storage.

30

stars

60

commits

Go

primary language

Jul 24, 2026

updated

go
ico
icon
png

README

go-png2ico

Command line tool to create ICO(favicon) from PNG images.

Table Of Content

Install

Go install

go install github.com/J-Siu/go-png2ico/v2@latest

Download

Usage

go-png2ico -h
Build ICO file from PNGs

Usage:
  go-png2ico <PNG file> <PNG file> ... <ICO file> [flags]

Flags:
  -d, --debug     Enable debug
  -h, --help      help for go-png2ico
  -v, --verbose   Verbose
      --version   version for go-png2ico

What It Does

  • Create ICO file from PNG files
  • Minimum overhead(16byte) per PNG added
  • Only use PNG format in ICO
  • PNG header check for input files
  • PNG header check for output(destination/target) file to avoid overwriting a PNG file

What It Does Not

  • Check file extension
  • Convert PNG to BMP inside ICO
  • Transform PNG

Limitation

  • ICO file always create from scratch or overwrite

    (no append to nor replace existing icon in ICO file)

  • PNG into ICO only, other format/conversion not supported

Module

Install

go get github.com/J-Siu/go-png2ico/v2

Import

import "github.com/J-Siu/go-png2ico/v2/p2i"

Struct

ICO

type ICO struct {
  Debug         bool
  Err           error
  Initialized   bool
  MyType        string
  OnErrContinue bool

  File       string   `json:"File"`
  FileHandle *os.File `json:"FileHandle"`
  pngCount   uint16
  pngs       []*PNG
}
func (t *ICO) New(file string, debug bool) *ICO
func (t *ICO) PngAdd(png *PNG) *ICO
func (t *ICO) PngAddFile(file string) *ICO
func (t *ICO) PngCount() uint16
func (t *ICO) Write() *ICO

PNG

type PNG struct {
  Debug         bool
  Err           error
  Initialized   bool
  MyType        string
  OnErrContinue bool

  Buf    []byte `json:"Buf"`
  Depth  uint16 `json:"Depth"` // bit/pixel
  File   string `json:"File"`  // filename
  Height uint8  `json:"Height"`
  Size   uint32 `json:"Size"`
  Width  uint8  `json:"Width"`
}
func (t *PNG) New(debug bool) *PNG
func (t *PNG) IsPNG() bool
func (t *PNG) Read(file string) *PNG

ICO Usage

// icoFile = ICO file to be created/overwritten
// ICO object must be initialized with New()
ico := new(p2i.ICO).New(icoFile)

// pngFile = PNG file path
// this steps can be repeated multiple times
ico.AddPngFile(pngFile)

// Create ICO file with all PNG loaded
ico.WriteAll()

Full example in root.go

Releases

https://github.com/J-Siu/go-png2ico/releases

Repository

Contributors

License

The MIT License

Copyright (c) 2025 John Siu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors

J-Siu

59 commits

devhindo

1 commits

Languages

Go

100.0%