7
$\begingroup$

I want to export an image exactly as it is shown in the notebook, but when I specify a high image resolution, the image saved to disk does not match what is shown in the notebook (the image saved appears to be an uncropped version of the image). I am running the following code to produce the graphic:

polygonSwirl[
   polygon_: Disk[], thickness_: .8, depth_: 20,   color_: Blue,
   edgeColor_: Black, scalingRate_: .2, xtranslationRate_: .2,
   ytranslationRate_: .2, background_: White, rotationRate_: 1, 
   rotPoint_: {1, 1},  rotModifier_: 5
   ] := Graphics[{EdgeForm[
     Directive[{AbsoluteThickness[thickness], edgeColor}]], color,
    GeometricTransformation[
     polygon,
     Table[
      ScalingTransform[{α/(depth - α)^scalingRate,
                        α/(depth - α)^scalingRate}].TranslationTransform[{-α^
           xtranslationRate, α^ytranslationRate}].RotationTransform[π/(depth - \
α)^rotationRate, rotPoint + rotModifier/α],
      {α, (depth - 1), 1, -1}]
     ],
    }, Background -> background, PlotRangeClipping -> True
   ];

polygonSwirl[
 polygon = Disk[],
 thickness = .4,
 depth = 100,
 color = LightPink,
 edgeColor = Lighter@Purple,
 scalingRate = -.1,
 xtranslationRate = -1,
 ytranslationRate = -1,
 background = LightPink,
 rotationRate = -.999,
 rotPoint = {0, 0},
 rotModifier = 5
 ]

The output shown (I took a screenshot) is

screenshot of notebook output

But the image saved to disk when I run this code is different:

 Export["~/Desktop/diskSwirl.png", %, ImageResolution -> 500]  

enter image description here

How do I ensure that the image exported matches what is shown in the notebook exactly? Screenshots do not have high enough resolution for my purposes.

$\endgroup$
  • 1
    $\begingroup$ I get the same behaviour (MMA10.2, OSX) . And when I manually resize the graphic in the notebook, the figure changes continuously whether i make it smaller or bigger ! Do you observe the same ? It strongly reminds this bug ... $\endgroup$ – SquareOne Aug 4 '15 at 21:31
  • $\begingroup$ Yes, the composition of the shapes changes as well. If you provide more complicated inputs to the function (increase the depth parameter) this becomes more apparent. And more bothersome! $\endgroup$ – Zakir Gowani Aug 4 '15 at 21:50
  • $\begingroup$ Hmmm I think this must have to do with Graphics, not Export. It must be redrawing the figure based on canvas size. $\endgroup$ – Zakir Gowani Aug 4 '15 at 22:10
  • $\begingroup$ Make the image the Import of the Export: img = Import[Export["~/Desktop/diskSwirl.png", polygonSwirl[polygon = Disk[], thickness = .4, depth = 100, color = LightPink, edgeColor = Lighter@Purple, scalingRate = -.1, xtranslationRate = -1, ytranslationRate = -1, background = LightPink, rotationRate = -.999, rotPoint = {0, 0}, rotModifier = 5], ImageResolution -> 500]] $\endgroup$ – Bob Hanlon Aug 4 '15 at 23:39
  • $\begingroup$ I added an answer indicating why I think this is a bug in the notebook display. It could well be related to what @SquareOne mentioned. $\endgroup$ – Jens Aug 5 '15 at 6:18
6
$\begingroup$

Although you have set the option PlotRangeClipping -> True, you didn't actually specify a PlotRange. This forces Graphics to determine the appropriate range automatically. The default for PlotRange is All, so the result of the Export command is actually correct. The notebook display is not correct.

But if you want the notebook display to show the cropping, and the exported graphic to have the same appearance, you have to override the default by setting PlotRange -> {{-100, 100}, {-100, 100}} (or a similar range).

The fact that the cropping is a bug can be checked by replacing Disk with Rectangle in your code. Then the output in the notebook is not cropped:

swirl2

So the automatic calculation of PlotRange in the case of transformed Disks is done incorrectly, but for Rectangles it works.

$\endgroup$

Your Answer

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

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