[SOLVED]6.8.8+Win7 x64 - converting PDF pages to PNM pipe
Posted: 2014-03-07T20:16:25-07:00
EDIT:
A short summary of the problems I was having and how they were solved.
------------------------
I am using the Windows precompiled binaryImageMagick-6.8.8-0-Q16-x64-dll.exe on Windows 7 Professional x86.
I am trying to run a pipeline where I use "convert" to process each page of a PDF, crop a selection, convert the selection to a "raw" PBM stream (type P4), convert that to a "plain" PBM stream (type P1) with the pnmtopnm program from the GnuWin32 package, and then send that stream to a script for analysis.
Here is my pipeline:
The problem is that convert appears to send all the separate pages from the PDF in one long stream instead of "chunks". The pnmtopnm program only manages to convert the first page image in the sequence since the P4 header for the subsequent image is sent with the last line as the current image.
Here is an example of the output from convert:
(converted to a plain P1 PBM stream for posting purposes; the actual output from convert is a binary P4 stream)
I am at a bit of a loss as to how I should proceed.
A short summary of the problems I was having and how they were solved.
- PNMPlus tools (specifically pnmtopnm -plain) do not work well with convert's output stream
Skip the use of pnmtopnm and instead use the -compress none option when converting to a PBM image.
- convert sends PNM output to STDOUT in a stream rather than "chunking" it.
That is by design. http://www.imagemagick.org/Usage/files/#adjoin
It is the responsibility of the script/program ingesting the output from convert to buffer the input stream until a complete image has been obtained.A major problem with saving images, is that ImageMagick works with a ordered sequence (list) of images, not just one image at a time. Because of this IM will attempt to write ALL the images in the current image sequence into the filename given.
------------------------
I am using the Windows precompiled binaryImageMagick-6.8.8-0-Q16-x64-dll.exe on Windows 7 Professional x86.
Code: Select all
>convert -version
Version: ImageMagick 6.8.8-0 Q16 x64 2013-12-21 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib
Here is my pipeline:
Code: Select all
convert pdf:2a_e9c_540.pdf -crop 10x10+150+150 +repage pbm:- | pnmtopnm -plain | BITS-N-BOBS.py
Here is an example of the output from convert:
(converted to a plain P1 PBM stream for posting purposes; the actual output from convert is a binary P4 stream)
Code: Select all
P1
10 10
0000000000
0110000110
0110000110
0110000110
0110000110
0110000110
0110000110
0111111110
0111111110
0000000000P1
10 10
0000000000
0000110000
0000110000
0000110000
0111111110
0111111110
0000110000
0000110000
0000110000
0000000000P1
10 10
0000000000
0111111110
0111111110
0110000110
0110000110
0110000110
0110000110
0111111110
0111111110
0000000000