Created
April 18, 2023 22:01
-
-
Save rslhdyt/bc70832a7c1b2e0344e065064bc5cfc3 to your computer and use it in GitHub Desktop.
Convert PDF page to image using image magick
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
# create magick shell command to convert the first page of PDF file into image format | |
# Usage: convert_magic.sh <PDF file> <image format> <output name> | |
# convert_magic.sh input.pdf png output.png | |
# check if the PDF file exists | |
if [ ! -f $1 ]; then | |
echo "File $1 does not exist" | |
exit 1 | |
fi | |
# check if the image format is specified | |
if [ -z $2 ]; then | |
echo "Image format is not specified" | |
exit 1 | |
fi | |
# check if the image format is supported | |
if [ $2 != "png" ] && [ $2 != "jpg" ] && [ $2 != "gif" ]; then | |
echo "Image format $2 is not supported" | |
exit 1 | |
fi | |
# check if desired output not specified | |
if [ -z $3 ]; then | |
echo "Output name not specified" | |
exit 1 | |
fi | |
# convert the first page of PDF file into image format | |
magick convert -density 300 -quality 100 $1\[0\] $2:$3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment