Skip to content

J-Siu/go-png2ico

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-png2ico Paypal donate

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
  • ICO use PNG format for storage
  • Minimum overhead(16byte) per PNG added
  • PNG header check for input files
  • PNG header check for output file to avoid mistake

What It Does Not

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

Limitation

  • ICO file always created from scratch
  • Will overwrite existing ICO file
  • Will not append nor replace within existing 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 {
  basestruct.Base

  File       string   `json:"File"`
  FileHandle *os.File `json:"FileHandle"`
  pngCount   uint16
  pngs       []*PNG
}
func (t *ICO) New(file string) *ICO
func (t *ICO) PngCount() uint16
func (t *ICO) AddPng(png *PNG) *ICO
func (t *ICO) AddPngFile(file string) *ICO
func (t *ICO) WriteAll() *ICO
func (t *ICO) open() *ICO
func (t *ICO) write(b *[]byte) *ICO
func (t *ICO) iconDir(num uint16) *[]byte
func (t *ICO) iconDirEntry(pngIndex int) *[]byte

PNG

type PNG struct {
  basestruct.Base

  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"`
  isPNG  bool
}
func (t *PNG) New() *PNG
func (t *PNG) IsPNG() bool
func (t *PNG) Read(file string) *PNG
func (t *PNG) Check() *PNG
func (t *PNG) info()

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages