惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
Attack and Defense Labs
Attack and Defense Labs
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Full Disclosure
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
V2EX - 技术
V2EX - 技术
B
Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threatpost
小众软件
小众软件
T
The Blog of Author Tim Ferriss
Google Online Security Blog
Google Online Security Blog
MongoDB | Blog
MongoDB | Blog
T
Tenable Blog
P
Privacy International News Feed
S
Security @ Cisco Blogs
H
Heimdal Security Blog
大猫的无限游戏
大猫的无限游戏
B
Blog RSS Feed
H
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
有赞技术团队
有赞技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
Security Latest
Security Latest
S
Securelist
Cyberwarzone
Cyberwarzone
D
Docker
S
Schneier on Security
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
P
Privacy & Cybersecurity Law Blog
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research

mephisto.cc

修复rime-ice无法弹出候选框的问题 开机滚动字体显示优化 个人网站安全防护 树莓派上部署Vaultwarden 使用goaccess实时分析Caddy日志 个人网站监控 Hugo全站AVIF记 Linux下尝试使用Godot开发小游戏 Arch linux dae 透明代理 Airflow接管galler-dl下载任务 如何使用gallery-dl批量下载图像 Arch核显下如何愉快玩Dota2和CS2 Arch/labwc 环境网络相关设置 Rime添加dota2词库 Arch 重装记录 Supertuxkart iOS版终于发布了 打造自己的流媒体音乐服务 剪切板管理工具clipcat推荐 MangoHud性能监控 微信小程序开发记 Rofi试用 解决Arch下VSCode无法输入中文的问题 独立窗口管理器下无法录屏问题处理 上海市二手房成交数据监控 OpenLDAP监控 Arch linux如何顺畅连接蓝牙设备 使用Git和Ansible管理配置文件 Arch Linux SSL VPN 客户端配置 简单获取celery任务实时结果 Arch linux下iNode客户端的安装和使用方法 券商费率调整记 迷你主机组装记 Labwc更换定制皮肤 树莓派跑分流代理 实用自动代理配置示例 九年老鼠标复活记 Openvpn示例 Mac下如何旋转webp图片 如何隐藏Vscode中Markdown PDF插件的头部内容 解决Linux下网络配置无法变更保存的问题 labwc环境启用wlogout Ubuntu下新官方微信尝鲜 简单检测用户是否开启广告屏蔽 Atuin ZFS下卡顿问题解决 Wine安装64位微信 Fish 和 Atuin使用记 Fastapi简单实现临时下载链接 Fastapi微信公众号开发简要 Hugo根据语种展示不同内容 如何修复Waybar微信图标错误 信封加密简要 Linux环境下维护公众号记录 快速隐藏和呼出终端 Wayland环境自动切换壁纸 SuperTuxKart 试玩 简单抓取雪球股票快讯 为什么你的kill命令不能列出信号表 Wine安装微信保姆教程 Hysteria科学上网简要 Ubuntu 23.10 钉钉无法启动解决方法 网站导航栏防止插入Adsense自动广告 Linux环境按键检测 Hugo文末添加最后修改时间 Wayland环境ksnip无法复制问题解决 我眼中的股票市场 Caddy简单图片防盗链 greetd和regreet使用教程 Wayland环境下截图加后期修改 Wayland 环境下gif录屏 Firefox的一些有趣功能 Ubuntu 切换系统语言 Firefox 标题栏高度调整 网站添加回到顶部功能 Hugo自定义字体 Labwc 便捷配置 Wofi使用教程 窗口管理器labwc使用记 文件共享软件Dufs推荐 Hugo静态站点接入Adsense广告 Fcitx5配置详解 Ubuntu安装chrome的方法总结 一种Xterm.js的全屏方案 Google网址收录api Python示例 手机听离线音乐 Snipe it资产导入 应用启动器yofi使用配置 Snipe it资产管理系统安装使用 Ubuntu开机启动加速 Vue3 vite TypeScript跨域等相关设置 Ubuntu手动升级Libreoffice Ubuntu设置alacritty为默认终端 简体文章批量转换为繁体 使用Inkscape调整svg图片大小 实用命令 使用mitmproxy给手机app抓包 Python中rstrip方法细解 Github同主机多仓库部署deploy key问题处理 Linux安装最新版本Python KeePassXC使用教程 Ubuntu 22.10连接蓝牙耳机报错br-connection-profile-unavailable解决方法
PNG图片批量转换为webp
2022-07-01 · via mephisto.cc

