将pdf转出来的图片拼接

convert 命令可以拼接图片

1
2
3
4
5
6
7
# Example (vertical sprite):

convert image1.png image2.png image3.png -append result/result-sprite.png

# Example (horizontal sprite):

convert image1.png image2.png image3.png +append result/result-sprite.png

脚本 concat-img-to-ocr,将pdf转出来的图片拼接,按照每组几个(第二个参数)来拼接出一组新的图片

示例: 按图片名字顺序,没3张合成一个图片: concat-img-to-ocr xxxpdf文件名_页面 3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

# help
# $1 pdf file name. A image exported from acrobat, is prefixed by the pdf file name
# $2 conut of images to concat

COUNTER=1
CONCAT_NUM=$2
IN_FILES=" "
OUT_COUNT=1
for f in $(ls -1 "$1"*.jpg | sort)
do
  IN_FILES=$IN_FILES"$f "
  
  MOD=$(( $COUNTER % $CONCAT_NUM ))
  echo "MOD: $MOD"
  echo "IN_FILES: $IN_FILES"
  
  if [ $MOD = 0 ]; then
    echo "MOD == 0"
    convert $IN_FILES -append $1"-concat-"$OUT_COUNT".jpg"
    let OUT_COUNT=$OUT_COUNT+1
    IN_FILES=" "
  fi
  
  let COUNTER=$COUNTER+1
done

if [ $MOD != 0 ]; then
  convert $IN_FILES -append $1"-concat-"$OUT_COUNT".jpg"
fi
echo "MOD: $MOD"
echo "COUNTER: $COUNTER"