Function Repository Resource:

RasterizeGraphicsCells

Source Notebook

Convert cells with graphics to bitmaps

Contributed by: Nikolay Murzin

ResourceFunction["RasterizeGraphicsCells"][]

rasterizes every cell with graphics in the current notebook.

ResourceFunction["RasterizeGraphicsCells"][nb]

rasterizes graphics cells in the specified notebook object.

ResourceFunction["RasterizeGraphicsCells"]["patt"]

rasterizes graphics cells in notebooks returned by Notebooks["patt"].

ResourceFunction["RasterizeGraphicsCells"][cell]

rasterizes a CellObject or a list of CellObjects.

Details and Options

ResourceFunction["RasterizeGraphicsCells"] takes a Method option, with possible values of Automatic and "FrontEnd". The default value of Automatic ensures a consistent resolution across platforms.
The setting Method "FrontEnd" uses the current screen resolution to rasterize, which is equivalent to using the menu item CellConvert ToBitmap for conversion.

Examples

Basic Examples (3) 

Rasterize all the graphics in a notebook:

In[1]:=
ResourceFunction["RasterizeGraphicsCells"][
 NotebookOpen[FindFile["ExampleData/document.nb"]]]

Now all the cells with graphics in the notebook are bitmap images:


Rasterize all graphics in the current notebook:

In[2]:=
ResourceFunction["RasterizeGraphicsCells"][]

Create a large output, then rasterize it:

In[3]:=
Graph3D[RandomGraph[{2^10, 2^12}]]
Out[3]=
In[4]:=
ResourceFunction["RasterizeGraphicsCells"][PreviousCell[]]

Applications (2) 

Create a notebook with huge graphic cells. This may take a couple minutes:

In[5]:=
nb = CreateDocument[{
    ExpressionCell[UnlabeledTree@RandomTree[2^12]],
    ExpressionCell[RandomGraph[{2^12, 2^13}]],
    ExpressionCell[Graph3D@RandomGraph[{2^12, 2^14}]]
    }];
In[6]:=
ByteCount[NotebookRead@Cells[nb]]
Out[6]=

RasterizeGraphicsCells can save considerable space and improve rendering time:

In[7]:=
ResourceFunction["RasterizeGraphicsCells"][nb];
In[8]:=
ByteCount[NotebookRead@Cells[nb]]
Out[8]=

Version History

  • 1.0.0 – 19 August 2022

Related Resources

License Information