Compare commits

..
2 Commits
Author SHA1 Message Date
James R. Barlow 1d09061130 Revert previous commit amd reject input images with alpha channel
Decided on this for simplicity of old release branch.

Modifies baiona.png by stripping
alpha, adds baiona_alpha which
includes the alpha.
2018-07-31 23:45:28 -07:00
James R. Barlow a2203b2447 Discard alpha channel when triaging images 2018-07-25 22:23:41 -04:00
6 changed files with 32 additions and 11 deletions
+6
View File
@@ -10,6 +10,12 @@ The OCRmyPDF package itself does not contain a public API, although it is fairly
replace: `#$1 <https://github.com/jbarlow83/OCRmyPDF/issues/$1>`_ replace: `#$1 <https://github.com/jbarlow83/OCRmyPDF/issues/$1>`_
v6.2.3
------
- Fix compatibility with img2pdf >= 0.3.0 by rejecting input images that have an alpha channel
v6.2.2 v6.2.2
------ ------
+2
View File
@@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>. # along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
from PIL import Image
from functools import partial from functools import partial
from collections.abc import Iterable from collections.abc import Iterable
from contextlib import suppress, contextmanager from contextlib import suppress, contextmanager
+8
View File
@@ -19,6 +19,7 @@ from contextlib import suppress
from shutil import copyfileobj from shutil import copyfileobj
from pathlib import Path from pathlib import Path
from datetime import datetime, timezone from datetime import datetime, timezone
from io import BytesIO
import sys import sys
import os import os
import shutil import shutil
@@ -144,6 +145,13 @@ def triage_image_file(input_file, output_file, log, options):
"image was scanned and specify it using --image-dpi.") "image was scanned and specify it using --image-dpi.")
raise DpiError() raise DpiError()
if im.mode in ('RGBA', 'LA'):
log.error(
"The input image has an alpha channel. Remove the alpha "
"channel first."
)
raise UnsupportedImageFormatError()
if 'iccprofile' not in im.info: if 'iccprofile' not in im.info:
if im.mode == 'RGB': if im.mode == 'RGB':
log.info('Input image has no ICC profile, assuming sRGB') log.info('Input image has no ICC profile, assuming sRGB')
Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

+8 -3
View File
@@ -829,6 +829,7 @@ def test_no_contents(spoof_tesseract_noop, resources, outpdf):
@pytest.mark.parametrize('image', [ @pytest.mark.parametrize('image', [
'baiona.png', 'baiona.png',
'baiona_gray.png', 'baiona_gray.png',
'baiona_alpha.png',
'congress.jpg' 'congress.jpg'
]) ])
def test_compression_preserved(spoof_tesseract_noop, ocrmypdf_exec, def test_compression_preserved(spoof_tesseract_noop, ocrmypdf_exec,
@@ -839,7 +840,6 @@ def test_compression_preserved(spoof_tesseract_noop, ocrmypdf_exec,
output_file = str(outpdf) output_file = str(outpdf)
im = Image.open(input_file) im = Image.open(input_file)
# Runs: ocrmypdf - output.pdf < testfile # Runs: ocrmypdf - output.pdf < testfile
with open(input_file, 'rb') as input_stream: with open(input_file, 'rb') as input_stream:
p_args = ocrmypdf_exec + [ p_args = ocrmypdf_exec + [
@@ -849,7 +849,12 @@ def test_compression_preserved(spoof_tesseract_noop, ocrmypdf_exec,
stdin=input_stream, env=spoof_tesseract_noop) stdin=input_stream, env=spoof_tesseract_noop)
out, err = p.communicate() out, err = p.communicate()
assert p.returncode == ExitCode.ok if im.mode in ('RGBA', 'LA'):
# If alpha image is input, expect an error
assert p.returncode != ExitCode.ok and b'alpha' in err
return
assert p.returncode == ExitCode.ok, err.decode('utf-8')
pdfinfo = PdfInfo(output_file) pdfinfo = PdfInfo(output_file)
@@ -894,7 +899,7 @@ def test_compression_changed(spoof_tesseract_noop, ocrmypdf_exec,
stdin=input_stream, env=spoof_tesseract_noop) stdin=input_stream, env=spoof_tesseract_noop)
out, err = p.communicate() out, err = p.communicate()
assert p.returncode == ExitCode.ok assert p.returncode == ExitCode.ok, err
pdfinfo = PdfInfo(output_file) pdfinfo = PdfInfo(output_file)