美文网首页
ICON图标生成器

ICON图标生成器

作者: Cylee1989 | 来源:发表于2019-07-09 15:02 被阅读0次

在我们开发APP或Game时,经常会遇到要更新图标的情况,然而每次都让美术童鞋出很多尺寸的图是一件很麻烦的事。尤其是项目要多的话,需要出的图就更多了,这不是一件高效率的做事方式。

所以写了个Go脚本,通过传参的方式,只需美术同学出一张较大尺寸的原图,就可以随意导出任意想要尺寸的图标啦!

package main

import (
    "flag"
    "fmt"
    "image"
    "image/jpeg"
    "image/png"
    "os"
    "path"
    "strconv"

    "github.com/nfnt/resize"
)

var _Service *TService
var iconSizes = []int{48, 72, 96, 144}

// TService 服务
type TService struct {
    SavePath  string
    FileExt   string
    IconImage image.Image
}

func main() {
    inPath := flag.String("i", "", "The import icon path.")
    outPath := flag.String("o", "", "The export icon path.")
    flag.Parse()
    if *inPath == "" || *outPath == "" {
        fmt.Println("Please enter the correct parameters")
        return
    }

    err := _Service.initService(*inPath, *outPath)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    _Service.make()
}

func (service *TService) initService(inPath, outPath string) error {
    file, err := os.Open(inPath)
    if err != nil {
        return err
    }
    defer file.Close()

    _Service = &TService{}
    _Service.SavePath = outPath
    _Service.FileExt = path.Ext(inPath)
    switch _Service.FileExt {
    case ".png":
        img, err := png.Decode(file)
        if err != nil {
            return err
        }
        _Service.IconImage = img
        break
    case ".jpg":
        img, err := jpeg.Decode(file)
        if err != nil {
            return err
        }
        _Service.IconImage = img
        break
    }

    service.createSavePath(_Service.SavePath)
    return nil
}

func (service *TService) createSavePath(fileName string) {
    os.RemoveAll(fileName)
    if _, err := os.Stat(fileName); os.IsNotExist(err) {
        os.MkdirAll(fileName, os.ModePerm)
    }
}

func (service *TService) make() {
    for index := 0; index < len(iconSizes); index++ {
        num := strconv.Itoa(iconSizes[index])
        img := resize.Resize(uint(iconSizes[index]), 0, service.IconImage, resize.Lanczos3)
        out, err := os.Create(service.SavePath + "/" + num + service.FileExt)
        if err != nil {
            fmt.Println("Icon Make Failed: \n" + err.Error())
            return
        }
        defer out.Close()
        png.Encode(out, img)
    }
    fmt.Println("Icon Make Success!")
}

相关文章

  • 视觉设计资源大收集

    文章转自极分享 更多精彩内容移步原文 阅读原文 目录 ICON图标 Fontello:图标字体生成器 The No...

  • ICON图标生成器

    在我们开发APP或Game时,经常会遇到要更新图标的情况,然而每次都让美术童鞋出很多尺寸的图是一件很麻烦的事。尤其...

  • 移动端图标生成工具

    移动端设置Icon时, 总是要麻烦美工切很多尺尺的图标,特麻烦。现有一款在线图标生成器,支持 亲测,特好用的!

  • 素材网站

    图标设计 图标学习方法 绘制功能性图标 系统学习功能图标 icon尺寸 icon规范 icon画法 金刚区设计规范...

  • 微信小程序(五)基础内容组件

    基础内容组件的使用场景 icon图标组件 (1) icon图标组件: icon组件:是小程序提供的图标组件。借助i...

  • ios打包icon和启动图标设置

    icon的设置 icon图标命名 启动图标的设置 启动图片的命名

  • 微信小程序组件icon

    icon:图标

  • Icon搜索与下载

    一、简介 icon是一种图标格式,用于系统图标、软件图标等,这种图标扩展名为*.icon、*.ico。常见的软件...

  • 前端小技术 二

    网站图标icon

  • UIApplicationShortcutItem 3DTouc

    // 创建标签的ICON图标。UIApplicationShortcutIcon *icon = [UIAppli...

网友评论

      本文标题:ICON图标生成器

      本文链接:https://www.haomeiwen.com/subject/ucmxkctx.html