Created
November 16, 2015 07:53
-
-
Save diablowu/9e6e67156993e3faebb2 to your computer and use it in GitHub Desktop.
pdf2jpg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "start convert pdf to jpeg" | |
| #command line | |
| sdir=$(dirname $0) | |
| gs_cli=$sdir'/gs' | |
| convert_cli='/usr/bin/convert' | |
| id_cli='/usr/bin/identify' | |
| #argv | |
| pdf=$1 | |
| jpg=$2 | |
| width=$3 | |
| #calc width & heigth | |
| $gs_cli \ | |
| -dBATCH \ | |
| -dNOPAUSE \ | |
| -q \ | |
| -sDEVICE=jpeg \ | |
| -o /tmp/_pdf_tmp.jpg \ | |
| -dJPEGQ=100 \ | |
| -dFirstPage=1 \ | |
| -dLastPage=1 \ | |
| -r300 \ | |
| rateexp=`$id_cli /tmp/_pdf_tmp.jpg |awk '{print $3}'|sed 's/x/\//g'` | |
| rate=`echo 'scale=4;'$rateexp|bc` | |
| heigth=`echo $width'/'$rate|bc` | |
| rm -rf /tmp/_pdf_tmp.jpg | |
| rx=$width'x'$heigth | |
| echo $rx | |
| if [ ! -d '/tmp/pdfjpg' ]; then | |
| mkdir /tmp/pdfjpg | |
| fi | |
| cd /tmp/pdfjpg | |
| $gs_cli \ | |
| -dBATCH \ | |
| -dNOPAUSE \ | |
| -q \ | |
| -sDEVICE=jpeg \ | |
| -o $jpg'_%03d.jpg' \ | |
| -dJPEGQ=100 \ | |
| -r100 \ | |
| -g$rx \ | |
| echo "start merge jpeg" | |
| $convert_cli -append $jpg'_*.jpg' $jpg'.jpg' | |
| echo "start resize jpeg" | |
| $convert_cli $jpg'.jpg' -strip -quality 75% -resize $width'x' $jpg'_min.jpg' | |
| echo "finish" | |
| rm -rf ./$jpg'_*.jpg' | |
| exit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment