IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    PicGO安装picgo-plugin-watermark实现上传图片时添加水印

    52txr发表于 2024-12-28 14:47:00
    love 0

    本文记录了在使用 PicGO 配置 picgo-plugin-watermark 插件实现上传图片时添加水印的全过程。首先分析了安装过程中遇到的 Python 环境问题,包括 npm 安装依赖时对 Python 版本的要求及解决方案。接着详细介绍了插件的安装及配置步骤,重点说明了图片水印与文字水印的设置方法及优先级,并通过示例演示了最终效果。同时附带了插件完整的配置说明,方便读者根据需求灵活调整水印样式与位置。

    遇到的问题(python)

    总结了一下,就是核心·的报错就是:

    npm error gyp ERR! find Python - version is ""
    npm error gyp ERR! find Python - version is  - should be >=3.6.0
    npm error gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
    npm error gyp ERR! find Python - "C:\Program Files\Python311\python.exe" could not be run

    翻译成人话就是找到的Python版本是空(也就是安装python),实际需要一个大于3.6版本python。竟然发现了C:\Program Files\Python311\python.exe这个程序,但是不可用。

    我搜了一下,有一个python 运行命令,我打开就是app store。好吧,我确实没有单独安装Python,只有一个conda虚拟环境。

    没有Python环境

    解决问题的话就是先安装一个python,可以安装3.10版本。如果是win7的话,得安装3.7、3.8,再后面就不支持win7了。

    国内的话建议使用镜像源来下载Python安装包:

    Python各版本安装包 - 华为云镜像

    把Python添加到路径

    记得添加环境变量,勾选上添加到PATH,其他安装自己看着即可。下面是安装好了:

    安装完成

    安装picgo-plugin-watermark

    cd C:\Users\你的电脑用户名\AppData\Roaming\picgo
    npm install picgo-plugin-watermark

    顺利安装:

    顺利安装插件

    配置插件

    重新启动PicGO软件。然后点击小齿轮对插件进行配置。

    配置插件

    下面进行配置。插件支持两种水印,分别是文字水印以及图片水印。这里我设置的是图片水印。可以同时设置图片水印以及文字水印,但是图片水印的优先级要高于文字水印。我只设置一个图片水印。图片水印的绝对路径位置是E:\temp-blog\watermarked.png。

    位置填写lt或者ct之类的。我是希望在图片中间,则是cm。

    我希望在较大的图片上添加水印,较小的就算了。可以设置最小尺寸为:300*300

    添加水印的示例

    本文已经开始使用。

    完整的配置说明

    fontFamily

    字体文件路径。E.g./Users/fonts/Arial-Unicode-MS.ttf。

    默认只支持英文水印,中文支持需要自行导入中文字体文件。

    text

    水印文字。E.g.hello world

    textColor

    水印文字的颜色,支持rgb和hex格式。E.g.rgb(178,178,178)、#b2b2b2

    fontSize

    字体大小,默认14

    image

    水印图片路径。E.g./Users/watermark.png,优先级大于文字

    position

    位置,默认rb

    export enum PositionType {
      lt = "left-top",
      ct = "center-top",
      rt = "right-top",
      lm = "left-middle",
      cm = "center-middle",
      rm = "right-middle",
      lb = "left-bottom",
      cb = "center-bottom",
      rb = "right-bottom"
    }

    minSize

    原图最小尺寸,小于这一尺寸不添加水印。E.g.200*200。

    高度或宽度任何一个小于限制,都会触发

    缺python的关键报错信息

    npm error gyp ERR! find Python checking if Python is C:\Program Files\Python310\python.exe
    npm error gyp ERR! find Python - version is ""
    npm error gyp ERR! find Python - version is  - should be >=3.6.0
    npm error gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
    npm error gyp ERR! find Python - "C:\Program Files\Python310\python.exe" could not be run
    npm error gyp ERR! find Python checking if Python is C:\Users\MrWood\AppData\Local\Programs\Python\Python310-32\python.exe
    
    npm error gyp ERR! find Python **********************************************************
    npm error gyp ERR! find Python You need to install the latest version of Python.
    npm error gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
    npm error gyp ERR! find Python you can try one of the following options:
    npm error gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
    npm error gyp ERR! find Python (accepted by both node-gyp and npm)
    npm error gyp ERR! find Python - Set the environment variable PYTHON
    npm error gyp ERR! find Python - Set the npm configuration variable python:
    npm error gyp ERR! find Python npm config set python "C:\Path\To\python.exe"
    npm error gyp ERR! find Python For more information consult the documentation at:
    npm error gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
    npm error gyp ERR! find Python **********************************************************


沪ICP备19023445号-2号
友情链接