National Oceanic and
Atmospheric Administration
United States Department of Commerce

controlling the size of GIF or PNG output

controlling the size of GIF or PNG output


If I need a particular size GIF or PNG output file, say 600x800, how do I go about calculating the SET WINDOW/SIZE, SET WINDOW/ASPECT values?


You can get any size gif you want, using SET WINDOW/SIZE and SET WINDOW/ASPECT, and the Ferret symbols PPL$XPIXEL and PPL$YPIXEL to check what size the GIF output is.

The PyFerret SET WINDOW command offers inch settings or pixel settings with qualifiers /XINCHES/YINCHES/ASPECT and /XPIXELS/YPIXELS/ASPECT.

Ferret sets the pixel symbols when a plot is drawn. We will use these symbols to resetthe size of the window to the desired width and height. SET WINDOW/ASPECT=y_over_x sets the ratio of the height to the width of the window. SET WINDOW/SIZE=0.7*frac rescales the area of the plot window to frac times the area of the default window.

When running with an X-window server, gif images are grabbed back from the output window.This can give inconsistent results. Run Ferret in -gif mode. (Note that prior to Ferret v5.8the symbols PPL$XPIXEL and PPL$YPIXEL were not available when in -gif mode.)


For example, to make a gif that is 800 pixels wide and 600 high, first make a test plot with the correct aspect ratio.

 > ferret -gif
 yes? set window/aspect=0.75
 yes? shade/i=1:10/j=1:15 i+j
 yes? show symbol ppl$xpixel
 PPL$XPIXEL = "824"
 yes? show symbol ppl$ypixel
 PPL$YPIXEL = "617"

Now, reset the size of the plot. The default window size is 0.7, and the SET WINDOW/SIZE=qualifier takes an argument which is the area of the plot window. Reset the default size of0.7 to default_size*(desired_pixel_size/current_pixel_size), or 0.7*(600*800)/(($ppl$xpixel)*($ppl$ypixel))

Once we reset the size, redraw the plot and save it as a gif file.

 yes? set window/aspect=0.75/size=`0.7*(600*800)/(($ppl$xpixel)*($ppl$ypixel))`
 !-> set window/aspect=0.75/size=0.66089
 yes? shade/i=1:10/j=1:15 i+j
 yes? frame/file=test.gif
 yes? show symbol ppl$xpixel
 PPL$XPIXEL = "800"
 yes? show symbol ppl$ypixel
 PPL$YPIXEL = "600"

 yes? exit

Check the size of the gif with a tool like xv, or the identify command from ImageMagick.

 > identify test.gif
 test.gif 800x600+0+0 PseudoClass 32c 10084b GIF 1s