-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
465087b
commit 41af6d0
Showing
4 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
# needs these two lines: | ||
sudo: required | ||
dist: trusty | ||
addons: | ||
chrome: stable | ||
|
||
language: python | ||
python: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "9aa0769fd66e42fcb83d86241d228062", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x08\\x06\\x00\\x00\\x00\\x1f\\x15\\…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# this generates a 1 pixel image with the rgba values (100, 200, 250, 255)\n", | ||
"# generated with the code in the next cells (kept for debugging purposes)\n", | ||
"import base64\n", | ||
"import ipywidgets\n", | ||
"image_data = base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNIOfHrPwAG4AMmv//laQAAAABJRU5ErkJggg==')\n", | ||
"ipywidgets.Image(value=image_data)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# try:\n", | ||
"# from io import BytesIO as StringIO\n", | ||
"# except:\n", | ||
"# from cStringIO import StringIO\n", | ||
"# import PIL.Image\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# f = StringIO(image_data)\n", | ||
"# image = PIL.Image.new('RGBA', (1,1))\n", | ||
"# image.putpixel((0, 0), (100, 200, 250, 255))\n", | ||
"# image.save(f, format='png')\n", | ||
"# base64.b64encode(f.getvalue())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# base64.b64encode(f.getvalue())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# image = PIL.Image.open(f)\n", | ||
"# pixel = image.getpixel((0, 0))\n", | ||
"\n", | ||
"# #assert pixel == (100, 200, 250)\n", | ||
"\n", | ||
"# pixel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
|
||
import nbformat | ||
from ..snapshot import SnapshotPreProcessor | ||
from ..execute import ExecutePreprocessor | ||
import PIL.Image | ||
try: | ||
from io import BytesIO as StringIO | ||
except: | ||
from cStringIO import StringIO | ||
import base64 | ||
|
||
current_dir = os.path.dirname(__file__) | ||
|
||
def test_red_pixel(): | ||
execute_preprocessor = ExecutePreprocessor(enabled=True) | ||
|
||
input_file = os.path.join(current_dir, 'files', 'single-pixel.ipynb') | ||
spp = SnapshotPreProcessor(page_opener_class='headless') | ||
nb = nbformat.read(input_file, 4) | ||
resources = {} | ||
nb, resources = execute_preprocessor.preprocess(nb, resources) | ||
assert 'image/png' not in nb.cells[0].outputs[0].data | ||
nb, resources = spp.preprocess(nb, resources) | ||
assert 'image/png' in nb.cells[0].outputs[0].data | ||
# we cannot be sure the browser encodes it the same way | ||
# assert nb.cells[0].outputs[0].data['image/png'] == 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNIOfHrPwAG4AMmv//laQAAAABJRU5ErkJggg==' | ||
# instead, we read the magic pixel values | ||
f = StringIO(base64.b64decode(nb.cells[0].outputs[0].data['image/png'])) | ||
image = PIL.Image.open(f) | ||
pixel = image.getpixel((0, 0)) | ||
assert pixel == (100, 200, 250, 255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters