Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing problem of not seeing images on python3 #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cache:
apt: true
directories:
- /home/travis/virtualenv/python2.7/lib/python2.7/site-packages
- /home/travis/virtualenv/python3.2/lib/python3.2/site-packages

before_install:
- sudo apt-get update
Expand All @@ -30,8 +31,8 @@ before_install:

python:
- "2.7"
# - "3.4"
# - "3.3"
- "3.2"
# - "3.3"

install:
- pip install -r devrequirements.txt
Expand Down
10 changes: 9 additions & 1 deletion vlogging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from io import BytesIO as StringIO
from string import Template
import base64
import sys

__version__ = "0.2"
renderers = []
__is_python_3__ = (sys.version_info[0] >= 3)

try:
import cv2
Expand Down Expand Up @@ -77,6 +79,12 @@ def __init__(self, title="", imgs=None, footnotes="", fmt="png"):

self.footnotes = footnotes

def getEncodedString(self, data):
ret = str(base64.b64encode(data))
if __is_python_3__:
ret = ret[2:-1]
return ret

def render_images(self):
rendered = []

Expand All @@ -93,7 +101,7 @@ def render_images(self):

return "".join(
Template('<img src="data:$mime;base64,$data" />').substitute({
"data": base64.b64encode(data).decode(),
"data": self.getEncodedString(data),
"mime": mime
}) for data, mime in rendered)

Expand Down