From e21b3155e582940294777a35d635a2755660f25b Mon Sep 17 00:00:00 2001 From: fritz-hh Date: Wed, 24 Apr 2013 21:12:35 +0200 Subject: [PATCH] OCRmyPDF.sh: corrected dpi computation fixes #12 --- OCRmyPDF.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/OCRmyPDF.sh b/OCRmyPDF.sh index 9c45f3b4..33ef47e0 100644 --- a/OCRmyPDF.sh +++ b/OCRmyPDF.sh @@ -193,14 +193,12 @@ while read pageSize ; do curOrigImg01=`ls -1 "$curOrigImg"*` propCurOrigImg01=`identify -format "%w %h %[colorspace]" "$curOrigImg01"` heightCurOrigImg01=`echo "$propCurOrigImg01" | cut -f1 -d" "` - widthICurOrigImg01=`echo "$propCurOrigImg01" | cut -f2 -d" "` + widthCurOrigImg01=`echo "$propCurOrigImg01" | cut -f2 -d" "` colorspaceCurOrigImg01=`echo "$propCurOrigImg01" | cut -f3 -d" "` - # compute the resolution of the whole page (taking into account all images) - dpi_x=$(($widthICurOrigImg01*72/$widthPDF)) - dpi_y=$(($heightCurOrigImg01*72/$heightPDF)) - [ "$dpi_x" -ne "$dpi_y" ] && echo "X/Y Resolutions not equal (Not supported currently). Exiting..." && exit $EXIT_BAD_INPUT_FILE - dpi="$dpi_x" - + # compute the resolution of the image in the page + dpi=`echo "sqrt(($widthCurOrigImg01*72/$widthPDF)*($heightCurOrigImg01*72/$heightPDF))" | bc -l` + dpi=`echo "scale=0;($dpi+0.5)/1" | bc` # round the dpi value to the nearest integer + # Identify if page image should be saved as ppm (color) or pgm (gray) ext="ppm" opt="" @@ -220,7 +218,7 @@ while read pageSize ; do # if requested deskew image (without changing its size in pixel) if [ "$PREPROCESS_DESKEW" -eq "1" ]; then [ $VERBOSITY -ge $LOG_DEBUG ] && echo "Page $page: Deskewing image" - ! convert "$curImgPixmap" -deskew 40% -gravity center -extent ${heightCurOrigImg01}x${widthICurOrigImg01} "$curImgPixmapDeskewed" \ + ! convert "$curImgPixmap" -deskew 40% -gravity center -extent ${heightCurOrigImg01}x${widthCurOrigImg01} "$curImgPixmapDeskewed" \ && echo "Could not deskew \"$curImgPixmap\". Exiting..." && exit $EXIT_OTHER_ERROR else cp "$curImgPixmap" "$curImgPixmapDeskewed"