---
title: "Rasterize"
language: "en"
type: "Symbol"
summary: "Rasterize[expr] returns a rasterized version of the displayed form of expr. Rasterize[expr, elem] gives the element elem associated with the rasterized form of expr. Rasterize[expr, {elem1, elem2, ...}] gives a list of the specified elemi."
keywords: 
- rasterizing graphics
- rasterizing 3D graphics
- rasterizing formulas
- rasterizing programs
canonical_url: "https://reference.wolfram.com/language/ref/Rasterize.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graphics Transformations"
    link: "https://reference.wolfram.com/language/guide/GraphicsTransformations.en.md"
  - 
    title: "Image Computation: Update History"
    link: "https://reference.wolfram.com/language/guide/ImageComputation-UpdateHistory.en.md"
  - 
    title: "Image Processing & Analysis"
    link: "https://reference.wolfram.com/language/guide/ImageProcessing.en.md"
  - 
    title: "Creating & Importing Images"
    link: "https://reference.wolfram.com/language/guide/CreatingAndImportingImages.en.md"
  - 
    title: "Tuning & Debugging"
    link: "https://reference.wolfram.com/language/guide/TuningAndDebugging.en.md"
related_workflows: 
  - 
    title: "Combine Multiple Images"
    link: "https://reference.wolfram.com/language/workflow/CombineMultipleImages.en.md"
related_functions: 
  - 
    title: "Image"
    link: "https://reference.wolfram.com/language/ref/Image.en.md"
  - 
    title: "Export"
    link: "https://reference.wolfram.com/language/ref/Export.en.md"
  - 
    title: "ExportString"
    link: "https://reference.wolfram.com/language/ref/ExportString.en.md"
  - 
    title: "Graphics"
    link: "https://reference.wolfram.com/language/ref/Graphics.en.md"
  - 
    title: "Magnify"
    link: "https://reference.wolfram.com/language/ref/Magnify.en.md"
  - 
    title: "Rotate"
    link: "https://reference.wolfram.com/language/ref/Rotate.en.md"
  - 
    title: "Antialiasing"
    link: "https://reference.wolfram.com/language/ref/Antialiasing.en.md"
  - 
    title: "CurrentNotebookImage"
    link: "https://reference.wolfram.com/language/ref/CurrentNotebookImage.en.md"
  - 
    title: "CurrentScreenImage"
    link: "https://reference.wolfram.com/language/ref/CurrentScreenImage.en.md"
  - 
    title: "WebImage"
    link: "https://reference.wolfram.com/language/ref/WebImage.en.md"
---
# Rasterize

Rasterize[expr] returns a rasterized version of the displayed form of expr.

Rasterize[expr, elem] gives the element elem associated with the rasterized form of expr. 

Rasterize[expr, {elem1, elem2, …}] gives a list of the specified elemi.

## Details and Options

* The expression ``expr`` can be graphics, text, a cell, a notebook object or any other expression.

* ``Rasterize[nb]`` gives a rasterized version of the complete content associated with the notebook object ``nb``.

* Possible basic elements that can be returned by ``Rasterize`` include:

|               |                                            |
| ------------- | ------------------------------------------ |
| "BoundingBox" | bounding box information for the raster    |
| "Data"        | the array of pixel values in the raster    |
| "Graphics"    | a graphics object representing the raster  |
| "Image"       | an image object representing the raster    |
| "RasterSize"  | pixel width and height of the raster       |
| "Regions"     | regions specified by Annotation constructs |

* ``Rasterize[expr]`` is equivalent to ``Rasterize[expr, "Image"]`` and displays in a notebook in a way that approximates the unrasterized display of ``expr``, with the same image size.

* An expression displayed at a given ``size`` at the default screen resolution ``res`` will result in a raster of dimension $\text{\textit{size}}\times \text{\textit{res}}/72$.

* The following options for ``Rasterize`` can be given:

