
번호가 매겨진 이미지 시리즈를 어떻게 만들 수 있나요? 수천 장의 이미지에 숫자(글쓰기)를 부여해야 합니다.
이를 수행하는 쉬운 방법이 있습니까?
input.png 변환 -font arial -검정색 채우기 -pointsize 10 -annotate +20+20"1"출력_0001.png
input.png 변환 -font arial -검정색 채우기 -pointsize 10 -annotate +20+20"2"출력_0002.png
....
input.png 변환 -font arial -검정색 채우기 -pointsize 10 -annotate +20+20"1250"출력_1250.png
답변1
루프 를 사용하십시오 for
.
for i in `seq 1 1250`
do convert input.png -font arial -fill black -pointsize 10 -annotate +20+20 $i output_$(printf %04d $i).png
done
편집하다: 질문에 Windows를 사용 중이라고 명시하지 않으셨습니다. cmd.exe나 PowerShell을 모르기 때문에 두 가지 대체 솔루션을 제안하겠습니다.
Perl 배포판이 있는 경우(예:http://strawberryperl.com또는http://dwimperl.com), 시도해 보세요(테스트되지 않음):
#!/usr/bin/perl
use v5.14;
for (1 .. 1250) {
my $x = sprintf "%04d", $_;
system qw/convert input.png -font arial -fill black -pointsize 10 -annotate +20+20/, $_, "output_$x.png";
}
C 컴파일러가 있다면 시도해 보십시오(다시 테스트하지 않음).
#include<stdio.h>
#include<stdlib.h>
int main(void){
char cmd[1000];
int i;
for(i = 1 ; i <= 1250 ; i++){
sprintf(cmd, "convert input.png -font arial -fill black -pointsize 10 -annotate +20+20 %d output_%04d.png", i, i);
system(cmd);
}
return 0;
}
답변2
어디에서도 빠른 답변을 찾을 수 없었기 때문에 필요한 작업을 정확하게 수행하기 위한 배치 스크립트를 작성했습니다.
@echo off
setlocal enableextensions enabledelayedexpansion
set /a count = 0
For %%A in (*.png) DO (
set /a count += 1
echo Processing Image !count!
magick convert -font arial-black -pointsize 250 -fill white -strokewidth 5 -stroke black -gravity southeast -annotate +100+0 "!count!" "%%A" "!count!_%%A"
)
endlocal
pause
일괄 처리를 처음 사용하는 경우 주의해야 할 사항은 다음과 같습니다.
For %%A in (*.png) DO (
이는 이 폴더에 있는 PNG 파일만 처리한다는 의미입니다. 사용 중인 파일 확장자로 변경하세요.
그리고 주요 명령을 살펴보십시오.
magick convert -font arial-black -pointsize 250 -fill white -strokewidth 5 -stroke black -gravity southeast -annotate +100+0 "!count!" "%%A" "!count!_%%A"
글꼴, 숫자 색상(채우기), 윤곽선 표시 여부(획 및 획 너비, 원하지 않는 경우 제거)를 포함하여 변경할 수 있는 여러 가지가 있습니다. 숫자가 인쇄될 위치를 결정합니다. 이 경우 남동쪽은 오른쪽 하단에 있음을 의미합니다.
그리고 숫자의 크기를 제어하는 -pointsize를 변경하고 싶을 것입니다. 번호를 매겨야 하는 이미지가 모두 1920x1080이므로 250이라는 값을 선택했지만 대상 이미지의 크기에 따라 글꼴 크기를 변경해야 합니다.
이...
set /a count = 0
이미지에 인쇄되는 첫 번째 숫자가 1이 된다는 의미입니다. 필요한 시작 숫자에 따라 0, 더 높거나 더 낮게 설정하려면 이 값을 -1로 설정하세요.
나중에 찾으시는 분들에게 도움이 되길 바랍니다!
답변3
대신에:output_1250.png
당신이 원하는 것:output_%04d.png
%d
imagemagick에게 증분 숫자(예: )를 삽입하도록 지시하고 01.png
02.png
숫자 %04d
를 4자리 길이로 만들고 0으로 채우는 것을 의미합니다(예 output_0001.png
: output_0002.png
...) .output_1250.png
이렇게 하면 변환 명령을 하나만 사용할 수 있습니다.