Skip to content

已轉換為WebP的照片仍會反覆被resize,導致repository大小不斷增加 #12

@YuevUwU

Description

@YuevUwU

描述

如題

原因

- name: JPG 轉檔成 WebP
run: |
find img -type d -exec mkdir -p converted/{} \;
find img -type f \( -name '*.png' -o -name '*.jpg' -o -name '*.JPG' -o -name '*.jpeg' -o -name '*.JPEG' \) -exec sh -c '
converted_file="converted/${1%.*}.webp"
echo "@!#$converted_file"
ffmpeg -i "$1" -q 50 "$converted_file"
' _ {} \;
find converted -type f -name '*.webp' -exec sh -c 'convert "$1" -resize x1000 "$1"' _ {} \;

FFmpeg 遇到同名檔案自動選擇不覆蓋(無交互式),但不會以非零錯誤碼中斷工作
(不中斷是預期的,但應該透過獨立檢查檔案是否目標檔案已存在,或日後 #13 的實現,而不是仰賴 FFmpeg exit code 為參考)
故 ImageMagick 6 convert -resize 永遠會被執行!

實作建議

當前社團圖片有自己的防止二次上傳的邏輯(diff)
請考慮實作時將機制統合為一

甚至可考慮只用 FFmpeg 與 ImageMagick 6 其中一個

後續處理

考慮改完用 git filter-repo --invert-paths --path-glob converted/**/*.webp (安裝指南) 刪掉不需要的 BLOB

統計

(測試時間:2025/11/2, commit: b9f1ed29)

du (src)

~/website-data-pure$ bash ../repo-size-report.sh
Source Code: 328.435MiB (1024-based)
.git: 370.942MiB (1024-based)
Delta=42.507MiB (1024-based)

git-count-objects

$ git count-objects -v ([doc](https://git-scm.com/docs/git-count-objects))
count: 0
size: 0
in-pack: 1936
packs: 1
size-pack: 379783
prune-packable: 0
garbage: 0
size-garbage: 0

git-sizer (repo)

$ git-sizer -v
Processing blobs: 1224
Processing trees: 493
Processing commits: 219
Matching commits to trees: 219
Processing annotated tags: 0
Processing references: 6
| Name                         | Value     | Level of concern               |
| ---------------------------- | --------- | ------------------------------ |
| Overall repository size      |           |                                |
| * Commits                    |           |                                |
|   * Count                    |   219     |                                |
|   * Total size               |   102 KiB |                                |
| * Trees                      |           |                                |
|   * Count                    |   493     |                                |
|   * Total size               |   199 KiB |                                |
|   * Total tree entries       |  5.17 k   |                                |
| * Blobs                      |           |                                |
|   * Count                    |  1.22 k   |                                |
|   * Total size               |   376 MiB |                                |
| * Annotated tags             |           |                                |
|   * Count                    |     0     |                                |
| * References                 |           |                                |
|   * Count                    |     6     |                                |
|     * Branches               |     1     |                                |
|     * Remote-tracking refs   |     5     |                                |
|                              |           |                                |
| Biggest objects              |           |                                |
| * Commits                    |           |                                |
|   * Maximum size         [1] |  1.55 KiB |                                |
|   * Maximum parents      [2] |     2     |                                |
| * Trees                      |           |                                |
|   * Maximum entries      [3] |    97     |                                |
| * Blobs                      |           |                                |
|   * Maximum size         [4] |  17.3 MiB | *                              |
|                              |           |                                |
| History structure            |           |                                |
| * Maximum history depth      |   200     |                                |
| * Maximum tag depth          |     0     |                                |
|                              |           |                                |
| Biggest checkouts            |           |                                |
| * Number of directories  [5] |    38     |                                |
| * Maximum path depth     [6] |     5     |                                |
| * Maximum path length    [7] |    72 B   |                                |
| * Number of files        [7] |   299     |                                |
| * Total size of files    [8] |   329 MiB |                                |
| * Number of symlinks         |     0     |                                |
| * Number of submodules       |     0     |                                |

[1]  9d19ba9d8df7006d207799e7599a0e54634ae0d0
[2]  94cc9596c29e0b84e027025c2c3f51aa71dd5145
[3]  2a5b670cd08c99651635d90a2c0c45c7c299d1fb (6a1f4787b44f38320f72331d3300ed6239cb1ebd:converted)
[4]  c52870ed7e3340e8cbe224cf7c083829ba4fa61a (refs/heads/main:111寒訓/IMG_0989.JPG)
[5]  2acc602e5c599537bb2ba5bf8160ab49e290ccfc (94cc9596c29e0b84e027025c2c3f51aa71dd5145^{tree})
[6]  5d3050913d69e0631415261206edcc958371a551 (refs/heads/main^{tree})
[7]  22c2773d4714d5077463bf7c0b840e51d2959b77 (6a1f4787b44f38320f72331d3300ed6239cb1ebd^{tree})
[8]  b3eaffad57bbc44dee41ca8d936097df0a33d4a3 (9cf4400cab73cbbb13e4ff58e75c795937712358^{tree})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions