WLJS LogoWLJS Notebook

Rasterize

Wolfram Kernel
Rasterize[expression_, opts___]
Rasterize[expression_, form_, opts___]

Rasterizes any expression using the frontend as it is rendered in a cell. The default output form is Image.

Requires Desktop App for rasterizing (not available in server mode). It literally takes a screenshot of a specific area.

Blocking function. Avoid using it in timers like SetTimeout, external event handlers such as InputButton or Button, or within AsyncFunction. Use RasterizeAsync instead.

Options

RasterSize

Controls the pixel size of the rasterized result.

Rasterize[Plot[Sin[x], {x, 0, 2 Pi}], RasterSize -> 600]

"Notebook"

Optionally provide notebook object (generated by EvaluationNotebook) if you have used HTML, WLX, JS outputs in the provided expression.

"ExposureTime"

Sets the time in seconds for asynchronous frontend elements to finish rendering before capture. Increase it when labels, legends, insets, LaTeX, or other elements are missing from the rasterized result. The default is 1.

Rasterize[expression, "ExposureTime" -> 6]

Output forms

The second argument selects the returned representation. Use "Image" for an image expression or "Graphics" for raster data wrapped in Graphics:

Rasterize[Plot[Sin[x], {x, 0, 2 Pi}], "Graphics", RasterSize -> 300]

Provide a list to return multiple representations from the same capture:

result = Rasterize[Plot[Sin[x], {x, 0, 2 Pi}],
  {"Image", "Graphics"}, RasterSize -> 300];

Head /@ result
Output
{Image, Graphics}

Application

Can be used to export graphics to raster format try

Rasterize[x+y]

And then you can freely export it to an image file

Export["image.png", %]

On this page