Giter Site home page Giter Site logo

jackmordaunt / icns Goto Github PK

View Code? Open in Web Editor NEW
75.0 3.0 5.0 198 KB

Easily create .icns files (Mac Icons) with this Go library or the included CLI.

License: MIT License

Go 99.06% Shell 0.94%
icns macos golang go iconset iconutil osx retina library cli icons

icns's Introduction

icns

Easily convert .jpg and .png to .icns with the command line tool icnsify, or use the library to convert from any image.Image to .icns.

go get github.com/jackmordaunt/icns

icns files allow for high resolution icons to make your apps look sexy. The most common ways to generate icns files are:

  1. iconutil, which is a Mac native cli utility.
  2. ImageMagick which adds a large dependency to your project for such a simple use case.

With this library you can use pure Go to create icns files from any source image, given that you can decode it into an image.Image, without any heavyweight dependencies or subprocessing required. You can also use it to create icns files on windows and linux (thanks Go).

A small CLI app icnsify is provided allowing you to create icns files using this library from the command line. It supports piping, which is something iconutil does not do, making it substantially easier to wrap or chuck into a shell pipeline.

Note: All icons within the icns are sized for high dpi retina screens, using the appropriate icns OSTypes.

GUI

preview is a gui for displaying icns files cross-platform.

Go Tool

go install github.com/jackmordaunt/icns/cmd/preview@latest

Clone

git clone https://github.com/jackmordaunt/icns
cd icns/cmd/preview && go install .

Note: Gio cannot be cross-compiled right now, so there are no preview builds in releases. Note: preview has it's own go.mod and therefore is versioned independently (unversioned).

preview

Command Line

Go Tool

go install github.com/jackmordaunt/icns/cmd/icnsify@latest
scoop bucket add extras # Ensure bucket is added first
scoop install icnsify

Or from my personal bucket:

scoop bucket add jackmordaunt https://github.com/jackmordaunt/scoop-bucket 
scoop install jackmordaunt/icns # Name is defaulted to repo name. 
winget install icnsify
brew tap jackmordaunt/homebrew-tap # Ensure tap is added first.
brew install icnsify

Clone

git clone https://github.com/jackmordaunt/icns
cd icns && go install ./cmd/icnsify

Pipe it

cat icon.png | icnsify > icon.icns

cat icon.icns | icnsify > icon.png

Standard

icnsify -i icon.png -o icon.icns

icnsify -i icon.icns -o icon.png

Library

go get github.com/jackmordaunt/icns/v3

func main() {
        pngf, err := os.Open("path/to/icon.png")
        if err != nil {
                log.Fatalf("opening source image: %v", err)
        }
        defer pngf.Close()
        srcImg, _, err := image.Decode(pngf)
        if err != nil {
                log.Fatalf("decoding source image: %v", err)
        }
        dest, err := os.Create("path/to/icon.icns")
        if err != nil {
                log.Fatalf("opening destination file: %v", err)
        }
        defer dest.Close()
        if err := icns.Encode(dest, srcImg); err != nil {
                log.Fatalf("encoding icns: %v", err)
        }
}

Roadmap

  • Encoder: image.Image -> .icns
  • Command Line Interface
    • Encoding
    • Pipe support
    • Decoding
  • Implement Decoder: .icns -> image.Image
  • Symmetric test: decode(encode(img)) == img

Coffee

If this software is useful to you, consider buying me a coffee!

https://liberapay.com/JackMordaunt

icns's People

Contributors

andydotxyz avatar d4x1 avatar dependabot[bot] avatar jacalz avatar jackmordaunt avatar sitiom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

icns's Issues

Zip binaries for Winget

Hi, this is a great project, and I plan to add this to Winget. However, Winget only supports installing from zip archives at the moment. Can you also please release alternative zip binaries in the releases? Thanks!

Moving the ui to a different repo?

Hi. Thanks for creating this library. It is very useful for the packaging that we do in https://github.com/fyne-io/fyne.

The recent versions seem to have a ui and depend on gioui for it. This unfortunately means that anyone importing this will get gioui and its dependencies added to their go.sum as well. Given that we are a user interface too, this is something that we would like to avoid. Is moving the ui something that you could consider?

homebrew

Any chance to have this also released on homebrew?

latest tag fails for build ?

Hey @JackMordaunt

Not sure as I did not dig into this, but v2.2.7 tag works for one cmd but not the other...

# works...
go install github.com/jackmordaunt/icns/v2/cmd/[email protected]

# works...
go install github.com/jackmordaunt/icns/cmd/preview@latest

# fails...
go install github.com/jackmordaunt/icns/cmd/[email protected]
go: github.com/jackmordaunt/icns/cmd/[email protected]: github.com/jackmordaunt/icns/cmd/[email protected]: reading https://proxy.golang.org/github.com/jackmordaunt/icns/cmd/preview/@v/v2.2.7.info: 404 Not Found
        server response: not found: github.com/jackmordaunt/icns/cmd/[email protected]: invalid version: unknown revision cmd/preview/v2.2.7

Creates invalid (?) icns files

I was trying to use this tool on linux to convert a png to icns file. It seemed to work and produced some file, but I was unable to actually open that file with anything.

Even image magick gives up on this with the folliwing output:

$ magick convert source-file.icns converted-file.png 
convert: no decode delegate for this image format `ICNS' @ error/constitute.c/ReadImage/562.
convert: no images defined `converted-file.png' @ error/convert.c/ConvertImageCommand/3282.

ImageMagick creates a valid icns file from the same source png.

Dropbox icns file: no icons found

Hi

I want to decode the icons of a few apps. Several work well, but some do not. Like the icon of Dropbox which is stored at /Applications/Dropbox.app/Contents/Resources/AppIcon.icns. The files exists and opens in Preview without problems, showing the Dropbox icon in several sizes. However, this library reports the error no icons found?

integration into gogio

Hey @andydotxyz

am working on it here: https://github.com/gedw99/gio-sign/

gogio and icns looks like it can work together. will make building cross platform.

The intent is that in CI, we can do a gio build and sign cross any platform to build any platform is the intent.

the rust signer can do this apparently. the signing from anywhere i mean.

first thing though is to get icns working with gogio and then get upstream.
we can integration the preview tool too after that if you want.

Homebrew instructions are outdated

$ brew tap jackmordaunt/homebrew-icnsify                         
==> Tapping jackmordaunt/icnsify
Cloning into '/opt/homebrew/Library/Taps/jackmordaunt/homebrew-icnsify'...
remote: Repository not found.
fatal: repository 'https://github.com/jackmordaunt/homebrew-icnsify/' not found
Error: Failure while executing; `git clone https://github.com/jackmordaunt/homebrew-icnsify /opt/homebrew/Library/Taps/jackmordaunt/homebrew-icnsify --origin=origin --template= --config core.fsmonitor=false` exited with 128.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.