Commit 16325f8c authored by Ingo Heimbach's avatar Ingo Heimbach

Fixed a wrongly named variable in the `EmbeddedImage` directive

parent cc304090
__version_info__ = (0, 1, 8) __version_info__ = (0, 1, 9)
__version__ = '.'.join(map(str, __version_info__)) __version__ = '.'.join(map(str, __version_info__))
...@@ -15,15 +15,15 @@ def is_url(url): ...@@ -15,15 +15,15 @@ def is_url(url):
return urlparse.urlparse(url).scheme not in ("", "file") return urlparse.urlparse(url).scheme not in ("", "file")
def convert_png_to_pillow_image_and_html_base64(png_filepath_or_url): def convert_image_to_pillow_image_and_html_base64(image_filepath_or_url):
if is_url(png_filepath_or_url): if is_url(image_filepath_or_url):
png_url = png_filepath_or_url image_url = image_filepath_or_url
response = requests.get(png_url) response = requests.get(image_url)
response.raise_for_status() response.raise_for_status()
image_content = response.content image_content = response.content
else: else:
png_filepath = png_filepath_or_url image_filepath = image_filepath_or_url
with open(png_filepath.encode(sys.getfilesystemencoding()), "rb") as image_file: with open(image_filepath.encode(sys.getfilesystemencoding()), "rb") as image_file:
image_content = image_file.read() image_content = image_file.read()
image = Image.open(BytesIO(image_content)) image = Image.open(BytesIO(image_content))
encoded_string = "data:image/{format};base64,".format(format=image.format.lower()) + base64.b64encode(image_content) encoded_string = "data:image/{format};base64,".format(format=image.format.lower()) + base64.b64encode(image_content)
...@@ -56,7 +56,7 @@ class EmbeddedImage(Directive): ...@@ -56,7 +56,7 @@ class EmbeddedImage(Directive):
% (self.name, self.options["align"], '", "'.join(self.align_values)) % (self.name, self.options["align"], '", "'.join(self.align_values))
) )
messages = [] messages = []
image, encoded_string = convert_png_to_pillow_image_and_html_base64(image_filepath) image, encoded_string = convert_image_to_pillow_image_and_html_base64(image_filepath)
reference = directives.uri(encoded_string) reference = directives.uri(encoded_string)
self.options["uri"] = reference self.options["uri"] = reference
if not any(attr in self.options for attr in ("height", "width", "scale")): if not any(attr in self.options for attr in ("height", "width", "scale")):
......
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