Skip to content

Commit d445f5d

Browse files
committed
Fix Python2 failure
1 parent 6076f06 commit d445f5d

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/jupyter_contrib_nbextensions/nbconvert_support/pre_embedimages.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import re
66
import os
77
import base64
8-
from urllib.request import urlopen
9-
from io import StringIO
108
from ipython_genutils.ipstruct import Struct
119

10+
try:
11+
from urllib.request import urlopen # py3
12+
except ImportError:
13+
from urllib2 import urlopen
14+
1215

1316
class EmbedImagesPreprocessor(Preprocessor):
1417
"""
@@ -69,19 +72,6 @@ def replfunc_md(self, match):
6972
with open(filename, 'rb') as f:
7073
data = f.read()
7174

72-
# TODO: scale image...
73-
if self.dpi_scaling > 0 and imgformat in ['png', 'jpg']:
74-
try:
75-
import pillow as PIL
76-
except ImportError:
77-
self.log.info("pillow library not available to scale images")
78-
if PIL:
79-
#im = PIL.Image.open(StringIO(data))
80-
#size = 128, 128
81-
#im.thumbnail(size, PIL.Image.ANTIALIAS)
82-
#data = im.save()
83-
self.log.info("Rescaled image %s to size %d x %d pixels" % (imgname, size) )
84-
8575
self.log.debug("embedding url: %s, format: %s" % (url, imgformat))
8676
b64_data = base64.b64encode(data).decode("utf-8")
8777
self.attachments[url] = { 'image/'+imgformat : b64_data }

0 commit comments

Comments
 (0)