同时支持Windows/Mac/Linux的图片批量添加水印并压缩的工具

69次阅读
没有评论

共计 2954 个字符,预计需要花费 8 分钟才能阅读完成。

特性

  • 同时支持 Window/Mac/Linux 三种系统
  • 单文件一键部署,无需安装依赖
  • 支持添加水印并压缩一条龙服务
  • 支持不加水印只进行压缩
  • 支持自定义水印文本
  • 支持自定义压缩级别
  • 支持自定义水印文本颜色
  • 支持自定义水印位置
  • 支持自定义水印文本大小

缺点

  • 暂时只支持英文文本水印,后续可开放全中文水印,如需中英混合水印可以考虑赞助后续开发
  • 需要一个启动密码才能运行
  • 由于打包了 python 解释器以及 opencv 和 PIL 库,生成的文件体积较大
  • 暂时只支持 jpeg,jpg,png 三种格式

开发环境

Mac:10.15.6

打包 / 运行环境

  • Mac:10.15.6
  • Windows: 1903
  • Linux: 在 Centos 7.4.1708 打包, 另外在基于 Ubuntu18.04 的 Linuxmint 19.2 中也测试过运行 ok

English Manual

$ ./image_helper -h
usage: image_helper.py [-h] -i [IMAGES [IMAGES ...]] [-t TEXT]
                       [-cl COMPRESSION_LEVEL] [-s FONTSIZE] [-r RGB_COLOR]
                       [-c COORDINATE] -p PASSWORD

A tool to add text watermark on the bottom right by default of the image and compress it.
The generated image file locates in the current dir just called 'new/'.

optional arguments:
  -h, --help            show this help message and exit
  -i [IMAGES [IMAGES ...]], --images [IMAGES [IMAGES ...]]
                        The image file you wanna add text watermark and
                        compress, or compress only
  -t TEXT, --text TEXT  The text of the watermark itself
  -cl COMPRESSION_LEVEL, --compression_level COMPRESSION_LEVEL
                        The compression level of the image you want to set.
                        For jp(e)g image, the range is 0 to 100, the bigger,
                        the bigger image you get,and the default is 50; For
                        png image, the range is 0 to 9, the bigger, the
                        smaller image you get, and the default is 5
  -s FONTSIZE, --fontsize FONTSIZE
                        The text watermark's font size, and the default is 50
  -r RGB_COLOR, --rgb_color RGB_COLOR
                        The rgb color for the text watermark, pls separate
                        with half angle comma ','and the default is
                        192,192,192.
  -c COORDINATE, --coordinate COORDINATE
                        The position of the watermark,and the range is 0 to 4,
                        0 means center, 1 means top left, 2 means top right, 3
                        means bottom left, 4 means bottom right, by default
                        it's bottom right 4.
  -p PASSWORD, --password PASSWORD
                        The boot password

Tip: if you only want to compress images, do not pass -t arg.
For more detailed Chinese documentation and usage tricks, Please visit below link:
同时支持 Windows/Mac/Linux 的图片批量添加水印并压缩的工具

中文手册

$ ./image_helper -h
使用: image_helper.py [-h] -i [IMAGES [IMAGES ...]] [-t TEXT]
                       [-cl COMPRESSION_LEVEL] [-s FONTSIZE] [-r RGB_COLOR]
                       [-c COORDINATE] -p PASSWORD

一个默认在右下角添加文本水印,生成的图片文件并压缩的工具,生成的图片文件位于当前目录的 new 文件夹里面。可选参数:
  -h, --help            显示帮助信息并退出
  -i [IMAGES [IMAGES ...]], --images [IMAGES [IMAGES ...]]
                        你想添加水印并压缩或只压缩的图片文件
  -t TEXT, --text TEXT  水印文本
  -cl COMPRESSION_LEVEL, --compression_level COMPRESSION_LEVEL
                        你想设置的图片压缩级别。对于 jp(e)g 图片,取值范围是 0 -100,值越大,你得到的图片大小越大,默认是 50;对于 png 图片,取值范围是 0 -9,值越大,你得到的图片越小,默认值是 5.
  -s FONTSIZE, --fontsize FONTSIZE
                        文本水印的大小,默认是 50
  -r RGB_COLOR, --rgb_color RGB_COLOR
                        文本水印的 rgb 颜色值,请用半角逗号 ',' 隔开, 默认是 192,192,192.
  -c COORDINATE, --coordinate COORDINATE
                        水印的位置,传参取值范围是 0 -4,0 表示中心,1 表示左上,2 表示右上,3 表示左下,4 表示右下,默认是右下
                        
  -p PASSWORD, --password PASSWORD
                        启动密码

小提示:如果你只需要压缩图片,请不要传递 - t 参数。更多详细的中文文档和使用技巧,请访问以下链接:
同时支持 Windows/Mac/Linux 的图片批量添加水印并压缩的工具

使用技巧

对于处理多张相同后缀名的图片,在 Mac 和 Linux 下,可以使用通配符,如下:

$ ./image_helper -t "https://www.sharpgan.com" -p wTjMEzGaW6v4UQZBCYeMQLbz -i *.png -s 80

在 windows 下可以使用 for 循环,如下:

for %i in (*.png) do image_helper.exe  -t "sharpgan.com" -p wTjMEzGaW6v4UQZBCYeMQLbz -i %i -r "255,64,64"  -s 100 -c 4

已在 cmd 下经过测试,运行详情可见下面的截图。对于处理多张后缀名不同的图片,在 Mac,Windows 和 Linux 三种系统下都可以使用如下技巧:

$ ./image_helper -t "https://www.sharpgan.com" -p wTjMEzGaW6v4UQZBCYeMQLbz -i 1.png 2.jpg -s 80

运行截图

  • Windows

同时支持 Windows/Mac/Linux 的图片批量添加水印并压缩的工具  

  • Linux

同时支持 Windows/Mac/Linux 的图片批量添加水印并压缩的工具

  • Mac

同时支持 Windows/Mac/Linux 的图片批量添加水印并压缩的工具

下载链接

Mac Linux Windows

启动密码

[$]

bXfp9vNefebB5JuEEvtbNBvY

[/$]

正文完
 
sharp097
版权声明:本站原创文章,由 sharp097 2020-09-14发表,共计2954字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)