|                       |                        |                                                 |
| :-------------------- | :--------------------- | :---------------------------------------------- |
| Background            | Automatic              | background to use                               |
| BaselinePosition      | Automatic              | how to align with a surrounding text baseline   |
| ImageFormattingWidth  | \$ImageFormattingWidth | wrapping width for expressions to be rasterized |
| ImageResolution       | \$ImageResolution      | image resolution in dpi for rasterization       |
| ImageSize             | Automatic              | final displayed image size in printer's points  |
| LightDark             | Inherited              | whether to rasterize in light or dark mode      |
| RasterSize            | Automatic              | raster size in pixels for rasterization         |

* ``RasterSize`` and ``ImageResolution`` determine the coarseness of rasterization; ``ImageSize`` determines the size at which the final image will be displayed.

* If there is an explicit setting for ``RasterSize``, it overrides any explicit setting for ``ImageResolution``.

* When the settings for ``RasterSize`` or ``ImageResolution`` are small, the graphic will appear coarse, and text may be illegible. There may also be artifacts associated with aliasing.

* Settings for ``ImageSize`` and ``Background`` in ``Rasterize`` override any settings for those options in ``expr``.

* ``Background -> None`` yields a raster with a transparent background.

* If no explicit size or resolution option settings are given, ``Rasterize[expr, …]`` will rasterize ``expr`` at the size and resolution it would normally be displayed in a notebook.

* ``Rasterize[expr, "RasterSize"]`` yields ``{w, h}``, where ``w`` is the overall width in pixels of the raster, and ``h`` is its overall height.

* ``Rasterize[expr, "BoundingBox"]`` yields ``{w, h, dh}``, where ``w`` is the overall width, ``h`` is the overall height, and ``dh`` is the offset of the baseline of the contents of ``expr`` from the bottom of its bounding box.

* Images generated by ``Rasterize`` can vary slightly from one computer system to another, mainly as a result of different fonts and anti-aliasing procedures.

* The results from ``Rasterize[expr, "BoundingBox"]`` can depend on details of font metrics, which generally differ between different computer systems.

* ``Rasterize[expr, "Regions"]`` gives a list of rules of the form ``{{a1, type1} -> reg1, {a2, type2} -> reg2, …}``, where each rule ``{ai, typei} -> regi`` is associated with an annotation of the form ``Annotation[expr, ai, typei]`` in ``expr``, or with an object that is automatically recognized as an annotation, such as a ``Hyperlink`` or ``Tooltip``. The ``regi`` give pixel positions in the form ``{{xmin, ymin}, {xmax, ymax}}``, where ``y`` coordinates run from top to bottom, mirroring the ``coords`` attribute of HTML.

* The default setting of ``LightDark -> Inherited`` uses the default light-dark setting of the notebook running the evaluation. If the evaluation was not started from a specific notebook, it uses the default light-dark setting of the notebook front end.

---

## Examples (36)

### Basic Examples (3)

Make a 15-pixel-wide rasterization of an image of a disk:

```wl
In[1]:= Rasterize[[image], RasterSize -> 15]

Out[1]= [image]
```

---

Make a 75-pixel-wide rasterization of text, and display it 200 pixels wide:

```wl
In[1]:= Rasterize[x ^ 2 + y ^ 2, RasterSize -> 75, ImageSize -> 200]

Out[1]= [image]
```

---

Make a 36 dpi rasterization of a 3D graphic with light yellow background:

```wl
In[1]:= Rasterize[Graphics3D[Cylinder[], ImageSize -> Small], ImageResolution -> 36, Background -> LightYellow]

Out[1]= [image]
```

### Scope (11)

Convert any Wolfram Language expression into a raster graphic:

```wl
In[1]:= Rasterize[Graphics3D[Sphere[]], RasterSize -> 150, ImageSize -> 150]

Out[1]= [image]
```

The default output is a raster graphic:

```wl
In[2]:= Short[InputForm[%], 2]

Out[2]//Short= "Image[NumericArray[{{{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, <<146>>, {255, 255, 255}}, <<162>>}, <<1>>], <<6>>]"
```

---

Get the bounding box information:

```wl
In[1]:= Rasterize[Grid@Table[x, {5}, {10}], "BoundingBox"]

Out[1]= {156, 81, 44}
```

---

Get the array of pixel values for the raster:

```wl
In[1]:= Rasterize[Grid@Table[x, {5}, {10}], "Data"]//Short

Out[1]//Short= {{{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, «307», {255, 255, 255}, {255, 255, 255}}, «161», {«1»}}

In[2]:= Graphics[Raster[%, Automatic, {0, 255}]]

Out[2]= [image]
```

---

Get the raster graphic:

```wl
In[1]:= Rasterize[Grid@Table[x, {5}, {10}], "Graphics"]

Out[1]= [image]
```

---

Get the pixel dimensions of the raster:

```wl
In[1]:= Rasterize[Grid@Table[x, {5}, {10}], "RasterSize"]

Out[1]= {312, 162}
```

---

Get both the raster graphic and its pixel dimensions:

```wl
In[1]:=
Rasterize[PolarPlot[Sin[3t], {t, 0, Pi}, ImageSize -> Tiny], 
	{"Graphics", "RasterSize"}]

Out[1]= {[image], {200, 185}}
```

---

Define regions using ``Annotation`` :

```wl
In[1]:= e = Graphics[{Red, Annotation[Disk[], "Red", "Region"], Blue, Annotation[Disk[{3, 0}], "Blue", "Region"]}, ImageSize -> 100]

Out[1]= [image]
```

Get the defined regions:

```wl
In[2]:= Rasterize[e, "Regions"]

Out[2]= {{"Red", "Region"} -> {{2., 1.92}, {40.4, 40.32}}, {"Blue", "Region"} -> {{59.6, 1.92}, {98., 40.32}}}
```

Display the regions using rectangles:

```wl
In[3]:= Show[Rasterize[e], Graphics[{FaceForm[], EdgeForm[Black], Rectangle@@Last@#& /@ Rasterize[e, "Regions"]}], ImageSize -> 100]

Out[3]= [image]
```

---

Set background color:

```wl
In[1]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], Background -> LightBlue]

Out[1]= [image]
```

---

Set image resolution:

```wl
In[1]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], ImageResolution -> 20]

Out[1]= [image]
```

---

Set raster size in pixels:

```wl
In[1]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], RasterSize -> 100]

Out[1]= [image]
```

---

``RasterSize`` overrides ``ImageResolution`` :

```wl
In[1]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], RasterSize -> 100, ImageResolution -> 20]

Out[1]= [image]
```

### Options (14)

#### Background (2)

Set background color:

```wl
In[1]:= Rasterize[Graphics3D[Cylinder[]], ImageSize -> 120, Background -> LightGreen]

Out[1]= [image]
```

---

By default, the background is opaque white:

```wl
In[1]:= Show[Graphics[{Cyan, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}], Rasterize[Graphics3D[Cylinder[]]], ImageSize -> 120]

Out[1]= [image]
```

Make the background transparent by setting ``Background -> None`` :

```wl
In[2]:= Show[Graphics[{Cyan, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}], Rasterize[Graphics3D[Cylinder[]], Background -> None], ImageSize -> 120]

Out[2]= [image]
```

#### ImageFormattingWidth (2)

Line wrap at different widths:

