หากคุณต้องการที่จะเขียนวันที่สร้างไฟล์ภาพที่เป็นภาพของตัวเอง (ถ้านั่นไม่ใช่สิ่งที่คุณต้องการโปรดแก้ไขคำถามของคุณ) imagemagickคุณสามารถใช้
- ติดตั้ง ImageMagick หากยังไม่ได้ติดตั้ง: - sudo apt-get install imagemagick
 
- เรียกใช้ bash loop ที่จะได้รับวันที่สร้างภาพแต่ละภาพและใช้- convertจาก- imagemagickห้องชุดเพื่อแก้ไขภาพ:
 - for img in *jpg; do convert "$img" -gravity SouthEast -pointsize 22 \
   -fill white -annotate +30+30  %[exif:DateTimeOriginal] "time_""$img"; 
done
 - สำหรับแต่ละภาพที่มีชื่อ- foo.jpgสิ่งนี้จะสร้างสำเนาที่เรียกว่า- time_foo.jpgมีการประทับเวลาที่ด้านล่างขวา คุณสามารถทำสิ่งนี้ได้อย่างสวยงามยิ่งขึ้นสำหรับไฟล์หลายประเภทและชื่อเอาต์พุตที่ดี แต่ไวยากรณ์มีความซับซ้อนน้อยกว่า:
 
ตกลงนั่นเป็นรุ่นที่เรียบง่าย ฉันเขียนสคริปต์ที่สามารถจัดการกับสถานการณ์ที่ซับซ้อนมากขึ้นไฟล์ในไดเรกทอรีย่อยชื่อไฟล์แปลก ฯลฯ เท่าที่ฉันรู้เพียงภาพ. png และ. tif เท่านั้นที่สามารถมีข้อมูล EXIF ดังนั้นจึงไม่มีประเด็นในการใช้งานรูปแบบอื่น ๆ . อย่างไรก็ตามคุณสามารถใช้วันที่สร้างไฟล์แทนข้อมูล EIF ได้ สิ่งนี้น่าจะไม่เหมือนกับวันที่ถ่ายภาพ แต่สคริปต์ด้านล่างนี้มีส่วนที่เกี่ยวข้องแสดงความคิดเห็น ลบความคิดเห็นหากคุณต้องการให้มันประมวลผลด้วยวิธีนี้
บันทึกสคริปต์นี้เป็นadd_watermark.shและเรียกใช้ในไดเรกทอรีที่มีไฟล์ของคุณ:
bash /path/to/add_watermark.sh
มันใช้exiv2ที่คุณอาจต้องติดตั้ง ( sudo apt-get install exiv2) สคริปต์:
#!/usr/bin/env bash
## This command will find all image files, if you are using other
## extensions, you can add them: -o "*.foo"
find . -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.tif" -o \
 -iname "*.tiff" -o -iname "*.png" | 
## Go through the results, saving each as $img
while IFS= read -r img; do
    ## Find will return full paths, so an image in the current
    ## directory will be ./foo.jpg and the first dot screws up 
    ## bash's pattern matching. Use basename and dirname to extract
    ## the needed information.
    name=$(basename "$img")
    path=$(dirname "$img")
    ext="${name/#*./}"; 
    ## Check whether this file has exif data
    if exiv2 "$img" 2>&1 | grep timestamp >/dev/null 
    ## If it does, read it and add the water mark   
    then
    echo "Processing $img...";
    convert "$img" -gravity SouthEast  -pointsize 22 -fill white \
             -annotate +30+30  %[exif:DateTimeOriginal] \
             "$path"/"${name/%.*/.time.$ext}";
    ## If the image has no exif data, use the creation date of the
    ## file. CAREFUL: this is the date on which this particular file
    ## was created and it will often not be the same as the date the 
    ## photo was taken. This is probably not the desired behaviour so
    ## I have commented it out. To activate, just remove the # from
    ## the beginning of each line.
    # else
    #   date=$(stat "$img" | grep Modify | cut -d ' ' -f 2,3 | cut -d ':' -f1,2)
    #   convert "$img" -gravity SouthEast  -pointsize 22 -fill white \
    #          -annotate +30+30  "$date" \
    #          "$path"/"${name/%.*/.time.$ext}";
    fi 
done
               
              
convert.im6: unknown image property "%[exif:DateTimeOriginal]" @ warning/property.c/InterpretImageProperties/3245. convert.im6: unable to open image `{img/%.*/.time.jpg}': No such file or directory @ error/blob.c/OpenBlob/2638.ฉันยังไม่ได้ตัดสินใจว่าต้องการใช้ไดเรกทอรีย่อยหรือยัง คุณสามารถแสดงวิธีใช้findเช่นกันได้หรือไม่? ขอบคุณ!