이미지가 가득한 폴더가 있습니다. 파일이 작성된 날짜를 기준으로 모든 이미지의 이미지 자체에 타임 스탬프를 추가하려고합니다. 이것이 가능한가? 이 게시물을 읽어했습니다 여기에 ,하지만 EXIF 데이터를 사용합니다. 이미지에 exif 데이터가 없습니다.
작성된 날짜를 사용하여 타임 스탬프를 직접 추가 할 수 있습니까? 아니면 exif 데이터를 사용해야합니까? exif 데이터를 사용해야하는 경우 생성 된 날짜를 사용하여 어떻게 작성합니까?
GUI없이 Ubuntu Server를 사용하고 있으므로 명령 줄 솔루션이 필요합니다. 누구든지 도울 수 있습니까? 감사!
답변
이미지 파일 생성 날짜를 이미지 자체에 쓰려면 (원하는 것이 아닌 경우 질문을 편집 하십시오)을 사용할 수 있습니다 imagemagick
.
-
아직 설치되지 않은 경우 ImageMagick을 설치하십시오.
sudo apt-get install imagemagick
-
각 사진과 사용의 생성 날짜 얻을 것이다 떠들썩한 파티 루프 실행
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
답변
다양한 형식과 언어로 jpeg 이미지에 삽입 날짜 / 시간 / 코멘트를 일괄 삽입 하려면 http://jambula.sourceforge.net/ 을 확인하십시오 . 특별한 특징은 날짜 스탬프가 무손실이라는 것입니다. Linux 및 Mac에서도 지원됩니다.
답변
빈 디렉토리에 파일을 플로팅하고 AWK를 쉘로 파이프하십시오. 어쩌면 약간 oldskool이지만 훨씬 적은 팬츠, 입력 할 문자가 훨씬 적습니다. 예 :
ls | awk '{print "convert "$0" -gravity SouthEast -pointsize 22 -fill white -annotate +30+30 %[exif:DateTimeOriginal] dated"$0}' | sh