Skip to content

Commit

Permalink
better way to png
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Kellerman committed Sep 8, 2020
1 parent 1d8d8f1 commit 4220486
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions juliabrot-zoom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"# Change some of the preview grid settings, for example size. Fractal will generate below cell\n",
"# Max dimensions are 16K x 16K, beware PS memory is limited and large images may have issues when coloring\n",
"# Note: cannot override kernel_mode unless overlay is reloaded!\n",
"big_grid.set_size(1920,1080)\n",
"big_grid.set_size(1920, 1080)\n",
"big_grid.settings.max_iterations = int(jui.iter_slider.value)\n",
"big_tile = jui.juliabrot.compute(big_grid.tile_list[0], True)"
]
Expand Down Expand Up @@ -282,8 +282,15 @@
"outputs": [],
"source": [
"# Create the canvas, push the data to it\n",
"canvas_full = jui.Canvas(width=big_tile.sizeX, height=big_tile.sizeY)\n",
"canvas_full.sync_image_data = True\n",
"canvas_full = jui.Canvas(width=big_tile.sizeX, height=big_tile.sizeY, sync_image_data=True)\n",
"def save_canvas_to_file(*args, **kwargs):\n",
" # Uncomment the following line to write image data from canvas to PNG file\n",
" #canvas_full.to_file('./user-images/fractal.png')\n",
" pass\n",
"\n",
"# Listen to changes on the ``image_data`` trait and call ``save_to_file`` when it changes.\n",
"canvas_full.observe(save_canvas_to_file, 'image_data')\n",
"\n",
"with jui.hold_canvas(canvas_full) :\n",
" canvas_full.put_image_data(rgb, 0, 0)\n",
" canvas_full.fill_style=\"#ffffff\" # Set text color\n",
Expand Down Expand Up @@ -311,16 +318,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Save the above canvas as an 8-bit PNG file, canvas.to_file() can have issues for large 4K sized images, use the 2nd method if it does"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"canvas_full.to_file('./user-images/fractal.png')"
"Save the above canvas as an 8-bit PNG file, canvas.to_file() can have issues for large 4K sized images"
]
},
{
Expand All @@ -329,9 +327,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Uncomment alternative and slower method to save to png (but it won't have the text)\n",
"#from skimage.io import imsave\n",
"#imsave('./user-images/fractal.png', rgb.astype(np.uint8)) # rgb is 64-bit float and scaled for 8-bit color"
"# Uncomment alternative and slower method to save to png (but it won't have the ipycanvas text)\n",
"from skimage.io import imsave\n",
"imsave('./user-images/fractal-sk.png', rgb.astype(np.uint8)) # rgb is 64-bit float and scaled for 8-bit color"
]
},
{
Expand Down

0 comments on commit 4220486

Please sign in to comment.