我遇到了這個有用的程序添加日期和時間的照片。我如何修改bat文件,以便它只添加日期而不是日期時間?如何修改這個腳本來添加日期而不是日期和時間的圖片?
例如10 2017年改爲:2017:12 12:10 10點10分02秒
@echo off & cls
rem enable variables referencing themselves inside loops
SetLocal EnableDelayedExpansion
rem optional settings
set fontcolor=#FFD800
set fontoutlinecolor=#000000
set fontstyle="Arial-Bold"
rem create a new folder where the stamped images will be placed
mkdir stamped
rem loop through all jpg png jpeg and gif files in the current folder
for /f "delims=" %%a in ('dir /b /A:-D /T:C "%cd%\*.jpg" "%cd%\*.png" "%cd%\*.jpeg" "%cd%\*.gif"') do (
rem retrieve image date and time
SetLocal EnableDelayedExpansion
for /f "tokens=1-2" %%i in ('identify.exe -ping -format "%%w %%h" "%cd%\%%a"') do set W=%%i& set H=%%j
rem retrieve image timestamp to perform size and distance calculations on
SetLocal EnableDelayedExpansion
for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
rem set timestamp to no timestamp if there is no timestamp
if "!timestamp!" == "" (
set timestamp=No timestamp
)
rem print some information about the process
echo %%a is !W! x !H! stamp !timestamp! ...
rem set timestamp size to a fourth of the screen width
set /A timestampsize = !W!/3
rem set timestamp offset distance from side of the screen
set /A timestampoffset = !W!/20
rem set timestamp outline relative size
set /A outlinewidth = !W!/600
rem echo !timestampsize! !timestampoffset!
rem create a custom image with the timestamp with transparent background and combine it with the image
convert.exe^
-verbose^
-background none^
-stroke !fontoutlinecolor!^
-strokewidth !outlinewidth!^
-font !fontstyle!^
-fill !fontcolor!^
-size !timestampsize!x^
-gravity center label:"!timestamp!" "%cd%\%%a" +swap^
-gravity southeast^
-geometry +!timestampoffset!+!timestampoffset!^
-stroke !fontoutlinecolor!^
-strokewidth !outlinewidth!^
-composite "%cd%\stamped\%%a"
endlocal
endlocal
echo.
)
endlocal
echo Complete!
pause
原始文件地點: https://nirklars.wordpress.com/2015/04/25/add-scaled-timestamps-to-photos/
不幸的是,這將不起作用,因爲EXIF標記一個單一的字符串,它包含日期和時間,並且沒有其他標記只有一天。所以解決方案是解析/剪切輸出,這是作爲練習留給讀者的:) – xenoid
@xenoid我明白'FOR/F TOKENS = ...'確實如此 - 它將行分成單獨的項目分配給連續變量,例如'%k'在這種情況下.... https://ss64.com/nt/for_cmd.html –