Controlling Your Drawing's Pixel Dimensions
- Michael Horvath
Let me start by describing these last two points. The points
Export_2define the area of your drawing that will be made visible when you export it as an SVG or PNG image file. Contents outside the box defined by these two points will be cropped or otherwise be made invisible. Contents inside this box will appear in the exported image. The points should be located at opposite corners of the box, or else the export area will be a one-dimensional straight line. In the worksheet above I have made
Export_2visible, and have added two more points and several segments to show you the extents of this box. Before saving your document you will probably want to hide these objects, or else parts of them will appear in the exported image. The next thing you need to do is create a slider to set the scale of your drawing. I named mine "PixelsPerUnit", and configured the slider to fit within the range of 0 to 500. Lastly, you need to create a button to trigger a script that will resize the drawing. Attached to the button click in the "Scripting" tab should be the following GeoGebra code:
ZoomIn(CopyFreeObject(x(Export_1)),CopyFreeObject(y(Export_1)-y(Corner(5)+(2,2))/PixelsPerUnit),CopyFreeObject(x(Export_1)+x(Corner(5)+(2,2))/PixelsPerUnit),CopyFreeObject(y(Export_1)))Now, when you press the button, the drawing will be shifted so that the
Export_1point is in the top-left corner of the drawing, and the dimensions of the drawing will be the size in GeoGebra units multiplied by the value of "PixelsPerUnit" slider. In the example drawing above, the size of the export area is -1.25 to +1.25 units along the x and y axes, and the slider is set to 150 pixels per unit. Thus the dimensions of the exported image should equal 375 by 375 pixels.
Firstly, if you are using GeoGebra 5 Classic, when you export the PNG or SVG image, you will need to select the "Size in pixels" option from the drop-down menu of the export dialog. If you are using GeoGebra 6 Classic, I think this is done automatically for you. Secondly, sometimes the dimensions of the exported image are off the mark by a pixel or two. For instance, the dimensions of the above drawing may end up being 376 by 375 pixels instead of 375 by 375 pixels. There's no real way to avoid this as far as I know.