I am generating a number of graphics using Mathematica that contain text. Adding the text to the graphic has been a considerable challenge, but I have finally come up with the following:

testg = Graphics[{Inset[
   Graphics[Polygon[{{0, 0}, {10, 0}, {10, 10}, {0, 10}}], 
     ImageSize -> {90, 90}], {Left, Center}, {Left, Center}], 
       TextData[{StyleBox["Text One\nText Two\n", 
          FontFamily -> "Arial", FontSize -> 30, 
          TextAlignment -> Left, LineSpacing -> {1, 0}], 
         StyleBox["Text Three", FontFamily -> "Arial", FontSize -> 12,
           TextAlignment -> Left, LineSpacing -> {1, 0}]}]]], 
     ImageSize -> {125, 90}, ImageMargins -> 0, ImagePadding -> None, 
     AspectRatio -> Full], {Right, Center}, {Right, Center}]}, 
  ImageSize -> {220, 90}, AspectRatio -> Full]

You will, no doubt, observe that the final graphic is produced by insetting the actual graphic (for demonstration purposes, I've made it just a rectangle) and then a cell with the text. I have had to size the rectangle to fit the text, and I have manually sized the text though trial and error. The composed image size is that of the two separate graphics with a bit of padding.

My question is, how can I resize this graphic on export? I would like to create much higher resolution images for use in a print environment.

Export["test.png", testg]

Setting the ImageSize on the export works to change the size of the PNG, but does not scale up the two Inset graphics. I need a way of doing this. As I will be producing many, many images, I would like to do this within Mathematica. Any help will be appreciated.

Alternative: I am actually very new to Mathematica, so a I would also be interested in better approach than mine.

  • $\begingroup$ What abut something like Export["test.png", Rasterize[testg, RasterSize -> 1000, ImageResolution -> 1000], ImageSize -> 1000]? $\endgroup$
    – ciao
    Mar 7, 2014 at 11:51
  • $\begingroup$ try exporting "eps", it seems to have the most consistent WYSIWYG rendering . Some of tho other export filters seem to have vastly different interpretations of some of the graphics scale directives. $\endgroup$
    – george2079
    Mar 7, 2014 at 13:08

2 Answers 2


The default image resolution in Mathematica is 72 dpi, as stated in the ImageResolution Details section.

This means your testg graphic with ImageSize -> {220, 90} is about 3 inches wide.

To keep this size and export with print quality resolution TIFF is the best format, although the file sizes are large.

Export["testg.tif", testg, ImageResolution -> 300]

Checking the file details in Paint Shop Pro :-

enter image description here

PNG will also give you a high resolution image for a much smaller file size but you lose control of the image size.

Export["testg.png", testg, ImageResolution -> 300]

You may find PDF format useful if you can import it into your application.

Your graphics will fit together more precisely if you include appropriate plot range specifications. For example in your code, the polygon size will change slightly if you use

Graphics[Polygon[{{0, 0}, {10, 0}, {10, 10}, {0, 10}}], 
 ImageSize -> {90, 90}, PlotRange -> {{0, 10}, {0, 10}}]

The following is more like how I would set up your image :-

poly = Graphics[Polygon[{{0, 0}, {10, 0}, {10, 10}, {0, 10}}],
   ImageSize -> {90, 90}, PlotRange -> {{0, 10}, {0, 10}}];

text = TextCell[Row[{
     Style["Text One\nText Two\n", FontSize -> 30],
     Style["Text Three", FontSize -> 12]}],
   FontFamily -> "Arial", LineSpacing -> {1, 0}];

textg = Graphics[{Yellow, Rectangle[{0, 0}, {220, 90}], Black,
   Inset[poly, {Left, Center}, {Left, Center}, {90, 90}],
   Inset[text, {Right, Center}, {Right, Center}]},
  ImageSize -> {220, 90}, PlotRange -> {{0, 220}, {0, 90}}]

enter image description here

There is a different example here.

  • $\begingroup$ This is the correct answer, based on how I asked the question. It will only, of course, scale bitmaps and not vector images. Thanks. $\endgroup$
    – Richard
    Mar 8, 2014 at 8:58
  • $\begingroup$ Also, thanks for the ideas on how to simplify the graphics down. $\endgroup$
    – Richard
    Mar 8, 2014 at 9:13

Although Chris Degnen's answer is correct, it doesn't permit you to scale when exporting to a vector format. In case others come here looking for a way to scale vectors, I offer the following answer. While reading up on the documentation for ImageResolution, I discovered the function Magnify which permits you to scale up any expression.

It is easily possible to write a small wrapper function using ImageDimensions and Magnify which together permit you to scale Graphics to an arbitrary size. Something like:

scale = newxdim / ImageDimensions[testg][[1]];
Magnify[testg, scale]

This can then be exported as needed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.