It seems that you cannot get a Graphics image with a height dimension less than 13. Trying to draw something and then asking for the ImageDimensions of the resulting Graphics, you will get three different results, based on the size of the given height.

For example, try to modify the h value in the following code and see the resulting ImageDimensions output (try h=10, h=14, h=20):

w = 100;
h = 10;
g = Graphics[{Red, Line[{{0, 0}, {w, h}}]}, AspectRatio -> Full, ImageSize -> {w, h}]

If you specify an ImageSize with a height >= 15 you will get an ImageDimensions output coherent with the specified size.

Instead, drawing something having an height < 15 produces two unexpected results : for h <= 11 the resulting height dimension is always 13, and for 11 < h < 15, we get some turbulence, see this plot of the resulting ImageDimension for h going from 1 to 32:

w = 100;  
t = Table[{h,ImageDimensions[Graphics[{Line[{{0, 0}, {w, h}}]}, ImageSize -> {w, h}]][[2]]}, {h, 1, 32}];  
TableForm[Transpose@t, TableHeadings -> {{"ImageSize height", "ImageDimensions height"}, None}]  

enter image description here enter image description here

Situation doesn't change applying Options to Graphics. This is a little Manipulate to play around with the stated issue:

w = 100;
 myLine = Graphics[{Blue, Line[{{0, 0}, {w, h}}]}  
   , ImageSize -> {w, h}  
   , AspectRatio -> Full  
   , PlotRangeClipping -> plotRangeClipping  
   , PlotRangePadding -> plotRangePadding  
   , ImagePadding -> imagePadding  
   , ImageMargins -> imageMargins  
 h1 = ImageDimensions[myLine][[2]];  
   Grid[{{"Height:", h}, {"Dimension:", 
      If[h1 == h, Style[h1, Green], Style[h1, Red]]}}],  
 , {{h, 1}, 1, 32, 1}  
 , {plotRangeClipping, {False, True}}  
 , {{plotRangePadding, None}, 0, 20, 1}  
 , {imagePadding, 0, 20, 1}  
 , {imageMargins, 0, 20, 1}  

enter image description here

The problem (bug?) is not with ImageDimensions itself, but with Graphics, that always add a unwanted surrounding space to its output when vertical size is less than 15. Here ImageDimensions is used just to give numeric evidence to the stated problem.

I notice this behavior in all 10.x releases, also the last one (, so it seems possible but improbable that this can be a bug passed unnoticed/unresolved until now, maybe I'm missing to set some (unobvious) parameters, any hints?

  • 1
    $\begingroup$ The usage of ImageDimensions with a general graphic is actually not documented, however I get basically the same threshold issue with ImageDimensions@Image@myLine. What are you trying to do? You can get the graphic dimensions with PlotRange/.AbsoluteOptions[graphic] $\endgroup$ – george2079 Oct 19 '15 at 14:58
  • 1
    $\begingroup$ Thank you George2079, but actually my need isn’t to obtain the dimension of a Graphic by ImageDimensions, in my post the usage of ImageDimensions is just to put in evidence the problem (bug?) in Graphics. My need is to draw some Graphics elements that are smaller than 13 in vertical size, and then put them together in a Column. But as the Graphics output is always filled with the unwanted, unexpected surrounding space when their vertical size is less than 15, these elements result spaced instead to be at the right distance between them. $\endgroup$ – Guido Oct 20 '15 at 9:16
  • 1
    $\begingroup$ I think the issue here relates to rasterization (It appears ImageDimensions is implicitly rasterizering to get your number ). You might want to pose the column issue as a new question. $\endgroup$ – george2079 Oct 20 '15 at 13:55
  • $\begingroup$ @Guido, Based on your last comment, are you aware that ImageSize is not specified in inches? Per the docs you need to multiply image size by 72 to get inches. 13/72nds of an inch is pretty small for a plot. $\endgroup$ – N.J.Evans Oct 20 '15 at 15:07
  • 1
    $\begingroup$ I traced this through various internal functions including System`ConvertersDump`iRasterize, System`ConvertersDump`ToRasterDataPacket, System`ConvertersDump`ConvertGraphicToRasterDataPacket, System`ConvertersDump`createExportPacketExpr, System`ConvertersDump`GetRasterData, and finally System`ConvertersDump`Utilities`GetFromFE. I was unable to find the source of the minimum raster size despite a few promising dead-ends like System`ConvertersDump`PadRaster. This appears to be a property of the Front End itself. $\endgroup$ – Mr.Wizard Feb 19 '17 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.