标题: [文件操作] [分享]批处理给照片(包括子文件夹)添加随机图片水印 [打印本页]
作者: Batcher 时间: 2023-11-8 19:23 标题: [分享]批处理给照片(包括子文件夹)添加随机图片水印
【问题描述】
https://mp.weixin.qq.com/s/mSfzh4YhBYGjiRpuOn6L7A
使用这篇文章里面的代码,在照片目录下的多张图片可以直接添加上。
但有很多文件夹,不同的文件夹里的图片都要改,怎么写?
作者: Batcher 时间: 2023-11-8 19:25
【解决方案】
RandomPictureWatermark-2.bat- @echo off
- setlocal enabledelayedexpansion
- REM 1、下载并安装 ImageMagick 这个命令行工具
- REM https://imagemagick.org/script/download.php#windows
- REM 2、根据自己电脑实际安装路径设置以下临时环境变量
- set "path=C:\Program Files\ImageMagick;%path%"
-
- REM 设置待处理的照片所在的目录
- set "FolderOld=C:\Test\照片"
- REM 设置水印图片所在的目录
- set "FolderWM=C:\Test\水印"
- REM 设置添加水印之后的照片所在的目录
- set "FolderNew=C:\Test\合成"
-
- set "IndexWM=0"
- for /f "delims=" %%i in ('dir /a-d /b /s "%FolderWM%\*.png"') do (
- set /a IndexWM+=1
- set "File!IndexWM!=%%i"
- )
-
- set "IndexGD=0"
- set "ListDirect=NorthWest North NorthEast West Center East SouthWest South SouthEast"
- for %%i in (%ListDirect%) do (
- set /a IndexGD+=1
- set "Position!IndexGD!=%%i"
- )
-
- REM 假设待处理的照片有jpg、png两种格式,如有需要可以继续添加
- set "ListExt=jpg png"
- set "PictureType="
- for %%i in (%ListExt%) do (
- set "PictureType=!PictureType! *.%%i"
- )
-
- cd /d "%FolderOld%"
- for /f "delims=" %%i in ('dir /b /a-d !PictureType!') do (
- echo %%i
- set /a SelectWM=!random!%%!IndexWM!+1
- ping -n 2 127.0.0.1 >nul
- set /a SelectGD=!random!%%!IndexGD!+1
- call magick.exe composite -gravity %%Position!SelectGD!%% "%%File!SelectWM!%%" "%%i" "%FolderNew%\%%i"
- )
- for /f "delims=" %%a in ('dir /b /ad') do (
- echo --- %%a
- if not exist "%FolderNew%\%%a" (
- md "%FolderNew%\%%a"
- )
- pushd "%%a"
- for /f "delims=" %%i in ('dir /b /a-d !PictureType!') do (
- echo %%i
- set /a SelectWM=!random!%%!IndexWM!+1
- ping -n 2 127.0.0.1 >nul
- set /a SelectGD=!random!%%!IndexGD!+1
- call magick.exe composite -gravity %%Position!SelectGD!%% "%%File!SelectWM!%%" "%%i" "%FolderNew%\%%a\%%i"
- )
- popd
- )
- endlocal
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |