Commit 06329b41 authored by Jerome Flesch's avatar Jerome Flesch

Merge pull request #28 from PauloMigAlmeida/master

Avoid unnecessary convert to RGB and allow using image formats different from PNG
parents e73a78bc 34a3c31c
...@@ -98,9 +98,11 @@ def image_to_string(image, lang=None, builder=None): ...@@ -98,9 +98,11 @@ def image_to_string(image, lang=None, builder=None):
cmd += ["-o", output_file.name] cmd += ["-o", output_file.name]
cmd += ["-"] # stdin cmd += ["-"] # stdin
if image.mode != "RGB":
image = image.convert("RGB")
img_data = BytesIO() img_data = BytesIO()
image = image.convert("RGB") image.save(img_data, format=image.format)
image.save(img_data, format="png")
proc = subprocess.Popen(cmd, proc = subprocess.Popen(cmd,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
......
...@@ -150,12 +150,13 @@ def detect_orientation(image, lang=None): ...@@ -150,12 +150,13 @@ def detect_orientation(image, lang=None):
if lang is not None: if lang is not None:
command += ['-l', lang] command += ['-l', lang]
image = image.convert("RGB") if image.mode != "RGB":
image = image.convert("RGB")
proc = subprocess.Popen(command, stdin=subprocess.PIPE, proc = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
image.save(proc.stdin, format='png') image.save(proc.stdin, format=image.format)
proc.stdin.close() proc.stdin.close()
output = proc.stdout.read() output = proc.stdout.read()
proc.wait() proc.wait()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment