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):
cmd += ["-o", output_file.name]
cmd += ["-"] # stdin
if image.mode != "RGB":
image = image.convert("RGB")
img_data = BytesIO()
image = image.convert("RGB")
image.save(img_data, format="png")
image.save(img_data, format=image.format)
proc = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
......
......@@ -150,12 +150,13 @@ def detect_orientation(image, lang=None):
if lang is not None:
command += ['-l', lang]
image = image.convert("RGB")
if image.mode != "RGB":
image = image.convert("RGB")
proc = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
image.save(proc.stdin, format='png')
image.save(proc.stdin, format=image.format)
proc.stdin.close()
output = proc.stdout.read()
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