Skip to content

Commit

Permalink
image works so far
Browse files Browse the repository at this point in the history
  • Loading branch information
lingruiluo committed Jul 10, 2020
1 parent 819830c commit 35e1409
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions notebooks/misc/svg_tests/image test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from jp_doodle import dual_canvas\n",
"from IPython.display import display"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "73e866324ddd4a5f904b52540e559d82",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"DualCanvasWidget(status='deferring flush until render')"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.image as mpimg\n",
"img = mpimg.imread('mandrill.png')\n",
"img.shape, img.max(), img.min()\n",
"demo = dual_canvas.DualCanvasWidget(width=320, height=220)\n",
"display(demo)\n",
"# Scaled the image to byte values.\n",
"inverted = (1 - img) * 255\n",
"# Load the image to the canvas and name it.\n",
"demo.name_image_array(\"mandrill\", inverted)\n",
"# Draw the image by name.\n",
"demo.named_image(\"mandrill\", 50, 50, 210, 130)\n",
"demo.fit()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'shape_name': 'canvas',\n",
" 'width': 320,\n",
" 'height': 220,\n",
" 'lineWidth': 1,\n",
" 'fillColor': 'black',\n",
" 'strokeStyle': 'black',\n",
" 'translate_scale': {'x': -47.9,\n",
" 'y': -41.36875,\n",
" 'w': 1.4939309056956116,\n",
" 'h': 1.4939309056956116,\n",
" 'model_height': 147.2625,\n",
" 'model_intercept': 230},\n",
" 'font': 'normal 10px Arial',\n",
" 'y_up': True,\n",
" 'style': 'border:1px solid #d3d3d3;'},\n",
" {'x': 50,\n",
" 'y': 50,\n",
" 'w': 210,\n",
" 'h': 130,\n",
" 'image_name': 'mandrill',\n",
" 'degrees': 0,\n",
" 'draw_on_canvas': {},\n",
" 'object_index': 0,\n",
" 'shape_name': 'named_image',\n",
" 'coordinate_conversion': {},\n",
" 'draw_mask': {},\n",
" 'sample_pixel': {'x': 160, 'y': 110}}]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"demo.get_raw_draw_information()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<svg viewBox=\"0 0 320 220\" xmlns=\"http://www.w3.org/2000/svg\">\n",
" <g transform=\"scale(1.4939309056956116 1.4939309056956116) translate(-47.9 -41.36875)\">\n",
"\t<image href=\"mandrill.png\" x=\"50\" y=\"50\" height=\"130\" width=\"210\" />\n",
"\t</g>\n",
"</svg>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from jp_doodle import svg_translation\n",
"\n",
"svg_translation.display_as_svg(demo)"
]
}
],
"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.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 35e1409

Please sign in to comment.