网站在进行 seo 测试时,有一项推荐是更改 PNG 格式图片为 webp,图片体积大幅减少,质量损失不多。这样会加快网页加载速度,节约带宽。

由于网页里面 png 图片已经又一定数量,需要批量转换格式。操作在 ubuntu 下完成,过程如下。

下载工具包

sudo apt install webp

单个转换测试

➜  cwebp xray_firefox.png -o xray_firefox.webp
Saving file 'xray_firefox.webp'
File:      xray_firefox.png
Dimension: 1398 x 973
Output:    56808 bytes Y-U-V-All-PSNR 44.33 47.21 47.59   45.13 dB
        (0.33 bpp)
block count:  intra4:       1282  (23.88%)
            intra16:      4086  (76.12%)
            skipped:      3883  (72.34%)
bytes used:  header:            421  (0.7%)
            mode-partition:   7225  (12.7%)
Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |       1%|       9%|      22%|      67%|    5368
    quantizer:  |      36 |      34 |      29 |      23 |
filter level:  |      11 |       7 |      12 |      10 |
➜  ls -lh xray_firefox*
-rw-rw-r-- 1 mephisto mephisto 168K Jun  3 21:08 xray_firefox.png
-rw-rw-r-- 1 mephisto mephisto  56K Jul  1 16:16 xray_firefox.webp
➜

如上所示,体积从 168K 减少至 56k,为原来的体积的三分之一

firefox 打开图片对比测试,左 PNG,右 WEB

png webp diff

调整质量因素参数测试(参数为 q,0<N<100,默认值为 75,下面示例为 85),体积从 56K 增加至 71K

➜ cwebp -q 85  xray_firefox.png -o xray_firefox.webp
Saving file 'xray_firefox.webp'
File:      xray_firefox.png
Dimension: 1398 x 973
Output:    71730 bytes Y-U-V-All-PSNR 48.50 51.31 51.68   49.29 dB
        (0.42 bpp)
block count:  intra4:       1303  (24.27%)
            intra16:      4065  (75.73%)
            skipped:      3946  (73.51%)
bytes used:  header:            544  (0.8%)
            mode-partition:   7375  (10.3%)
Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |       1%|       9%|      22%|      67%|    5368
    quantizer:  |      20 |      18 |      16 |      12 |
filter level:  |       7 |       4 |       3 |       2 |
➜  iPhone ls -lh xray_firefox*
-rw-rw-r-- 1 mephisto mephisto 168K Jun  3 21:08 xray_firefox.png
-rw-rw-r-- 1 mephisto mephisto  71K Jul  1 16:23 xray_firefox.webp

批量转换

  • 简单批量转换脚本

      ➜  cat test.sh
      #/bin/bash
      for file in *.png;
      do
          echo $file
          cwebp "$file" -o "${file%.png}.webp";
      done
    
  • 执行脚本

      ➜  ./test.sh
      font_result.png
      Saving file 'font_result.webp'
      File:      font_result.png
      Dimension: 1335 x 1005
      Output:    57624 bytes Y-U-V-All-PSNR 43.96 45.09 45.14   44.31 dB
              (0.34 bpp)
      block count:  intra4:       1396  (26.38%)
                  intra16:      3896  (73.62%)
                  skipped:      3630  (68.59%)
      bytes used:  header:            419  (0.7%)
                  mode-partition:   7629  (13.2%)
      Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
          macroblocks:  |       2%|       7%|      19%|      72%|    5292
          quantizer:  |      36 |      35 |      29 |      23 |
      filter level:  |      11 |       7 |      38 |      30 |
      github_hook_result.png
      Saving file 'github_hook_result.webp'
      File:      github_hook_result.png
      Dimension: 1664 x 634
      Output:    33674 bytes Y-U-V-All-PSNR 45.81 45.92 46.16   45.89 dB
              (0.26 bpp)
      block count:  intra4:        643  (15.46%)
                  intra16:      3517  (84.54%)
                  skipped:      3258  (78.32%)
      bytes used:  header:            388  (1.2%)
                  mode-partition:   4412  (13.1%)
      Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
          macroblocks:  |       1%|       4%|      10%|      85%|    4160
          quantizer:  |      36 |      36 |      31 |      24 |
      filter level:  |      11 |       8 |       6 |       4 |
      github_webhook.png
      Saving file 'github_webhook.webp'
      File:      github_webhook.png
      Dimension: 1085 x 687
      Output:    35696 bytes Y-U-V-All-PSNR 44.19 44.32 44.53   44.27 dB
              (0.38 bpp)
      block count:  intra4:        658  (22.50%)
                  intra16:      2266  (77.50%)
                  skipped:      2141  (73.22%)
      bytes used:  header:            380  (1.1%)
                  mode-partition:   3715  (10.4%)
      Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
          macroblocks:  |       2%|       7%|      11%|      80%|    2924
          quantizer:  |      36 |      36 |      30 |      24 |
      filter level:  |      11 |       8 |       5 |       5 |
    
      ......
    
  • 查看结果,体积越大的图片,效果越明显

      ➜  ls -lh
      total 1.9M
      -rw-rw-r-- 1 mephisto mephisto  43K May 29 12:53 404.jpg
      -rw-rw-r-- 1 mephisto mephisto 166K Jun  8 13:59 font_result.png
      -rw-rw-r-- 1 mephisto mephisto  57K Jul  1 16:29 font_result.webp
      -rw-rw-r-- 1 mephisto mephisto  96K Jun  6 18:24 github_hook_result.png
      -rw-rw-r-- 1 mephisto mephisto  33K Jul  1 16:29 github_hook_result.webp
      -rw-rw-r-- 1 mephisto mephisto  93K Jun  6 18:18 github_webhook.png
      -rw-rw-r-- 1 mephisto mephisto  35K Jul  1 16:29 github_webhook.webp
      -rw-rw-r-- 1 mephisto mephisto 184K Jun  7 18:01 google_fonts.png
      -rw-rw-r-- 1 mephisto mephisto  74K Jul  1 16:29 google_fonts.webp
      -rw-rw-r-- 1 mephisto mephisto 114K Jun  4 16:03 haha.png
      -rw-rw-r-- 1 mephisto mephisto  52K Jul  1 16:29 haha.webp
      -rw-rw-r-- 1 mephisto mephisto  79K Jun  7 18:07 libre_baskerville_font.png
      -rw-rw-r-- 1 mephisto mephisto  28K Jul  1 16:29 libre_baskerville_font.webp
      -rw-rw-r-- 1 mephisto mephisto  67K Jun 21 17:27 rime_clover.png
      -rw-rw-r-- 1 mephisto mephisto  17K Jul  1 16:29 rime_clover.webp
      -rw-rw-r-- 1 mephisto mephisto 403K Jun 21 17:48 rime_example.png
      -rw-rw-r-- 1 mephisto mephisto  50K Jul  1 16:29 rime_example.webp
      -rwxrwxr-x 1 mephisto mephisto   89 Jul  1 16:29 test.sh
      -rw-rw-r-- 1 mephisto mephisto 168K Jun  3 21:08 xray_firefox.png
      -rw-rw-r-- 1 mephisto mephisto  56K Jul  1 16:29 xray_firefox.webp
    

如今 webp 的支持已经比较完善了,本站绝大部分的图片都已更改为 webp 格式,包括 ico 图标文件,目测无明显图片品质损失,加载速度的确较大幅度提升,毕竟小破站,想改就该。

大型站点,请君酌情处理。

2025 年 12 月 14 日更新:

使用 imagemagick 的相关工具转换也非常方便,推荐使用

1sudo pacman -S imagemagick
  • 单个转换 webp
1magick input.png output.webp
  • 批量转换
1  mogrify -format webp \*.png