NOAAs National Weather Service GD: What is it, and what can it do for you? Arthur Taylor...
-
Upload
posy-hudson -
Category
Documents
-
view
220 -
download
0
description
Transcript of NOAAs National Weather Service GD: What is it, and what can it do for you? Arthur Taylor...
NOAA’s National Weather ServiceNOAA’s National Weather Service
GD: What is it, and what can it do GD: What is it, and what can it do for you?for you?
Arthur TaylorArthur Taylor
NOAA/NWS/Meteorological Development LaboratoryNOAA/NWS/Meteorological Development Laboratory
Sep. 15, 2004Sep. 15, 2004
GD DemonstrationGD Demonstration
GD: What is it?GD: What is it?
• The acronym GD originally stood for “gif draw”. The acronym GD originally stood for “gif draw”. – Unfortunately the gif patent issues caused GD to switch to creating png Unfortunately the gif patent issues caused GD to switch to creating png
images. When it did so, GD stood for “graphics draw”. images. When it did so, GD stood for “graphics draw”. – Now that the patents have expired GD can stand for “gif draw” once Now that the patents have expired GD can stand for “gif draw” once
again.again.• Definition: GD is an ANSI C graphics library for the dynamic
creation of images.• GD is a set of graphic primitives, which allow one to draw to a GD is a set of graphic primitives, which allow one to draw to a
buffer in memory, using lines, arcs, polygons, text, etc.buffer in memory, using lines, arcs, polygons, text, etc.• GD is a set of functions that allows one to read or write various GD is a set of functions that allows one to read or write various
image file formats, including PNG, JPEG, and, as of 7/21/2004, image file formats, including PNG, JPEG, and, as of 7/21/2004, GIF to or from a buffer in memory.GIF to or from a buffer in memory.
• GD does not use X-lib, so it can be easily run as a cron job, GD does not use X-lib, so it can be easily run as a cron job, although typically it is used in CGI applications.although typically it is used in CGI applications.
GD DemonstrationGD Demonstration
GD What it is not?GD What it is not?
• GD is not a paint program, although it can be used to draw most GD is not a paint program, although it can be used to draw most of the features in a paint program.of the features in a paint program.
• GD is not a GIS, although I will be showing examples of how it GD is not a GIS, although I will be showing examples of how it can be used to draw maps.can be used to draw maps.
• GD is not a graphing package, although I will be showing GD is not a graphing package, although I will be showing examples of how it can be used to make graphsexamples of how it can be used to make graphs
GD DemonstrationGD Demonstration
GD: What do I need in order GD: What do I need in order to use it?to use it?
• The GD library (http://www.boutell.com/gd/)The GD library (http://www.boutell.com/gd/)• An ANSI C compiler.An ANSI C compiler.– The following languages are exceptions, as they have some form of The following languages are exceptions, as they have some form of
native support for GD: PHP, Perl, OCaml, Tcl, Pascal, REXXnative support for GD: PHP, Perl, OCaml, Tcl, Pascal, REXX• You also need zlibYou also need zlib– zlib, available from zlib, available from http://www.gzip.org/zlib/http://www.gzip.org/zlib/ (Data compression library) (Data compression library)
• You also need libpng.You also need libpng.– libpng, available from libpng, available from http://www.libpng.org/pub/png/http://www.libpng.org/pub/png/ (Portable Network (Portable Network
Graphics library; requires zlib)Graphics library; requires zlib)• Not Required, but useful:Not Required, but useful:– FreeType 2.x, available from FreeType 2.x, available from http://www.freetype.org/http://www.freetype.org/ (Free, high-quality, (Free, high-quality,
and portable font engine)and portable font engine)– JPEG library, available from JPEG library, available from http://www.ijg.org/http://www.ijg.org/ (Portable JPEG (Portable JPEG
compression/decompression library)compression/decompression library)
GD DemonstrationGD Demonstration
GD: How do I learn to use it?GD: How do I learn to use it?
• The GD home page: The GD home page: http://www.boutell.com/gd/http://www.boutell.com/gd/ is a great place to start. is a great place to start.• The GD manual: The GD manual: http://www.boutell.com/gd/manual2.0.28.htmlhttp://www.boutell.com/gd/manual2.0.28.html has help has help
on all the functions, along with examples.on all the functions, along with examples.
• What about the licensing? What about the licensing? – Permission has been granted to copy, distribute and modify GD in any context Permission has been granted to copy, distribute and modify GD in any context
without fee, including a commercial application, provided that a notice about who without fee, including a commercial application, provided that a notice about who created GD is present in user-accessible supporting documentation.created GD is present in user-accessible supporting documentation.
– This does not affect your ownership of the derived work itself, and the intent is to This does not affect your ownership of the derived work itself, and the intent is to assure proper credit for the authors of GD, not to interfere with your productive use assure proper credit for the authors of GD, not to interfere with your productive use of GD. If you have questions, ask. "Derived works" includes all programs that of GD. If you have questions, ask. "Derived works" includes all programs that utilize the library. Credit must be given in user-accessible documentation.utilize the library. Credit must be given in user-accessible documentation.
– This software is provided "AS IS." The copyright holders disclaim all warranties, This software is provided "AS IS." The copyright holders disclaim all warranties, either express or implied, including but not limited to implied warranties of either express or implied, including but not limited to implied warranties of merchantability and fitness for a particular purpose, with respect to this code and merchantability and fitness for a particular purpose, with respect to this code and accompanying documentation.accompanying documentation.
GD DemonstrationGD Demonstration
Demo1.c : Sample Code/* Bring in gd library functions */#include "gd.h“/* Bring in std I/O so we can output to file */#include <stdio.h>int main (int argc, char **argv){ gdImagePtr im; /* The gd image */ FILE *pngout; /* png output file */ FILE *gifout; /* gif output file */ FILE *jpegout; /* jpg output file */ int black; /* black color */ int white; /* white color */
/* Allocate the image: 64 X 64 pixels. */ im = gdImageCreate (64, 64); /* Allocate the color black. Since this * is the first color in a new image, it will * be the background color. */
black = gdImageColorAllocate (im, 0, 0, 0);
/* Allocate the color white. */ white = gdImageColorAllocate (im,255,255,255);
/* Draw a white line from the upper left to * lower right. */ gdImageLine (im, 0, 0, 63, 63, white);
/* Open files for writing. */ pngout = fopen ("test.png", "wb"); gifout = fopen ("test.gif", "wb"); jpegout = fopen ("test.jpg", "wb"); /* Output the images to the disk. */ gdImagePng (im, pngout); gdImageGif (im, gifout); /* Output the image to JPEG, using the default * JPEG quality setting. */ gdImageJpeg (im, jpegout, -1); /* Close the files. */ fclose (pngout); fclose (gifout); fclose (jpegout); /* Destroy the image in memory. */ gdImageDestroy (im); return 0;}
Note: located on IBM under Note: located on IBM under “/nfsuser/g06/we25at/gd/demo”“/nfsuser/g06/we25at/gd/demo”
GD DemonstrationGD Demonstration
Demo2.f: Sample Code
PROGRAM DEMO2
C Allocate the image: 64 X 64 pixels CALL FORTGDIMAGECREATE (IMAGE, 64, 64)
C Allocate the color black. Since this C is the first color in a new image, it willC be the background color
CALL FORTGDIMAGECOLORALLOCATE (IMAGE, 0, 0, 1 0, IBLACK)
C Allocate the color white. CALL FORTGDIMAGECOLORALLOCATE (IMAGE, 255, 1 255, 255, IWHITE)
C Draw a white line from the upper left toC lower right CALL FORTGDIMAGELINE (IMAGE, 0, 0, 63, 1 63, IWHITE)
C Output the image to a PNG file CALL FORTGDIMAGEPNG (IMAGE, "test.png", 8)
C Output the image to a GIF file CALL FORTGDIMAGEGIF (IMAGE, "test.gif", 8)
C Output the image to a JPEG file CALL FORTGDIMAGEJPEG (IMAGE, "test.jpg", 8, 1 -1)
C Destroy the image in memory. CALL FORTGDIMAGEDESTROY (IMAGE) END
Note: This relies on “gdUtil.c” to act as a wrapper around the gd routines.
GD DemonstrationGD Demonstration
Paint example: read/modify/savePaint example: read/modify/save
• This is an example of a program This is an example of a program that “paints” using GD. that “paints” using GD.
• It’s purpose is to update the It’s purpose is to update the status of various tidal stations. status of various tidal stations.
• To do so, it read an image To do so, it read an image using: “using: “gdImageCreateFromGif ””
• Then it colors specific areas of Then it colors specific areas of the image using: the image using: ““gdImageFilledRectangle ””
• Next it updates the date using: Next it updates the date using: ““gdImageString ””
• Finally it saves the image using: Finally it saves the image using: ““gdImageGif””
GD DemonstrationGD Demonstration
Evaluation Branch's "drawshp"Evaluation Branch's "drawshp"
Author: Arthur TaylorAuthor: Arthur TaylorMain (expert) user: Mike SchenkMain (expert) user: Mike SchenkPlatforms: IBM (AIX), Linux, PCPlatforms: IBM (AIX), Linux, PCDistribution: Source Code, and Distribution: Source Code, and Executable.Executable.Input files: “.ini control file”, set of Input files: “.ini control file”, set of shape filesshape filesDescription: The program reads the .ini Description: The program reads the .ini file which contains the map projection file which contains the map projection and color table information. It then and color table information. It then adds layers which can be shape file adds layers which can be shape file layers, image layers, or text layers. layers, image layers, or text layers. The .ini file specifies where to place The .ini file specifies where to place each layer, if it isn’t part of the map.each layer, if it isn’t part of the map.Original Purpose: To help visualize Original Purpose: To help visualize NDFD verification at points.NDFD verification at points.
GD DemonstrationGD Demonstration
GD Functions used in “drawshp”GD Functions used in “drawshp”
gdImageCreategdImageCreateFromPng
– Creates a gd image, an initializes it with the PNG data.
gdImageCopy– Copies a gd image to another gd image
gdImageColorResolve– Checks if there is already a color with this
definition. If so, reuses it, otherwise defines a new color.
gdImageFilledRectangle– Fills in a rectangle
gdImageRectangle– Draws the outline of a rectangle.
gdImageString– Draws a text string.
gdImageSetPixel– Sets a particular pixel to a given value.
gdImageFilledPolygon– Fills in a polygon
gdImagePolygon– Draws the outline of a polygon
gdImageSetThickness– Sets the thickness of the pen used to draw
the outline of features.gdImagePnggdImageDestroy
GD DemonstrationGD Demonstration
NDFD’s imageGenNDFD’s imageGen
Author: Rici YuAuthor: Rici YuMain (expert) user: Marc SaccuciMain (expert) user: Marc SaccuciPlatforms: Linux, PC (requires cygwin1.dll).Platforms: Linux, PC (requires cygwin1.dll).Distribution: Executable only.Distribution: Executable only.Input files: map definition file, tile file, color Input files: map definition file, tile file, color table file, configuration file, NxM (4 byte real) table file, configuration file, NxM (4 byte real) mosaic file, shape file, city filemosaic file, shape file, city fileDescription: The program reads the map Description: The program reads the map definition file for the map projection. Then definition file for the map projection. Then reads the color table, tile file, and the mosaic reads the color table, tile file, and the mosaic file to draw the grid. It then reads the shape file to draw the grid. It then reads the shape file to draw the boundaries, and finally adds file to draw the boundaries, and finally adds the cities labels using the city file.the cities labels using the city file.Original Purpose: To create web images of the Original Purpose: To create web images of the NDFD grid.NDFD grid.
GD DemonstrationGD Demonstration
Drawshp vs ImageGen Drawshp vs ImageGen
• Features of drawshp that ImageGen Features of drawshp that ImageGen doesn’t have:doesn’t have:– Can draw filled polygons.Can draw filled polygons.– Can draw point shape files, using various Can draw point shape files, using various
colors and symbols.colors and symbols.– Can create text boxes, and can configure Can create text boxes, and can configure
where to put them.where to put them.– Flexibilty about importing and placing other Flexibilty about importing and placing other
images.images.– Built around point and polygon shp files, Built around point and polygon shp files,
which as a side effect allows for GIS which as a side effect allows for GIS analysis of the data.analysis of the data.
– Discrete color scale.Discrete color scale.• Features of ImageGen that drawshp Features of ImageGen that drawshp
doesn’t have:doesn’t have:– Can load a particular grid and generate Can load a particular grid and generate
multiple zooms (sector images) of that grid, multiple zooms (sector images) of that grid, before going to the next one.before going to the next one.
– Can draw Wind Barbs.Can draw Wind Barbs.– Can draw highway (line) shp files.Can draw highway (line) shp files.– Continuous color scale across top mode.Continuous color scale across top mode.
GD DemonstrationGD Demonstration
Tcl Graph GD libraryTcl Graph GD library
Author: Arthur TaylorAuthor: Arthur TaylorPlatforms: IBM (AIX), Linux, PCPlatforms: IBM (AIX), Linux, PCDistribution: Source CodeDistribution: Source CodeDescription: Run from a Tcl script, the Description: Run from a Tcl script, the code calls a “GraphInit” routine which code calls a “GraphInit” routine which sets basic parameters such as labels sets basic parameters such as labels and titles. Then responds to various and titles. Then responds to various “add” calls such as “add bar” or “add “add” calls such as “add bar” or “add point-curve”. After the last added point-curve”. After the last added feature, the Tcl script calls “gd close” to feature, the Tcl script calls “gd close” to close the image and save it to disk.close the image and save it to disk.
GD DemonstrationGD Demonstration
Tcl Graph GD libraryTcl Graph GD library
GD DemonstrationGD Demonstration
PHP use of GD libraryPHP use of GD library
Author: John SchattelAuthor: John SchattelPlatforms: Web (linux)Platforms: Web (linux)Distribution: Php CodeDistribution: Php CodeDescription: Uses GD from php, to plot the Description: Uses GD from php, to plot the results of a XML query of the NDFD results of a XML query of the NDFD database. database.
http://webdev1.weather.gov/john_s/http://webdev1.weather.gov/john_s/production/plotMeteogramDev.phpproduction/plotMeteogramDev.php
GD DemonstrationGD Demonstration
ConclusionConclusion
• What is GD? What is GD? – GD (“gif draw”) is a set of primitive drawing routines that can be used to GD (“gif draw”) is a set of primitive drawing routines that can be used to
create or modify image files.create or modify image files.• What can it do for you? What can it do for you? – GD by itself can be used by either FORTRAN or C to create or modify GD by itself can be used by either FORTRAN or C to create or modify
images from CGI programs, cron jobs, or from the command line. So it is images from CGI programs, cron jobs, or from the command line. So it is limited by your imagination.limited by your imagination.
• What programs / packages are already available at MDL?What programs / packages are already available at MDL?– GIS Category: “GIS Category: “drawshpdrawshp” and “” and “imageGenimageGen”. Both have their advantages ”. Both have their advantages
and disadvantages. Given a need, the programs could be modified to do and disadvantages. Given a need, the programs could be modified to do the same things as the other.the same things as the other.
– Graph Category: “Graph Category: “Tcl GraphTcl Graph” is the only graphing package developed at ” is the only graphing package developed at MDL. Typically MDL uses “gnuplot” (which may use GD) instead, or MDL. Typically MDL uses “gnuplot” (which may use GD) instead, or some PHP graphing routines (see John Schattel).some PHP graphing routines (see John Schattel).
– Paint Category: No packages, but some simple programs.Paint Category: No packages, but some simple programs.