Skip to content

walledata/flatter

Repository files navigation

Flatter

资源目录展平与图片压缩

安装依赖

  • macOS直接执行

    ./setup.sh
  • 其他操作系统需要将setup.sh中的brew安装命令替换为对应系统的包管理器安装命令

全自动脚本

一键执行目录展平 -> 压缩图片 -> 恢复目录结构(需要先安装依赖)

./main.sh <源图片文件夹路径> <目标文件夹路径>

以下非必读

资源目录展平与还原

目前版本完全基于标准库编写,不需要安装除python3解释器本身以外的任何依赖。

  • 查看帮助

    python3 flatter.py -h

    帮助内容如下:

    usage: flatter.py [-h] {flat,move_back} start_dir dest_dir
    
    Flat and restore resource directory.
    Copyright (C) 2024 Walledata.
    Licensed under GPLv3 License.
    
    positional arguments:
      {flat,move_back}  flat - copy all images to a single level folder, move_back - restore the original resource directory structure.
      start_dir         flat: original resource dir; move_back: the json file records the original resource dir structure.
      dest_dir          Directory where to store the flatten resource dir.
    
    options:
      -h, --help        show this help message and exit
    
  • 目录展平

    python3 flatter.py flat <your_resource_folder> ./tmp > map.json
  • 目录还原

    python3 flatter.py move_back ./map.json ./tmp

    **注意:**执行还原会将展平后的文件再复制回原始的资源目录,会进行文件覆盖,虽然理论上仍然是用相同的文件覆盖,但是保险期间还是建议先对map.json做字符替换处理(具体可以参考main.sh中的实现),或者先将原始的资源目录备份

图片压缩

  • 使用ffmpeg压缩.jpg图片,使用~~pngquant~~crunch压缩.png图片

  • 安装FFmpeg:

    brew install ffmpeg
  • 安装pngquant:

    git clone --recursive https://github.com/kornelski/pngquant.git
    cd pngquant
    cargo build --release --features=cocoa
    sudo mv target/release/pngquant /usr/local/bin/pngquant
  • 安装Crunch:

    Install Crunch.

    git clone https://github.com/chrissimpkins/Crunch.git
    make build-dependencies
    make install-executable
  • 压缩示例:

    • 待压缩图片放在./input/(假设目录已做过展平处理)

    • 压缩后的图片保存到./output/

    • 压缩

      ./compress.sh ./input ./output

About

图片资源目录展平、压缩与还原

Resources

License

Stars

Watchers

Forks

Packages

No packages published