diff --git a/.github/labeler.yml b/.github/labeler.yml index f7806a6..366fc16 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,9 +1,10 @@ pr/test: - tests/* + - tests/fixtures/* pr/GitHub: - .github/* pr/IMGkit: - - src/* + - src/imgkit/* pr/documents: - '*.md' - 'LICENSE' diff --git a/.gitignore b/.gitignore index 71af159..7a73ed9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .idea *.pyc *.jpg +*.png # Build .cache diff --git a/README.md b/README.md index 2b8ee22..1eb0e8c 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ body = """ Hello World! - + """ imgkit.from_string(body, 'out.png') diff --git a/setup.cfg b/setup.cfg index e74989b..758a3c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = imgkit -version = 1.2.1 +version = 1.2.2 author = Jarrekk author_email = me@jarrekk.com description = Wkhtmltopdf python wrapper to convert html to image using the webkit rendering engine and qt diff --git a/src/imgkit/api.py b/src/imgkit/api.py index 5c812fb..e9b40f0 100644 --- a/src/imgkit/api.py +++ b/src/imgkit/api.py @@ -9,7 +9,7 @@ def from_url( options=None, toc=None, cover=None, - configuration=None, + config=None, cover_first=None, ): """ @@ -30,7 +30,7 @@ def from_url( options=options, toc=toc, cover=cover, - config=configuration, + config=config, cover_first=cover_first, ) return rtn.to_img(output_path) @@ -43,7 +43,7 @@ def from_file( toc=None, cover=None, css=None, - configuration=None, + config=None, cover_first=None, ): """ @@ -66,7 +66,7 @@ def from_file( toc=toc, cover=cover, css=css, - config=configuration, + config=config, cover_first=cover_first, ) return rtn.to_img(output_path) @@ -79,7 +79,7 @@ def from_string( toc=None, cover=None, css=None, - configuration=None, + config=None, cover_first=None, ): """ @@ -102,7 +102,7 @@ def from_string( toc=toc, cover=cover, css=css, - config=configuration, + config=config, cover_first=cover_first, ) return rtn.to_img(output_path) diff --git a/src/imgkit/imgkit.py b/src/imgkit/imgkit.py index 0b72c21..67b56cd 100644 --- a/src/imgkit/imgkit.py +++ b/src/imgkit/imgkit.py @@ -71,7 +71,6 @@ def _command(self, path=None): options = self._gegetate_args(self.options) options = [x for x in options] - # print 'options', options if self.css: self._prepend_css(self.css) @@ -231,7 +230,9 @@ def to_img(self, path=None): # string and prepend css to it and then pass it to stdin. # This is a workaround for a bug in wkhtmltoimage (look closely in README) if self.source.isString() or (self.source.isFile() and self.css): - string = self.source.to_s().encode("utf-8") + # HTML charset should be UTF-8 as encoding via utf-8 + charset_meta = '' + string = (charset_meta + self.source.to_s()).encode("utf-8") elif self.source.isFileObj(): string = self.source.source.read().encode("utf-8") else: diff --git a/src/imgkit/source.py b/src/imgkit/source.py index dfe09a0..4d89127 100644 --- a/src/imgkit/source.py +++ b/src/imgkit/source.py @@ -2,6 +2,8 @@ import io import os +from six import text_type + class Source: @@ -17,12 +19,12 @@ def __init__(self, url_or_file, type_): def isUrl(self): """URL type""" - return "url" in self.type + return "url" == self.type def isString(self): """String type""" - return "string" in self.type + return "string" == self.type def isFile(self, path=None): # dirty hack to check where file is opened with codecs module @@ -47,4 +49,7 @@ def isFileObj(self): return hasattr(self.source, "read") def to_s(self): - return self.source + if isinstance(self.source, text_type): + return self.source + else: + return text_type(self.source, "utf-8")