├── .github └── workflows │ └── go.yml ├── .gitignore ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── main.go └── screenshots └── code-sample.png /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | name: Build 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Set up Go 1.12 12 | uses: actions/setup-go@v1 13 | with: 14 | go-version: 1.12 15 | id: go 16 | 17 | - name: Check out code into the Go module directory 18 | uses: actions/checkout@v1 19 | 20 | - name: cross compile - darwin-amd64 21 | run: env GOOS=darwin GOARCH=amd64 go build -o dist/ionic-resource-generator-osx -v . 22 | 23 | - name: cross compile - linux-amd64 24 | run: env GOOS=linux GOARCH=amd64 go build -o dist/ionic-resource-generator-linux -v . 25 | 26 | - name: cross compile - windows-amd64 27 | run: env GOOS=windows GOARCH=amd64 go build -o dist/ionic-resource-generator-windows.exe -v . 28 | 29 | - name: Upload to release 30 | uses: fnkr/github-action-ghr@v1 31 | if: startsWith(github.ref, 'refs/tags/') 32 | env: 33 | GHR_COMPRESS: xz 34 | GHR_PATH: dist/ 35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | .vscode -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Harsh Zalavadiya 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ionic-resource-generator 2 | whenever you run ionic resources basically it uploads your icon and splash screen and resizes and then downloads it, It takes lots of time plus if you are running any build system that is offline or behind proxy then configuring it is just pain 3 | 4 | thats why ionic-resource-generater was born! 5 | 6 | > Update: Now ionic already has offline resources utility https://ionicframework.com/docs/cli/commands/cordova-resources 7 | 8 | ## Features 9 | - Works Offline ⚡ 10 | - Lightning Fast 💫 11 | - No Dependency 😇 12 | - Saves your internet bandwith 💰 13 | - Cross Platform 🐿️ 14 | 15 | ## How to Use 16 | - Download platform specific binary release from [here](https://github.com/harshzalavadiya/ionic-resource-generator/releases) 17 | - Copy executable to resources folder 18 | - Update your `icon.png` and `splash.png` in root of resources folder 19 | - open terminal in resource folder and run `ionic-resource-generator generate` 🎉 20 | 21 | ![code](https://github.com/harshzalavadiya/ionic-resource-generator/blob/master/screenshots/code-sample.png?raw=true) 22 | 23 | Thank you all [contributers](https://github.com/harshzalavadiya/ionic-resource-generator/graphs/contributors) Feel free to raise issues or make PRs 24 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/harshzalavadiya/tmp-irg 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/disintegration/gift v1.2.1 7 | github.com/urfave/cli v1.22.1 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= 3 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 4 | github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc= 5 | github.com/disintegration/gift v1.2.1/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dUg3/RlKGr4HI= 6 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 7 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 8 | github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= 9 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 10 | github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= 11 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 12 | github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= 13 | github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 14 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 15 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 16 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "image" 6 | "image/png" 7 | "io/ioutil" 8 | "log" 9 | "os" 10 | "path/filepath" 11 | "strings" 12 | 13 | "github.com/disintegration/gift" 14 | "github.com/urfave/cli" 15 | ) 16 | 17 | // Declarations 18 | const imgIcon = "icon.png" 19 | const imgSplash = "splash.png" 20 | const splashPath = string(os.PathSeparator) + "splash" + string(os.PathSeparator) 21 | 22 | func main() { 23 | //Defining Version 24 | cli.VersionFlag = cli.BoolFlag{ 25 | Name: "version, v", 26 | Usage: "prints utility version", 27 | } 28 | 29 | // Magic happens here 30 | app := cli.NewApp() 31 | app.Name = "generate, g" 32 | app.Version = "1.0.0" 33 | app.Usage = "generate ionic icons and splash screens!" 34 | app.Action = func(c *cli.Context) error { 35 | for _, platform := range Dirs(".") { 36 | GenerateResources(GetImages(platform)) 37 | } 38 | return nil 39 | } 40 | 41 | err := app.Run(os.Args) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | 46 | } 47 | 48 | func Exists(name string) bool { 49 | if _, err := os.Stat(name); err != nil { 50 | if os.IsNotExist(err) { 51 | return false 52 | } 53 | } 54 | return true 55 | } 56 | 57 | func Dirs(path string) []string { 58 | var platforms []string 59 | files, err := ioutil.ReadDir(path) 60 | if err != nil { 61 | log.Fatal(err) 62 | } 63 | 64 | for _, file := range files { 65 | if IsDir(file.Name()) { 66 | platforms = append(platforms, file.Name()) 67 | } 68 | } 69 | 70 | return platforms 71 | } 72 | 73 | func IsDir(path string) bool { 74 | fileInfo, _ := os.Stat(path) 75 | return fileInfo.IsDir() 76 | } 77 | 78 | func GenerateResources(pngs []string) { 79 | for _, p := range pngs { 80 | width, height := GetImageDimension(p) 81 | src := LoadImage(imgIcon) 82 | if strings.Contains(p, splashPath) { 83 | src = LoadImage(imgSplash) 84 | } 85 | filters := map[string]gift.Filter{ 86 | "crop_to_size": gift.ResizeToFill(width, height, gift.LanczosResampling, gift.CenterAnchor), 87 | } 88 | for _, filter := range filters { 89 | g := gift.New(filter) 90 | dst := image.NewNRGBA(g.Bounds(src.Bounds())) 91 | g.Draw(dst, src) 92 | SaveImage(p, dst) 93 | } 94 | fmt.Printf("✓ Updated — %s (%dx%d)\n", p, width, height) 95 | } 96 | } 97 | 98 | func GetImages(root string) []string { 99 | var pngs []string 100 | err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 101 | if filepath.Ext(path) == ".png" { 102 | pngs = append(pngs, path) 103 | } 104 | return nil 105 | }) 106 | if err != nil { 107 | panic(err) 108 | } 109 | return pngs 110 | } 111 | 112 | func GetImageDimension(path string) (int, int) { 113 | file, err := os.Open(path) 114 | if err != nil { 115 | fmt.Fprintf(os.Stderr, "%v\n", err) 116 | } 117 | 118 | image, _, err := image.DecodeConfig(file) 119 | if err != nil { 120 | fmt.Fprintf(os.Stderr, "%s: %v\n", path, err) 121 | } 122 | return image.Width, image.Height 123 | } 124 | 125 | func LoadImage(filename string) image.Image { 126 | f, err := os.Open(filename) 127 | if err != nil { 128 | log.Fatalf("os.Open failed: %v", err) 129 | } 130 | img, _, err := image.Decode(f) 131 | if err != nil { 132 | log.Fatalf("image.Decode failed: %v", err) 133 | } 134 | return img 135 | } 136 | 137 | func SaveImage(filename string, img image.Image) { 138 | f, err := os.Create(filename) 139 | if err != nil { 140 | log.Fatalf("os.Create failed: %v", err) 141 | } 142 | err = png.Encode(f, img) 143 | if err != nil { 144 | log.Fatalf("png.Encode failed: %v", err) 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /screenshots/code-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hc-oss/ionic-resource-generator/360d4a641860aeea5d51d56bea553e4e1076f613/screenshots/code-sample.png --------------------------------------------------------------------------------