2017-09-15 15 views
1

我遇到了這個有用的程序添加日期和時間的照片。我如何修改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/

回答

1

你可以得到公正從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」只會讀取「identify」命令的輸出,直到第一個空間(僅爲日期部分)。然後它將您的「%timestamp%」變量設置爲該值並繼續。

0

我不說話這麼難聽的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批處理,下面的命令:

identify -format "%%[EXIF:DateTimeOriginal]" someImage.jpg 

產生這樣的:

2013:03:09 08:59:50 
+0

不幸的是,這將不起作用,因爲EXIF標記一個單一的字符串,它包含日期和時間,並且沒有其他標記只有一天。所以解決方案是解析/剪切輸出,這是作爲練習留給讀者的:) – xenoid

+0

@xenoid我明白'FOR/F TOKENS = ...'確實如此 - 它將行分成單獨的項目分配給連續變量,例如'%k'在這種情況下.... https://ss64.com/nt/for_cmd.html –

相關問題