Fanning Software Consulting

Raster File Output Dimensions

Facebook Twitter RSS Google+

QUESTION: I love the way the raster file output from Coyote Graphics routines uses such nice fonts and looks so good. But, I want to put this output into my web pages and this is difficult to do when each output file is slightly different in terms of its pixel size. What do I have to do to control the output dimensions of the raster files?

ANSWER: One of the tenets of Coyote Graphics is that if and when you create raster file output from a graphics window, it should look as much as possible like the contents of the graphics window (in truth, it always looks much better, because it uses nicer PostScript fonts). As you know, this is done via PostScript intermediary files with raster conversion via ImageMagick.

The way I did this when I first introduced Coyote Graphics routines resulted in raster file output that was approximately the size of the graphics window, but there was no exact control over the dimensions of the final raster file. This lack of control has made it difficult to produce graphical output for inclusion on web pages, where it would be convenient for all raster images to have the same relative size.

To address this problem, I have added a new Width keyword to cgPS_Closein an April 3rd, 2012 update to the Coyote Library. With this keyword, it is possible to specify the final output width of raster file output created with ImageMagick. For example, these commands will now result in an output PNG file that is exactly 600 pixels wide.

   cgPS_Open
   cgHistoplot, cgDemodata(7), /Fill
   cgPS_Close, /PNG, Width=600
A raster image exactly 600 pixels wide.
A raster image exactly 600 pixels wide.
 

The height of the raster file will be adjusted automatically to maintain the correct aspect ratio of the output (thus, preserving the Coyote Graphics tenet described above).

The way Coyote Graphics routines create raster file output using ImageMagick is controlled via parameters set up with cgWindow_SetDefs. So, for example, if you wanted all your raster file output to have a width of 675 pixels because that was the size you wanted to use in your web page, you could configure that by setting this as the default raster size width with the IM_Width keyword.

   cgWindow_SetDefs, IM_Width=675

Now all raster file output will be set to this width, whether you create the file from a Coyote Graphics command directly, like this:

   cgPlot, cgDemodata(1), Color='red', Output='myplot.jpg'

Or, if you create the raster file from a resizeable Coyote Graphics window, like this:

   cgWindow
   cgLoadCT, 33, /Window
   cgContour, cgDemodata(2), /Fill, /Outline, /Window
   cgControl, Output='mycontour.png'

If you want to return to the "normal" way of doing things, simply set the IM_Width keyword to 0.

   cgWindow_SetDefs, IM_Width=0

Version of IDL used to prepare this article: IDL 7.1.2.

Written: 3 April 2012