Skip to content

Commit

Permalink
Fix #68 #69 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrekk authored Apr 10, 2021
1 parent 5c87162 commit 1124d2e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pr/test:
- tests/*
- tests/fixtures/*
pr/GitHub:
- .github/*
pr/IMGkit:
- src/*
- src/imgkit/*
pr/documents:
- '*.md'
- 'LICENSE'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.idea
*.pyc
*.jpg
*.png

# Build
.cache
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ body = """
<meta name="imgkit-orientation" content="Landscape"/>
</head>
Hello World!
</html>
</html>
"""

imgkit.from_string(body, 'out.png')
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = imgkit
version = 1.2.1
version = 1.2.2
author = Jarrekk
author_email = [email protected]
description = Wkhtmltopdf python wrapper to convert html to image using the webkit rendering engine and qt
Expand Down
12 changes: 6 additions & 6 deletions src/imgkit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def from_url(
options=None,
toc=None,
cover=None,
configuration=None,
config=None,
cover_first=None,
):
"""
Expand All @@ -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)
Expand All @@ -43,7 +43,7 @@ def from_file(
toc=None,
cover=None,
css=None,
configuration=None,
config=None,
cover_first=None,
):
"""
Expand All @@ -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)
Expand All @@ -79,7 +79,7 @@ def from_string(
toc=None,
cover=None,
css=None,
configuration=None,
config=None,
cover_first=None,
):
"""
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/imgkit/imgkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 = '<meta charset="UTF-8">'
string = (charset_meta + self.source.to_s()).encode("utf-8")
elif self.source.isFileObj():
string = self.source.source.read().encode("utf-8")
else:
Expand Down
11 changes: 8 additions & 3 deletions src/imgkit/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import io
import os

from six import text_type


class Source:

Expand All @@ -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
Expand All @@ -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")

0 comments on commit 1124d2e

Please sign in to comment.