【解决方案】
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
复制代码
|