Crop image from pdf

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image from pdf

Post by fmw42 »

try this using -depth 8

Code: Select all

infile="fifty.pdf"
convert "$infile[0]" -depth 8 -background white -flatten -alpha off -negate -threshold 0 \
-define connected-components:verbose=true -connected-components 8 null: |\
tail -n +2 | while read line; do
bbox=`echo "$line" | sed 's/^[ ]*//' | cut -d\  -f2`
color=`echo "$line" | sed 's/^[ ]*//' | cut -d\  -f5`
#echo "bbox=$bbox; color=$color;"
if [ "$color" = "srgb(255,255,255)" ]; then
convert "$infile[0]" -crop "$bbox" +repage result.png
break
fi
done
ggoutfitters
Posts: 8
Joined: 2016-10-10T12:27:26-07:00
Authentication code: 1151

Re: Crop image from pdf

Post by ggoutfitters »

Awesome, works great!

Thank you!!!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Crop image from pdf

Post by anthony »

I have always has an interest in extracting the non-vector components (raster images) of a PDF file in there 'native' density.

As you should know resizing any raster image always results in a loss of quality, Thus my interest.

A quick google search found "pdfimages" from the "xpdf" package does exactly that!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply