Batch file 如何修改此脚本以在图片中添加日期而不是日期和时间?
我遇到了这个有用的程序,可以在照片中添加日期和时间。如何修改bat文件,使其只添加日期而不添加日期时间 e、 g.2017:12:10而不是2017:12:10:10:02Batch file 如何修改此脚本以在图片中添加日期而不是日期和时间?,batch-file,imagemagick,Batch File,Imagemagick,我遇到了这个有用的程序,可以在照片中添加日期和时间。如何修改bat文件,使其只添加日期而不添加日期时间 e、 g.2017:12:10而不是2017:12:10:10:02 @echo off & cls rem enable variables referencing themselves inside loops SetLocal EnableDelayedExpansion rem optional settings set fontcolor=#FFD800 set fonto
@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
原始文件存放地点:
我不会说那种糟糕的Windows批处理语言怪物,但我怀疑您需要更改行:
for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
要仅获取第一个令牌,而不是前两个令牌,请执行以下操作:
for /f "tokens=1 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
如果这不起作用,并且任何不懂ImageMagick但懂Windows BATCH的人,请执行以下命令:
identify -format "%%[EXIF:DateTimeOriginal]" someImage.jpg
产生以下结果:
2013:03:09 08:59:50
通过编辑这一行,您可以仅从EXIF时间戳中获取日期
for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
把那行改成这行
for /f "tokens=1-2 delims= " %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
这样,您就可以使用空格作为分隔符,使用“delims=”而不是“delims=”。然后变量“%k”只读取“identifite”命令的输出,直到第一个空格,这只是日期部分。然后它将“%timestamp%”变量设置为该值,并像以前一样继续操作。不幸的是,这不起作用,因为EXIF标记只包含一个包含日期和时间的字符串,并且没有其他标记只包含日期。因此,解决方案是解析/剪切输出,这是留给读者的一个练习:)@xenoid我知道,
FOR/F TOKENS=…
正是这样做的-它将行拆分为单独的项,以分配给连续变量,即在本例中,%k
。。。。