```wl
In[1]:= Table[Rasterize[Framed@Range[10], ImageFormattingWidth -> d], {d, {50, 100, 200, 400}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Do not line wrap:

```wl
In[1]:= Rasterize[NestList[# + (1/#)&, x, 4], ImageFormattingWidth -> ∞, Background -> LightRed]

Out[1]= [image]
```

#### ImageResolution (3)

The default resolution is determined by the current display settings:

```wl
In[1]:=
Rasterize[Style["Text", 40]]
Options[%, ImageResolution]

Out[1]= [image]

Out[1]= {ImageResolution -> 144.}
```

Use ``ImageResolution`` to specify the desired resolution:

```wl
In[2]:=
Rasterize[Style["Text", 40], ImageResolution -> 300]
Options[%, ImageResolution]

Out[2]= [image]

Out[2]= {ImageResolution -> 300.}
```

Use a low resolution:

```wl
In[3]:= Rasterize[Style["Text", 40], ImageResolution -> 30]

Out[3]= [image]
```

---

Image resolution affects the raster size but not the display size of the expression:

```wl
In[1]:= Rasterize[Style["Text", 40], "Image", ImageResolution -> #]& /@ {50, 100, 200}

Out[1]= {[image], [image], [image]}
```

Raster size at different resolutions:

```wl
In[2]:= Rasterize[Style["Text", 40], "RasterSize", ImageResolution -> #]& /@ {50, 100, 200}

Out[2]= {{67, 35}, {133, 70}, {267, 140}}
```

Display size at different resolutions:

```wl
In[3]:= Rasterize[Style["Text", 40], "BoundingBox", ImageResolution -> #]& /@ {50, 100, 200}

Out[3]= {{96, 50, 40}, {96, 50, 40}, {96, 50, 40}}
```

---

``RasterSize`` overrides ``ImageResolution`` :

```wl
In[1]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], RasterSize -> 100, ImageResolution -> 20]

Out[1]= [image]
```

Low-resolution rasterization with the automatic raster size:

```wl
In[2]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], ImageResolution -> 20, RasterSize -> Automatic]

Out[2]= [image]
```

#### ImageSize (2)

By default, rasterized expressions are returned at their original display size:

```wl
In[1]:= list = Graphics[Triangle[], ImageSize -> #]& /@ {80, 100, 120}

Out[1]= {[image], [image], [image]}

In[2]:= Rasterize /@ list

Out[2]= {[image], [image], [image]}
```

Use the ``ImageSize`` option to set a specific display size:

```wl
In[3]:= Rasterize[#, ImageSize -> 40]& /@ list

Out[3]= {[image], [image], [image]}
```

---

The ``ImageSize`` option overrides any previous settings in the expression being rasterized:

```wl
In[1]:= g = Plot[x Sin[x], {x, 0, 1}, ImageSize -> 300]

Out[1]= [image]

In[2]:= Rasterize[g, ImageSize -> #]& /@ {100, 200}

Out[2]= {[image], [image]}

In[3]:= ImageDimensions /@ %

Out[3]= {{200, 124}, {400, 245}}
```

If an expression does not have a scalable display size, ``ImageSize`` is only setting the final display size:

```wl
In[4]:= Rasterize[Style["Text", 40], ImageSize -> #]& /@ {100, 200}

Out[4]= {[image], [image]}

In[5]:= ImageDimensions /@ %

Out[5]= {{192, 101}, {192, 101}}
```

#### LightDark (2)

Rasterize some text assuming light mode:

```wl
In[1]:= Rasterize["abc", LightDark -> "Light"]

Out[1]= [image]
```

Rasterize assuming dark mode:

```wl
In[2]:= Rasterize["abc", LightDark -> "Dark"]

Out[2]= [image]
```

---

``LightDarkSwitched`` respects the setting of the ``LightDark`` option:

```wl
In[1]:=
g = Graphics[{LightDarkSwitched[Red, Green], Disk[]}];
{Rasterize[g, LightDark -> "Light"], Rasterize[g, LightDark -> "Dark"]}

Out[1]= {[image], [image]}
```

#### RasterSize (3)

The default raster size is determined by the display size of the expression and the resolution settings:

```wl
In[1]:=
Rasterize[Style["Text", 40]]
ImageDimensions[%]

Out[1]= [image]

Out[1]= {192, 101}
```

Use ``RasterSize -> w`` to specify an explicit image width:

```wl
In[2]:=
Rasterize[Style["Text", 40], RasterSize -> 100]
ImageDimensions[%]

Out[2]= [image]

Out[2]= {100, 52}
```

Use ``RasterSize -> {w, h}`` to specify both width and height:

```wl
In[3]:=
Rasterize[Style["Text", 40], RasterSize -> {100, 60}]
ImageDimensions[%]

Out[3]= [image]

Out[3]= {100, 60}
```

---

Set different raster sizes in pixels:

```wl
In[1]:= Table[Rasterize[Style[x ^ 2 + y ^ 2, 40], RasterSize -> r], {r, {30, 50, 200}}]

Out[1]= {[image], [image], [image]}
```

---

``RasterSize`` overrides ``ImageResolution``. Use the default ``RasterSize`` :

```wl
In[1]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], ImageResolution -> 20]

Out[1]= [image]
```

Check the size of the raster:

```wl
In[2]:= ImageDimensions[%]

Out[2]= {44, 18}
```

Specify the ``RasterSize`` :

```wl
In[3]:= Rasterize[Style[x ^ 2 + y ^ 2, 50], ImageResolution -> 20, RasterSize -> 100]

Out[3]= [image]

In[4]:= ImageDimensions[%]

Out[4]= {100, 40}
```

### Applications (3)

Image of the first 1000 letters from the US Constitution:

```wl
In[1]:= txt = Import["ExampleData/USConstitution.txt"];

In[2]:= Rasterize[Text@StringTake[txt, 1000], RasterSize -> 600, ImageSize -> 300, Background -> LightBlue]

Out[2]= [image]
```

---

Thumbnail of a Wolfram System notebook:

```wl
In[1]:= nb = Import["ExampleData/document.nb"];

In[2]:= Rasterize[nb, ImageSize -> 300]

Out[2]= [image]
```

---

Rasterize a line segment with grid lines:

```wl
In[1]:= lines[Antialiasing -> a_] := Table[Show[Rasterize[Graphics[Style[Line[{{0, 0}, {x, 1}}], Antialiasing -> a]], Background -> None, RasterSize -> 20, ImageSize -> 20], Frame -> True, FrameTicks -> False, GridLines -> Function[{m, M}, Range[Floor[m], Ceiling[M]]], GridLinesStyle -> Directive[Black, Opacity[.1]], ImageSize -> 100], {x, 6}]
```

With antialiasing:

```wl
In[2]:= lines[Antialiasing -> True]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Without antialiasing:

```wl
In[3]:= lines[Antialiasing -> False]

Out[3]= {[image], [image], [image], [image], [image], [image]}
```

### Properties & Relations (2)

Rasterizing a graphic with a custom ``ImageSize`` option works by changing the graphic's ``ImageSize``, not by magnifying the graphic:

```wl
In[1]:= g = Graphics[Text[Style["Some text", FontSize -> 20], {0, 0}], Background -> LightGreen, ImageSize -> 80];

In[2]:= Grid[{{g, Rasterize[g, ImageSize -> 160]}}]

Out[2]= [image]	[image]
```

A graphic embedded in a non-graphical construct will magnify instead:

```wl
In[3]:= Grid[{{g, Rasterize[Text[g], ImageSize -> 160]}}]

Out[3]= [image]	[image]
```

---

Rasterizing a ``Cell`` expression displays the cell's contents as the Wolfram System front end would:

```wl
In[1]:= Rasterize[Cell["Wolfram", "ExampleText"]]

Out[1]= [image]
```

Properties of the cell that affect the contents will be displayed:

```wl
In[2]:= Rasterize[Cell["Wolfram", "ExampleText", FontSize -> 20, Background -> LightOrange]]

Out[2]= [image]
```

Properties that only affect margins or cell-level decorations will not be displayed:

```wl
In[3]:= Rasterize[Cell["Wolfram", "ExampleText", CellMargins -> 50, CellFrame -> True, CellFrameLabels -> {{"1", "2"}, {"3", "4"}}]]

Out[3]= [image]
```

### Possible Issues (1)

Because ``ImageSize`` is in points, it may not correspond to the pixel dimensions of the resulting image:

```wl
In[1]:= Rasterize[Graphics[Circle[]], ImageSize -> 40]//ImageDimensions

Out[1]= {80, 80}
```

To specify the pixel dimensions, use ``RasterSize`` :

```wl
In[2]:= Rasterize[Graphics[Circle[]], RasterSize -> 40]//ImageDimensions

Out[2]= {40, 40}
```

### Interactive Examples (1)

Interactively change the rasterization parameters:

```wl
In[1]:=
Manipulate[Rasterize[Graphics[Table[{Hue[t / 20], Circle[{Cos[2Pi t / 20], Sin[2Pi t / 20]}]}, {t, 20}], Frame -> True], ImageSize -> size, ImageResolution -> dpi], 
	{{size, 150}, 30, 300}, 
	{{dpi, 82}, 30, 300}
	]

Out[1]= DynamicModule[«8»]
```

### Neat Examples (1)

Pages from the US Constitution:

```wl
In[1]:= txt = Import["ExampleData/USConstitution.txt"];

In[2]:= Grid@Partition[Table[Rasterize[Framed[Style[StringTake[txt, {2000s + 1, 2000(s + 1)}], LineIndent -> 0], FrameMargins -> 10], RasterSize -> 100, ImageSize -> 50], {s, 0, Quotient[StringLength[txt], 2000] - 1}], 7]

Out[2]=
|         |         |         |         |         |         |         |
| ------- | ------- | ------- | ------- | ------- | ------- | ------- |
| [image] | [image] | [image] | [image] | [image] | [image] | [image] |
| [image] | [image] | [image] | [image] | [image] | [image] | [image] |
| [image] | [image] | [image] | [image] | [image] | [image] | [image] |
```

## See Also

* [`Image`](https://reference.wolfram.com/language/ref/Image.en.md)
* [`Export`](https://reference.wolfram.com/language/ref/Export.en.md)
* [`ExportString`](https://reference.wolfram.com/language/ref/ExportString.en.md)
* [`Graphics`](https://reference.wolfram.com/language/ref/Graphics.en.md)
* [`Magnify`](https://reference.wolfram.com/language/ref/Magnify.en.md)
* [`Rotate`](https://reference.wolfram.com/language/ref/Rotate.en.md)
* [`Antialiasing`](https://reference.wolfram.com/language/ref/Antialiasing.en.md)
* [`CurrentNotebookImage`](https://reference.wolfram.com/language/ref/CurrentNotebookImage.en.md)
* [`CurrentScreenImage`](https://reference.wolfram.com/language/ref/CurrentScreenImage.en.md)
* [`WebImage`](https://reference.wolfram.com/language/ref/WebImage.en.md)

## Related Guides

* [Graphics Transformations](https://reference.wolfram.com/language/guide/GraphicsTransformations.en.md)
* [Image Computation: Update History](https://reference.wolfram.com/language/guide/ImageComputation-UpdateHistory.en.md)
* [Image Processing & Analysis](https://reference.wolfram.com/language/guide/ImageProcessing.en.md)
* [Creating & Importing Images](https://reference.wolfram.com/language/guide/CreatingAndImportingImages.en.md)
* [Tuning & Debugging](https://reference.wolfram.com/language/guide/TuningAndDebugging.en.md)

## Related Workflows

* [Combine Multiple Images](https://reference.wolfram.com/language/workflow/CombineMultipleImages.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Strings and Text](https://www.wolfram.com/language/elementary-introduction/11-strings-and-text.html)
* [An Elementary Introduction to the Wolfram Language: Arrays, or Lists of Lists](https://www.wolfram.com/language/elementary-introduction/13-arrays-or-lists-of-lists.html)
* [An Elementary Introduction to the Wolfram Language: Machine Learning](https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html)

## History

* [Introduced in 2007 (6.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn60.en.md) \| [Updated in 2008 (7.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn70.en.md) ▪ [2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) ▪ [2017 (11.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn112.en.md) ▪ [2020 (12.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn121.en.md) ▪ [2025 (14.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn143.en.md)