Github 精选 #4 | 让 Github 帮你自动压缩图片!

大家好,我是路遥,每周五给你推荐一个泛移动端优质 Github 项目。

今天的主角是 Imgbot, 自动帮你压缩 Github 仓库中的图片资源。

Author github.com/imgbot
Url github.com/imgbot/Imgb…
Language C#/HTML/Vue/Less
Star 874
Fork 212
Issue 26 Open/147 Closed
Commits 1003
Last Update Mar 7, 2022
License MIT

以上数据截止至 2022 年 3 月 11 日。

使用

Imagebot 是一个开源的 Github App,提供图片资源的无损压缩,它具备以下特性:

  1. 无损压缩
  2. 开源实现
  3. 基于 PR
  4. 利用 Github app 提供权限
  5. 可计划的执行任务
  6. 可配置忽略文件/文件夹
  7. 更强的压缩选项
  8. 支持 public/private 仓库
  9. 对于开源项目免费

简单的说,Imagebot 可以自动帮你压缩仓库中的图片资源,并给你提交 PR。

你可以 Github 的应用市场找到它,地址如下:

github.com/marketplace…

安装之后进行简单的配置,选择你需要应用的仓库,我用我的 demo 项目进行了测试:

image-20220311115458495.png

A few hours later ,你就会收到一个来自 imgbot 的 PR ,如下图所示:

image-20220311115929322.png

Beep boop,帮助我减小了 25% 的图片资源。它以表格的形式,把图片压缩的详细数据展示了出来。

配置

Imgbot 也提供了个性化配置项,在仓库根目录创建 .imgbotconfig 文件,格式为 json 。下面是一个示例:

{
    "schedule": "daily", // daily|weekly|monthly
    "ignoredFiles": [
        "*.jpg",                   // ignore by extension
        "image1.png",              // ignore by filename
        "public/special_images/*", // ignore by folderpath
    ],
    "aggressiveCompression": "true", // true|false
    "compressWiki": "true", // true|false
    "minKBReduced": 500, // delay new prs until size reduction meets this threshold (default to 10)
    "prTitle" : "Your own pr title",        
    "prBody" : " Text before optimization ratio {optimization_ratio} Text after optimization ratio 
                 Text before optimization details {optimization_details} Text after optimization details",
}
复制代码

schedule

检测周期,默认情况下,只有当有图片需要压缩的时候才会提 PR。你也可以设置为 dailyweeklymonthly

ignoredFiles

配置忽略文件。格式如下:

"ignoredFiles": [
    "*.jpeg" // 根据后缀过滤
]
复制代码

提供了多种过滤方式:

"public/special_images/*" // 忽略指定文件夹
"special-image1.png" // 忽略单个文件
"**/test_images/**" // 忽略嵌套文件夹
"path/to/prefix*" // 根据正则忽略
复制代码

aggressiveCompression

{
    "aggressiveCompression": false
}
复制代码

默认值为 false ,表示无损压缩。true 表示有损压缩。

compressWiki

设置是否需要压缩 wiki 中的图片。

prTitle

PR 的标题。

prBody

PR 的内容。有默认内容,可以付费自定义。

{
    "prBody" : " Text before optimization ratio {optimization_ratio} Text after optimization ratio 
                 Text before optimization details {optimization_details} Text after optimization details",
}
复制代码

最后

相比较在打包过程中介入,进行图片压缩和替换,imgbot 的方案也不失为一种好方法。在日常开发工作之外,以 PR 的方式完美融合到 workflow 。

这一期的介绍就到这里了,我们下周五见。

如果你有好的项目推荐,欢迎向我投稿 ,wx: bingxinshuo_ 。

Guess you like

Origin juejin.im/post/7075863383056547871