The gd 2.0 documentation update is not complete, but most new features are documented to some degree and the what's new section is reasonably complete. Enjoy!
HEY! READ THIS! gd 2.0.1 creates PNG, JPEG and WBMP images, not GIF images. This is a good thing. PNG is a more compact format, and full compression is available. JPEG works well with photographic images, and is still more compatible with the major Web browsers than even PNG is. WBMP is intended for wireless devices (not regular web browsers). Existing code will need modification to call gdImagePng or gdImageJpeg instead of gdImageGif. Please do not ask us to send you the old GIF version of GD. Unisys holds a patent on the LZW compression algorithm, which is used in fully compressed GIF images. The best solution is to move to legally unencumbered, well-compressed, modern image formats such as PNG and JPEG as soon as possible.gd 2.0.1 requires that the following libraries also be installed:
libpng (see the libpng home page)
zlib (see the info-zip home page) zlib
jpeg-6b or later, if desired (see the Independent JPEG Group home page)
If you want to use the TrueType font support, you must also install the FreeType 2.x library, including the header files. See the Freetype Home Page, or SourceForge. No, I cannot explain why that site is down on a particular day, and no, I can't send you a copy.
If you want to use the Xpm color bitmap loading support, you must also have the X Window System and the Xpm library installed (Xpm is often included in modern X distributions).
Please read the documentation and install the required libraries. Do not send email asking why
png.h
is not found. Do not send email asking whylibgd.so
is not found, either. See the requirements section for more information. Thank you!
Up to the Boutell.Com, Inc. Home Page
Credits and license terms
In order to resolve any possible confusion regarding the authorship of gd, the following copyright statement covers all of the authors who have required such a statement. If you are aware of any oversights in this copyright notice, please contact Thomas Boutell who will be pleased to correct them.
COPYRIGHT STATEMENT FOLLOWS THIS LINE
Portions copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 by Cold Spring Harbor Laboratory. Funded under Grant P41-RR02188 by the National Institutes of Health.Portions copyright 1996, 1997, 1998, 1999, 2000, 2001 by Boutell.Com, Inc.
Portions relating to GD2 format copyright 1999, 2000 Philip Warner.
Portions relating to PNG copyright 1999, 2000 Greg Roelofs.
Portions relating to libttf copyright 1999, 2000 John Ellson (ellson@lucent.com).
Portions relating to JPEG and to color quantization copyright 2000, Doug Becker and copyright (C) 1994-1998, Thomas G. Lane. This software is based in part on the work of the Independent JPEG Group. See the file README-JPEG.TXT for more information.
Portions relating to WBMP copyright 2000 Maurice Szmurlo and Johan Van den Brande.
Permission has been granted to copy, distribute and modify gd in any context without fee, including a commercial application, provided that this notice is present in user-accessible supporting documentation.
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 of gd. If you have questions, ask. "Derived works" includes all programs that utilize the library. Credit must be given in user-accessible documentation.
This software is provided "AS IS." The copyright holders disclaim all warranties, 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 accompanying documentation.
Although their code does not appear in gd 2.0.1, the authors wish to thank David Koblas, David Rowley, and Hutchison Avenue Software Corporation for their prior contributions.
END OF COPYRIGHT STATEMENT
gd is a graphics library. It allows your code to quickly draw images complete with lines, arcs, text, multiple colors, cut and paste from other images, and flood fills, and write out the result as a PNG or JPEG file. This is particularly useful in World Wide Web applications, where PNG and JPEG are two of the formats accepted for inline images by most browsers.
gd is not a paint program. If you are looking for a paint program, you are looking in the wrong place. If you are not a programmer, you are looking in the wrong place, unless you are installing a required library in order to run an application.
gd does not provide for every possible desirable graphics operation. It is not necessary or desirable for gd to become a kitchen-sink graphics package, but version 2.0 does include most frequently requested features, including both truecolor and palette images, resampling (smooth resizing of truecolor images) and so forth.
What if I want to use another programming
language?
Not all of these tools are necessarily up to date and fully compatible
with 2.0.1.
readme.jpn
file.
pixels
array
will fail only if it encounters an existing truecolor image, which may
happen if the code attempts to open and modify an existing JPEG or
truecolor PNG. Such code should be modified to check the
trueColor
flag of the gdImage
structure, and
refer to the tpixels
array instead when it is set.
#include <gd.h>
corrected to #include "gd.h"
in gd_wbmp.c
What's new in version 1.7.3?
Another attempt at Makefile fixes to permit
linking with all libraries required on platforms with order-
dependent linkers. Perhaps it will work this time.
What's new in version 1.7.2?
An uninitialized-pointer bug in gdtestttf.c
was corrected.
This bug caused crashes at the end of each call to gdImageStringTTF on
some platforms. Thanks to Wolfgang Haefelinger.
Documentation fixes. Thanks to Dohn Arms.
Makefile fixes to permit linking with all libraries required on platforms with order- dependent linkers.
What's new in version 1.7.1?
A minor buglet in the Makefile was corrected, as well as an inaccurate
error message in gdtestttf.c
. Thanks to Masahito Yamaga.
What's new in version 1.7?
Version 1.7 contains the following changes:
autoconf
and configure
have been removed, in favor of a
carefully designed Makefile which produces and properly installs
the library and the binaries. System-dependent variables are
at the top of the Makefile for easy modification. I'm sorry,
folks, but autoconf generated many, many confused email
messages from people who didn't have things where autoconf
expected to find them. I am not an autoconf/automake wizard, and
gd is a simple, very compact library which does not need to
be a shared library. I did make many improvements
over the old gd 1.3 Makefile, which were directly inspired by the
autoconf version found in the 1.6 series (thanks to John Ellson).
-pedantic-errors
flag of gcc. Several pieces of not-quite-ANSI-C code were causing problems
for those with non-gcc compilers.
gdttf.c
patched to allow the use of Windows symbol
fonts, when present (thanks to Joseph Peppin).
extern "C"
wrappers added to gd.h
and the
font header files for the convenience of C++ programmers.
bdftogd
was also modified to automatically insert these
wrappers into future font header files. Thanks to John Lindal.
SEEK_SET
.
Thanks to Robert Bonomi.
gdImageCreateFromXpm
function, if the Xpm library is available. Thanks to Caolan McNamara.
What's new in version 1.6.3?
Version 1.6.3 corrects a memory leak in gd_png.c. This leak caused
a significant amount of memory to be allocated and not freed when
writing a PNG image.
Also in this release the build process has been converted to
GNU autoconf/automake/libtool conventions so that both (or either)
static and shared libraries can be built.
Unlike gd 1.6, users should have no trouble linking with
gd 1.6.1 if they follow the instructions and install all of
the pieces. However, If you get undefined symbol errors,
be sure to check for older versions of libpng in your
library directories!
Support for 8-bit palette PNG images has been added.
Support for GIF has been removed. This step was taken
to completely avoid the legal controversy regarding the LZW
compression algorithm used in GIF. Unisys holds a patent which
is relevant to LZW compression. PNG is a superior image format
in any case. Now that PNG is supported by both Microsoft
Internet Explorer and Netscape (in their recent releases),
we highly recommend that GD users upgrade in order to get
well-compressed images in a format which is legally unemcumbered.
This format also supports version numbers and rudimentary validity
checks, so it should be more 'supportable' than the previous GD format.
To use gd, you will need an ANSI C compiler. All popular
Windows 95 and NT C compilers are ANSI C compliant. Any
full-ANSI-standard C compiler should be adequate. The cc
compiler released with SunOS 4.1.3 is not an ANSI C compiler.
Most Unix users who do not already have gcc should get it.
gcc is free, ANSI compliant and a de facto industry standard.
Ask your ISP why it is missing.
As of version 1.6, you also need the zlib compression library,
and the libpng library. As of version 1.6.2, you can draw text
using antialiased TrueType fonts if you also have the libttf
library installed, but this is not mandatory.
zlib is available for a variety of platforms from
the zlib web site.
libpng is available for a variety of platforms from
the PNG web site.
You will also want a PNG viewer, if you do not already have
one for your system, since you will need a good way to check the
results of your work. Netscape 4.04 and higher, and Microsoft
Internet Explorer 4.0 or higher, both support PNG.
For some purposes you might be happier with a package like
Lview Pro for Windows or xv for X. There are PNG viewers available
for every graphics-capable modern operating system, so consult
newsgroups relevant to your particular system.
In order to build gd, you must first unpack the archive you have
downloaded. If you are not familiar with
Unpacking the archive will produce a directory called "gd-2.0.1".
If you get errors, edit the Makefile again, paying special attention
to the INCLUDEDIRS and LIBDIRS settings.
IF YOU GET LINKER ERRORS, TRY JUGGLING THE ORDER OF THE -l DIRECTIVES
IN THE MAKEFILE. Some platforms may prefer that the libraries be listed
in the opposite order.
If you wish to test the library, type "make test" AFTER you have
successfully executed "make install". This will build
several test programs, including "gddemo". Run gddemo to see some of
the capabilities of gd.
gddemo should execute without incident, creating the file
demoout.png. (Note there is also a file named demoin.png,
which is provided in the package as part of the demonstration.)
Display demoout.png in your PNG viewer. The image should
be 128x128 pixels and should contain an image of the
space shuttle with quite a lot of graphical elements drawn
on top of it.
(If you are missing the demoin.png file, the other items
should appear anyway.)
Look at demoin.png to see the original space shuttle
image which was scaled and copied into the output image.
If you want to use the provided fonts, include
gdfontt.h, gdfonts.h, gdfontmb.h, gdfontl.h and/or gdfontg.h. For
more impressive results, install FreeType 2.x and use the new
gdImageStringFT
function. If you are not using the provided Makefile and/or a
library-based approach, be sure to include the source modules as well in your
project. (They may be too large for 16-bit memory models,
that is, 16-bit DOS and Windows.)
Here is a short example program. (For a more advanced example,
see gddemo.c, included in the distribution. gddemo.c is NOT the same program;
it demonstrates additional features!)
The above example program should
give you an idea of how the package works.
gd provides many additional functions, which are listed
in the following reference chapters, complete with code
snippets demonstrating each. There is also an
alphabetical index.
webpng.c is provided in the distribution. Unix users can
simply type "make webpng" to compile the program. Type
"webpng" with no arguments to see the available options.
The
The order of the structure members may appear confusing, but was chosen
deliberately to increase backwards compatibility with existing gd 1.x-based
binary code that references particular structure members.

If the PNG image being loaded is a truecolor image, the resulting
gdImagePtr will refer to a truecolor image. If the PNG image
being loaded is a palette or grayscale image, the resulting
gdImagePtr will refer to a palette image. gd retains only 8 bits
of resolution for each of the red, green and blue channels, and
only 7 bits of resolution for the alpha channel. The former
restriction affects only a handful of very rare 48-bit color
and 16-bit grayscale PNG images. The second restriction affects
all semitransparent PNG images, but the difference is essentially
invisible to the eye. 7 bits of alpha channel resolution is,
in practice, quite a lot.
The programmer must write an input function which accepts
a context pointer, a buffer, and a number of bytes to be
read as arguments. This function must read the number of
bytes requested, unless the end of the file has been reached,
in which case the function should return zero, or an error
has occurred, in which case the function should return
The example below
implements gdImageCreateFromPng
by creating a custom data source and invoking gdImageCreateFromPngSource.
If quality is negative, the default IJG JPEG quality value (which
should yield a good general quality / size tradeoff for most
situations) is used. Otherwise, for practical purposes, quality
should be a value in the range 0-95, higher quality values usually
implying both higher quality and larger image sizes.
If you have set image interlacing using
gdImageInterlace, this function will
interpret that to mean you wish to output a progressive JPEG. Some
programs (e.g., Web browsers) can display progressive JPEGs
incrementally; this can be useful when browsing over a relatively slow
communications link, for example. Progressive JPEGs can also be
slightly smaller than sequential (non-progressive) JPEGs.
The programmer must write an output function which accepts
a context pointer, a buffer, and a number of bytes to be
written as arguments. This function must write the number of
bytes requested and return that number, unless an error
has occurred, in which case the function should return
The example below
implements gdImagePng
by creating a custom data source and invoking gdImagePngFromSink.
WBMP file support is black and white only. The color index
specified by the fg argument is the "foreground," and only pixels
of this color will be set in the WBMP file. All other pixels
will be considered "background."
The gd image format is intended for fast reads and writes of
images your program will need frequently to build other
images. It is not a compressed format, and is not intended
for general use.
The gd2 image format is intended for fast reads and writes of
parts of images.
It is a compressed format, and well suited to retrieving smll sections of
much larger images.
The third and fourth parameters are the 'chunk size' and format resposectively.
The file is stored as a series of compressed subimages, and the
Chunk Size determines the sub-image size - a value of
zero causes the GD library to use the default.
It is also possible to store GD2 files in an uncompressed format, in which case the
fourth parameter should be GD2_FMT_RAW.
gdImageDashedLine is used to draw a dashed line between two endpoints
(x1,y1 and x2, y2).
The line is drawn using the color index specified. The portions of the line
that are not drawn are left transparent so the background is visible.
The border color cannot be a special color
such as gdTiled; it must be a proper
solid color. The fill color can be, however.
Note that gdImageFillToBorder is recursive. It is not the most
naive implementation possible, and the implementation is
expected to improve, but there will always be degenerate
cases in which the stack can become very deep. This can be
a problem in MSDOS and MS Windows 3.1 environments. (Of course,
in a Unix or Windows 95/98/NT environment with a proper stack, this is
not a problem at all.)
The fill color can be gdTiled, resulting
in a tile fill using another image as the tile. However,
the tile image cannot be transparent. If the image you wish
to fill with has a transparent color index, call
gdImageTransparent on the
tile image and set the transparent color index to -1
to turn off its transparency.
Note that gdImageFill is recursive. It is not the most
naive implementation possible, and the implementation is
expected to improve, but there will always be degenerate
cases in which the stack can become very deep. This can be
a problem in MSDOS and MS Windows environments. (Of course,
in a Unix or Windows 95/98/NT environment with a proper stack, this is
not a problem at all.)
gdImageSetBrush is used to specify the brush to be used in a
particular image. You can set any image to be the brush.
If the brush image does not have the same color map as the
first image, any colors missing from the first image
will be allocated. If not enough colors can be allocated,
the closest colors already available will be used. This
allows arbitrary PNGs to be used as brush images. It also
means, however, that you should not set a brush unless you
will actually use it; if you set a rapid succession of
different brush images, you can quickly fill your color map,
and the results will not be optimal.
You need not take any special action when you are finished
with a brush. As for any other image, if you will not
be using the brush image for any further purpose,
you should call gdImageDestroy.
You must not use the color gdBrushed
if the current brush has been destroyed; you can of
course set a new brush to replace it.
gdImageSetTile is used to specify the tile to be used in a
particular image. You can set any image to be the tile.
If the tile image does not have the same color map as the
first image, any colors missing from the first image
will be allocated. If not enough colors can be allocated,
the closest colors already available will be used. This
allows arbitrary PNGs to be used as tile images. It also
means, however, that you should not set a tile unless you
will actually use it; if you set a rapid succession of
different tile images, you can quickly fill your color map,
and the results will not be optimal.
You need not take any special action when you are finished
with a tile. As for any other image, if you will not
be using the tile image for any further purpose,
you should call gdImageDestroy.
You must not use the color gdTiled
if the current tile has been destroyed; you can of
course set a new tile to replace it.
To use gdImageSetStyle, create an array of integers and assign
them the desired series of color values to be repeated.
You can assign the special color value
gdTransparent to indicate that the existing color should
be left unchanged for that particular pixel (allowing a dashed
line to be attractively drawn over an existing image).
Then, to draw a line using the style, use the normal
gdImageLine function with the
special color value gdStyled.
As of version 1.1.1, the style
array is copied when you set the style, so you need not
be concerned with keeping the array around indefinitely.
This should not break existing code that assumes styles
are not copied.
You can also combine styles and brushes to draw the brush
image at intervals instead of in a continuous stroke.
When creating a style for use with a brush, the
style values are interpreted differently: zero (0) indicates
pixels at which the brush should not be drawn, while one (1)
indicates pixels at which the brush should be drawn.
To draw a styled, brushed line, you must use the
special color value
gdStyledBrushed. For an example of this feature
in use, see gddemo.c (provided in the distribution).
This function was added in gd1.3 to provide a means of rendering
fonts with more than 256 characters for those who have them. A
more frequently used routine is gdImageString.
This function was added in gd1.3 to provide a means of rendering
fonts with more than 256 characters for those who have them. A
more frequently used routine is gdImageStringUp.
gdImageStringFT draws a string of anti-aliased characters on the image using
the FreeType
library to render user-supplied TrueType fonts. We do not provide
TrueType fonts (.ttf and .ttc files). Obtaining them is entirely up to
you. The string is anti-aliased, meaning that there should be
fewer "jaggies" visible. The fontname is the full pathname to a TrueType
font file, or a font face name if the GDFONTPATH environment variable
or FreeType's DEFAULT_FONTPATH variable have been set intelligently.
The string may be arbitrarily scaled (ptsize) and rotated (angle in radians).
The user-supplied int brect[8] array is filled on return from gdImageStringFT
with the 8 elements representing the 4 corner coordinates of the
bounding rectangle.
The points are relative to the text regardless of the angle, so "upper left"
means in the top left-hand corner seeing the text horizontally.
Use a NULL gdImagePtr to get the bounding rectangle without rendering.
This is a relatively cheap operation if followed by a rendering of the same
string, because of the caching of the partial rendering during bounding
rectangle calculation.
The string is rendered in the color indicated by the gf color index.
Use the negative of the desired color index to
disable anti-aliasing.
The string may contain UTF-8 sequences like: "À"
gdImageStringFT will return a null char* on success, or an error
string on failure.
In the event that all gdMaxColors colors
(256) have already been allocated, gdImageColorAllocate will
return -1 to indicate failure. (This is not uncommon when
working with existing PNG files that already use 256 colors.)
Note that gdImageColorAllocate
does not check for existing colors that match your request;
see gdImageColorExact,
gdImageColorClosest and
gdImageColorClosestHWB
for ways to locate existing colors that approximate the
color desired in situations where a new color is not available.
Also see gdImageColorResolve,
new in gd-1.6.2.
In the event that all gdMaxColors colors
(256) have already been allocated, gdImageColorAllocate will
return -1 to indicate failure. (This is not uncommon when
working with existing palette-based PNG files that already use 256 colors.)
Note that gdImageColorAllocateAlpha
does not check for existing colors that match your request;
see gdImageColorExactAlpha and
gdImageColorClosestAlpha
for ways to locate existing colors that approximate the
color desired in situations where a new color is not available.
Also see gdImageColorResolveAlpha.
If no colors have yet been allocated in the image,
gdImageColorClosest returns -1.
When applied to a truecolor image, this function always
succeeds in returning the desired color.
This function is most useful as a backup method for choosing
a drawing color when an image already contains
gdMaxColors (256) colors and
no more can be allocated. (This is not uncommon when
working with existing PNG files that already use many colors.)
See gdImageColorExact
for a method of locating exact matches only.
If no colors have yet been allocated in the image,
gdImageColorClosestAlpha returns -1.
When applied to a truecolor image, this function always
succeeds in returning the desired color.
This function is most useful as a backup method for choosing
a drawing color when a palette-based image already contains
gdMaxColors (256) colors and
no more can be allocated. (This is not uncommon when
working with existing palette-based PNG files that already use many colors.)
See gdImageColorExactAlpha
for a method of locating exact matches only.
If no colors have yet been allocated in the image,
gdImageColorClosestHWB returns -1.
When applied to a truecolor image, this function always
succeeds in returning the desired color.
This function is most useful as a backup method for choosing
a drawing color when an image already contains
gdMaxColors (256) colors and
no more can be allocated. (This is not uncommon when
working with existing PNG files that already use many colors.)
See gdImageColorExact
for a method of locating exact matches only.
When applied to a truecolor image, this function always
succeeds in returning the desired color.
When applied to a truecolor image, this function always
succeeds in returning the desired color.
When applied to a truecolor image, this function always
succeeds in returning the desired color.
The color index used should be an index
allocated by gdImageColorAllocate,
whether explicitly invoked by your code or implicitly
invoked by loading an image.
In order to ensure that your image has a reasonable appearance
when viewed by users who do not have transparent background
capabilities (or when you are writing a JPEG-format file, which does
not support transparency), be sure to give reasonable RGB values to the
color you allocate for use as a transparent color,
even though it will be transparent on systems
that support PNG transparency.
The
When you copy a region from one location in an image to another
location in the same image, gdImageCopy will perform as expected
unless the regions overlap, in which case the result is
unpredictable.
Important note on copying between images: since
different images do
not necessarily have the same color tables, pixels are not simply set to the
same color index values to copy them. gdImageCopy will attempt
to find an identical RGB value in the destination image for
each pixel in the copied portion of the source image by
invoking gdImageColorExact. If
such a value is not found, gdImageCopy will attempt to
allocate colors as needed using
gdImageColorAllocate. If both of these methods fail,
gdImageCopy will invoke
gdImageColorClosest to find the color in the destination
image which most closely approximates the color of the
pixel being copied.
The
When you copy a region from one location in an image to another
location in the same image, gdImageCopy will perform as expected
unless the regions overlap, in which case the result is
unpredictable. If this presents a problem, create a scratch image
in which to keep intermediate results.
Important note on copying between images: since images
do not necessarily have the same color tables, pixels are not simply set
to the same color index values to copy them. gdImageCopy will attempt
to find an identical RGB value in the destination image for
each pixel in the copied portion of the source image by
invoking gdImageColorExact. If
such a value is not found, gdImageCopy will attempt to
allocate colors as needed using
gdImageColorAllocate. If both of these methods fail,
gdImageCopy will invoke
gdImageColorClosest to find the color in the destination
image which most closely approximates the color of the
pixel being copied.
Pixel values are only interpolated if the destination image is a
truecolor image. Otherwise,
gdImageCopyResized is
automatically invoked.
The
When you copy a region from one location in an image to another
location in the same image, gdImageCopy will perform as expected
unless the regions overlap, in which case the result is
unpredictable. If this presents a problem, create a scratch image
in which to keep intermediate results.
Important note on copying between images: since images
do not necessarily have the same color tables, pixels are not simply set
to the same color index values to copy them. If the destination image
is a palette image, gd will use the
gdImageColorResolve function to
determine the best color available.
If, however, the pct parameter is less than 100, then the two images are merged.
With pct = 0, no action is taken.
This feature is most useful to 'highlight' sections of an image by merging a solid color with
pct = 50:
A nonzero value for the interlace argument turns on interlace;
a zero value turns it off. Note that interlace has no effect
on other functions, and has no meaning unless you save the
image in PNG or JPEG format; the gd and xbm formats do not support
interlace.
When a PNG is loaded with
gdImageCreateFromPng or a JPEG is
loaded with
gdImageCreateFromJpeg, interlace
will be set according to the setting in the PNG or JPEG file.
Note that many PNG and JPEG viewers and web browsers do not
support interlace or the incremental display of progressive
JPEGs. However, the interlaced PNG or progressive JPEG should still
display; it will simply appear all at once, just as other images do.
The program "pngtogd.c" is provided as a simple way of converting
.png files to .gd format. I emphasize again that you will not
need to use this format unless you have a need for high-speed loading
of a few frequently-used images in your program.
The program "pngtogd2.c" is provided as a simple way of converting
.png files to .gd2 format.
The
It is not necessary to implement all functions in an I/O context if you know
that it will only be used in limited cirsumstances. At the time of writing
(Version 1.6.1, July 1999), the known requirements are:
Be sure to read this manual carefully first.
What's new in version 1.6.2?
Version 1.6.2 from John Ellson
if ((color=gdImageColorExact(im,R,G,B)) < 0)
if ((color=gdImageColorAllocate(im,R,G,B)) < 0)
color=gdImageColorClosest(im,R,G,B);
What's new in version 1.6.1?
Version 1.6.1 incorporates superior PNG reading and writing code
from Greg Roelofs, with minor modifications by Tom Boutell.
Specifically, I altered his code to read non-palette images
(converting them to palette images badly, by dithering them),
and to tolerate palette images with types of transparency that
gd doesn't actually support (it just ignores the advanced
transparency features). Any bugs in this area are therefore my
fault, not Greg's.
What's new in version 1.6?
Version 1.6 features the following changes:
What's new in version 1.5?
Version 1.5 featured the following changes:
NOTE: In fairness to Thomas Boutell, any bug/problems with any of the above features should
probably be reported to Philip Warner.
gdImagePaletteCopy - Copies a palette from one image to another, doing it's best to match the colors in the target image to the colors in the source palette.
gdImageGd2, gdImageCreateFromGd2 - Support for new format
gdImageCopyMerge - Merges two images (useful to highlight part of an image)
gdImageCopyMergeGray - Similar to gdImageCopyMerge, but tries to preserve source image hue.
gdImagePngPtr, gdImageJpegPtr, gdImageWBMPPtr, gdImageGdPtr, gdImageGd2Ptr - return memory blocks for each type of image.
gdImageCreateFromPngCtx, gdImageCreateFromGdCtx, gdImageCreateFromGd2Ctx, gdImageCreateFromGd2PartCtx - Support for new I/O context.
What's new in version 1.4?
Version 1.4 features the following changes:
What's new in version 1.3?
Version 1.3 features the following changes:
pixels
array will require
changes.
What else do I need to use gd?
By HTTP
By FTP
tar
and
gunzip
(Unix) or ZIP
(Windows), please
consult with an experienced user of your system. Sorry, we cannot
answer questions about basic Internet skills.
For Unix
cd
to the 2.0.1 directory. Edit the Makefile with
your preferred text editor and make any necessary changes to the
settings at the top, especially if you want Xpm or TrueType support.
Next, type "make install". Because gd 2.0 and above installs
as a shared library, it is necessary to install the library properly
before running gd-based programs.
For Windows, Mac, Et Cetera
Create a project using your favorite programming environment.
Copy all of the gd files to the project directory. Add gd.c
to your project. Add other source files as appropriate. Learning the
basic skills of creating projects with your chosen C environment
is up to you.
gd basics: using gd in your program
gd lets you create PNG or JPEG images on the fly. To use gd in your
program, include the file gd.h, and link with the libgd.a
library produced by "make libgd.a", under Unix. Under other
operating systems you will add gd.c to your own project.
/* Bring in gd library functions */
#include "gd.h"
/* Bring in standard I/O so we can output the PNG to a file */
#include <stdio.h>
int main() {
/* Declare the image */
gdImagePtr im;
/* Declare output files */
FILE *pngout, *jpegout;
/* Declare color indexes */
int black;
int white;
/* Allocate the image: 64 pixels across by 64 pixels tall */
im = gdImageCreate(64, 64);
/* Allocate the color black (red, green and blue all minimum).
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 (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a line from the upper left to the lower right,
using white color index. */
gdImageLine(im, 0, 0, 63, 63, white);
/* Open a file for writing. "wb" means "write binary", important
under MSDOS, harmless under Unix. */
pngout = fopen("test.png", "wb");
/* Do the same for a JPEG-format file. */
jpegout = fopen("test.jpg", "wb");
/* Output the image to the disk file in PNG format. */
gdImagePng(im, pngout);
/* Output the same image in JPEG format, using the default
JPEG quality setting. */
gdImageJpeg(im, jpegout, -1);
/* Close the files. */
fclose(pngout);
fclose(jpegout);
/* Destroy the image in memory. */
gdImageDestroy(im);
}
When executed, this program creates an image, allocates
two colors (the first color allocated becomes the background
color), draws a diagonal line (note that 0, 0 is the upper
left corner), writes the image to PNG and JPEG files, and
destroys the image.
Webpng: a more powerful gd example
Webpng is a simple utility program to manipulate PNGs from the
command line. It is written for Unix and similar command-line
systems, but should be easily adapted for other environments.
Webpng allows you to set transparency and interlacing and
output interesting information about the PNG in question.
Function and type reference
Types
gdImage
(TYPE)
pixels
or tpixels
arrays. If the trueColor
flag
is set, the tpixels
array is valid; otherwise the
pixels
array is valid.
colorsTotal
, red
, green
,
blue
, alpha
and open
arrays
manage the palette. They are valid only when the trueColor
flag is not set.
The transparent
value contains the palette index of the first
transparent color as read-only information for backwards compatibility;
gd 2.0 stores this information in the alpha
array so that
variable transparency can be supported for each palette entry. However,
for truecolor images, transparent
represents a single
RGB color which is always 100% transparent, and this
feature is generally supported by browsers which do not support
full alpha channels.
typedef struct {
/* Palette-based image pixels */
unsigned char ** pixels;
int sx;
int sy;
/* These are valid in palette images only. See also
/* 'alpha', which appears later in the structure to
preserve binary backwards compatibility */
int colorsTotal;
int red[gdMaxColors];
int green[gdMaxColors];
int blue[gdMaxColors];
int open[gdMaxColors];
/* For backwards compatibility, this is set to the
first palette entry with 100% transparency,
and is also set and reset by the
gdImageColorTransparent function. Newer
applications can allocate palette entries
with any desired level of transparency; however,
bear in mind that many viewers, notably
many web browsers, fail to implement
full alpha channel for PNG and provide
support for full opacity or transparency only. */
int transparent;
int *polyInts;
int polyAllocated;
struct gdImageStruct *brush;
struct gdImageStruct *tile;
int brushColorMap[gdMaxColors];
int tileColorMap[gdMaxColors];
int styleLength;
int stylePos;
int *style;
int interlace;
/* New in 2.0: alpha channel for palettes. Note that only
Macintosh Internet Explorer and (possibly) Netscape 6
really support multiple levels of transparency in
palettes, to my knowledge, as of 2/15/01. Most
common browsers will display 100% opaque and
100% transparent correctly, and do something
unpredictable and/or undesirable for levels
in between. TBB */
int alpha[gdMaxColors];
/* Truecolor flag and pixels. New 2.0 fields appear here at the
end to minimize breakage of existing object code. */
int trueColor;
int ** tpixels;
/* Should alpha channel be copied, or applied, each time a
pixel is drawn? This applies to truecolor images only.
No attempt is made to alpha-blend in palette images,
even if semitransparent palette entries exist.
To do that, build your image as a truecolor image,
then quantize down to 8 bits. */
int alphaBlendingFlag;
/* Should the alpha channel of the image be saved? This affects
PNG at the moment; other future formats may also
have that capability. JPEG doesn't. */
int saveAlphaFlag;
} gdImage;
typedef struct {
/* # of characters in font */
int nchars;
/* First character is numbered... (usually 32 = space) */
int offset;
/* Character width and height */
int w;
int h;
/* Font data; array of characters, one row after another.
Easily included in code, also easily loaded from
data files. */
char *data;
} gdFont;
typedef struct {
int x, y;
} gdPoint, *gdPointPtr;
typedef struct {
int (*source) (void *context, char *buffer, int len);
void *context;
} gdSource, *gdSourcePtr;
Represents a source from which a PNG can be read.
Programmers who do not wish to read PNGs from a file can provide
their own alternate input mechanism, using the
gdImageCreateFromPngSource function.
See the documentation of that function for an example of the
proper use of this type.
typedef struct {
int (*sink) (void *context, char *buffer, int len);
void *context;
} gdSink, *gdSinkPtr;
Represents a "sink" (destination) to which a PNG can be written.
Programmers who do not wish to write PNGs to a file can provide
their own alternate output mechanism, using the
gdImagePngToSink function.
See the documentation of that function for an example of the
proper use of this type.
Image creation, destruction, loading and saving
... inside a function ...
gdImagePtr im;
im = gdImageCreate(64, 64);
/* ... Use the image ... */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
im = gdImageCreateTrueColor(64, 64);
/* ... Use the image ... */
gdImageDestroy(im);
gdImageCreateFromJpegCtx(FILE *in)
(FUNCTION)
gdImageCreateFromJpegCtx(FILE *in)
(FUNCTION)
gdImagePtr im;
... inside a function ...
FILE *in;
in = fopen("myjpeg.jpg", "rb");
im = gdImageCreateFromJpeg(in);
fclose(in);
/* ... Use the image ... */
gdImageDestroy(im);
gdImageCreateFromPngCtx(gdIOCtx *in)
(FUNCTION)
gdImagePtr im;
... inside a function ...
FILE *in;
in = fopen("mypng.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* ... Use the image ... */
gdImageDestroy(im);
-1
. The programmer then creates a
gdSource structure and sets
the source
pointer to the input function and
the context pointer to any value which is useful to the
programmer.
static int freadWrapper(void *context, char *buf, int len);
gdImagePtr gdImageCreateFromPng(FILE *in)
{
gdSource s;
s.source = freadWrapper;
s.context = in;
return gdImageCreateFromPngSource(&s);
}
static int freadWrapper(void *context, char *buf, int len)
{
int got = fread(buf, 1, len, (FILE *) context);
return got;
}
gdImageCreateFromGdCtx(gdIOCtx *in)
(FUNCTION)
... inside a function ...
gdImagePtr im;
FILE *in;
in = fopen("mygd.gd", "rb");
im = gdImageCreateFromGd(in);
fclose(in);
/* ... Use the image ... */
gdImageDestroy(im);
gdImageCreateFromGd2Ctx(gdIOCtx *in)
(FUNCTION)
... inside a function ...
gdImagePtr im;
FILE *in;
in = fopen("mygd.gd2", "rb");
im = gdImageCreateFromGd2(in);
fclose(in);
/* ... Use the image ... */
gdImageDestroy(im);
gdImageCreateFromGd2PartCtx(gdIOCtx *in)
(FUNCTION)
... inside a function ...
gdImagePtr im;
FILE *in;
in = fopen("myxbm.xbm", "rb");
im = gdImageCreateFromXbm(in);
fclose(in);
/* ... Use the image ... */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
FILE *in;
in = fopen("myxpm.xpm", "rb");
im = gdImageCreateFromXpm(in);
fclose(in);
/* ... Use the image ... */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
im = gdImageCreate(10, 10);
/* ... Use the image ... */
/* Now destroy it */
gdImageDestroy(im);
void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality)
(FUNCTION)
... inside a function ...
gdImagePtr im;
int black, white;
FILE *out;
/* Create the image */
im = gdImageCreate(100, 100);
/* Allocate background */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate drawing color */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Draw rectangle */
gdImageRectangle(im, 0, 0, 99, 99, black);
/* Open output file in binary mode */
out = fopen("rect.jpg", "wb");
/* Write JPEG using default quality */
gdImageJpeg(im, out, -1);
/* Close file */
fclose(out);
/* Destroy image */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black, white;
FILE *out;
/* Create the image */
im = gdImageCreate(100, 100);
/* Allocate background */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate drawing color */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Draw rectangle */
gdImageRectangle(im, 0, 0, 99, 99, black);
/* Open output file in binary mode */
out = fopen("rect.png", "wb");
/* Write PNG */
gdImagePng(im, out);
/* Close file */
fclose(out);
/* Destroy image */
gdImageDestroy(im);
-1
. The programmer then creates a
gdSink structure and sets
the sink
pointer to the output function and
the context pointer to any value which is useful to the
programmer.
static int stdioSink(void *context, char *buffer, int len)
{
return fwrite(buffer, 1, len, (FILE *) context);
}
void gdImagePng(gdImagePtr im, FILE *out)
{
gdSink mySink;
mySink.context = (void *) out;
mySink.sink = stdioSink;
gdImagePngToSink(im, &mySink);
}
gdImageWBMPCtx(gdIOCtx *out)
(FUNCTION)(FUNCTION)
... inside a function ...
gdImagePtr im;
int black, white;
FILE *out;
/* Create the image */
im = gdImageCreate(100, 100);
/* Allocate background */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate drawing color */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Draw rectangle */
gdImageRectangle(im, 0, 0, 99, 99, black);
/* Open output file in binary mode */
out = fopen("rect.wbmp", "wb");
/* Write WBMP, with black as foreground */
gdImageWBMP(im, black, out);
/* Close file */
fclose(out);
/* Destroy image */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black, white;
FILE *out;
/* Create the image */
im = gdImageCreate(100, 100);
/* Allocate background */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate drawing color */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Draw rectangle */
gdImageRectangle(im, 0, 0, 99, 99, black);
/* Open output file in binary mode */
out = fopen("rect.gd", "wb");
/* Write gd format file */
gdImageGd(im, out);
/* Close file */
fclose(out);
/* Destroy image */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black, white;
FILE *out;
/* Create the image */
im = gdImageCreate(100, 100);
/* Allocate background */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate drawing color */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Draw rectangle */
gdImageRectangle(im, 0, 0, 99, 99, black);
/* Open output file in binary mode */
out = fopen("rect.gd", "wb");
/* Write gd2 format file */
gdImageGd2(im, out, 0, GD2_FMT_COMPRESSED);
/* Close file */
fclose(out);
/* Destroy image */
gdImageDestroy(im);
Drawing Functions
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Set a pixel near the center. */
gdImageSetPixel(im, 50, 50, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a line from the upper left corner to the lower right corner. */
gdImageLine(im, 0, 0, 99, 99, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a dashed line from the upper left corner to the lower right corner. */
gdImageDashedLine(im, 0, 0, 99, 99);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
/* Points of polygon */
gdPoint points[3];
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a triangle. */
points[0].x = 50;
points[0].y = 0;
points[1].x = 99;
points[1].y = 99;
points[2].x = 0;
points[2].y = 99;
gdImagePolygon(im, points, 3, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a rectangle occupying the central area. */
gdImageRectangle(im, 25, 25, 74, 74, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
int red;
/* Points of polygon */
gdPoint points[3];
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate the color red. */
red = gdImageColorAllocate(im, 255, 0, 0);
/* Draw a triangle. */
points[0].x = 50;
points[0].y = 0;
points[1].x = 99;
points[1].y = 99;
points[2].x = 0;
points[2].y = 99;
/* Paint it in white */
gdImageFilledPolygon(im, points, 3, white);
/* Outline it in red; must be done second */
gdImagePolygon(im, points, 3, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = int gdImageColorAllocate(im, 255, 255, 255);
/* Draw a filled rectangle occupying the central area. */
gdImageFilledRectangle(im, 25, 25, 74, 74, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
s
and ends at
the position specified by e
. The arc is drawn in
the color specified by the last argument. A circle can be drawn
by beginning from 0 degrees and ending at 360 degrees, with
width and height being equal. e must be greater than s. Values greater
than 360 are interpreted modulo 360.
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 50);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Inscribe an ellipse in the image. */
gdImageArc(im, 50, 25, 98, 48, 0, 360, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
s
and ends at
the position specified by e
. The arc is filled in
the color specified by the second to last argument. A circle can be drawn
by beginning from 0 degrees and ending at 360 degrees, with
width and height being equal. e must be greater than s. Values greater
than 360 are interpreted modulo 360. The last argument is a bitwise
OR of the following possibilities:
gdArc and gdChord are mutually exclusive;
gdChord just connects the starting and ending
angles with a straight line, while gdArc produces
a rounded edge. gdPie is a synonym for gdArc.
gdNoFill indicates that the arc or chord should be
outlined, not filled. gdEdged, used together with
gdNoFill, indicates that the beginning and ending
angles should be connected to the center; this is
a good way to outline (rather than fill) a
'pie slice'.
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 50);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Inscribe a filled pie slice in the image. */
gdImageFilledArc(im, 50, 25, 98, 48, 0, 45, white, gdArc);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 50);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Inscribe a filled ellipse in the image. */
gdImageFilledEllipse(im, 50, 25, 98, 48, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
color
, beginning at the specified point and stopping at
the specified border
color. For a way of flooding an
area defined by the color of the starting point, see
gdImageFill.
... inside a function ...
gdImagePtr im;
int black;
int white;
int red;
im = gdImageCreate(100, 50);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate the color red. */
red = gdImageColorAllocate(im, 255, 0, 0);
/* Inscribe an ellipse in the image. */
gdImageArc(im, 50, 25, 98, 48, 0, 360, white);
/* Flood-fill the ellipse. Fill color is red, border color is
white (ellipse). */
gdImageFillToBorder(im, 50, 50, white, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
color
, beginning at the specified point and flooding the
surrounding region of the same color as the starting point.
For a way of flooding a region defined by a specific border
color rather than by its interior color, see
gdImageFillToBorder.
... inside a function ...
gdImagePtr im;
int black;
int white;
int red;
im = gdImageCreate(100, 50);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Allocate the color red. */
red = gdImageColorAllocate(im, 255, 0, 0);
/* Inscribe an ellipse in the image. */
gdImageArc(im, 50, 25, 98, 48, 0, 360, white);
/* Flood-fill the ellipse. Fill color is red, and will replace the
black interior of the ellipse. */
gdImageFill(im, 50, 50, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im, brush;
FILE *in;
int black;
im = gdImageCreate(100, 100);
/* Open the brush PNG. For best results, portions of the
brush that should be transparent (ie, not part of the
brush shape) should have the transparent color index. */
in = fopen("star.png", "rb");
brush = gdImageCreateFromPng(in);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageSetBrush(im, brush);
/* Draw a line from the upper left corner to the lower right corner
using the brush. */
gdImageLine(im, 0, 0, 99, 99, gdBrushed);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
/* Destroy the brush image */
gdImageDestroy(brush);
... inside a function ...
gdImagePtr im, tile;
FILE *in;
int black;
im = gdImageCreate(100, 100);
/* Open the tile PNG. For best results, portions of the
tile that should be transparent (ie, allowing the
background to shine through) should have the transparent
color index. */
in = fopen("star.png", "rb");
tile = gdImageCreateFromPng(in);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageSetTile(im, tile);
/* Fill an area using the tile. */
gdImageFilledRectangle(im, 25, 25, 75, 75, gdTiled);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
/* Destroy the tile image */
gdImageDestroy(tile);
gdImagePtr im;
int styleDotted[2], styleDashed[6];
FILE *in;
int black;
int red;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
red = gdImageColorAllocate(im, 255, 0, 0);
/* Set up dotted style. Leave every other pixel alone. */
styleDotted[0] = red;
styleDotted[1] = gdTransparent;
/* Set up dashed style. Three on, three off. */
styleDashed[0] = red;
styleDashed[1] = red;
styleDashed[2] = red;
styleDashed[3] = gdTransparent;
styleDashed[4] = gdTransparent;
styleDashed[5] = gdTransparent;
/* Set dotted style. Note that we have to specify how many pixels are
in the style! */
gdImageSetStyle(im, styleDotted, 2);
/* Draw a line from the upper left corner to the lower right corner. */
gdImageLine(im, 0, 0, 99, 99, gdStyled);
/* Now the dashed line. */
gdImageSetStyle(im, styleDashed, 6);
gdImageLine(im, 0, 99, 0, 99, gdStyled);
/* ... Do something with the image, such as saving it to a file ... */
/* Destroy it */
gdImageDestroy(im);
gdImagePtr im;
int red, blue;
im = gdImageCreateTrueColor(100, 100);
/* Background color */
red = gdTrueColor(255, 0, 0);
gdImageFilledRectangle(im, 0, 0, 100, 100, red);
/* Drawing color. Full transparency would be an alpha channel value
of 127 (gd has a 7 bit alpha chnanel). 0 is opaque,
127 is transparent. So cut gdAlphaTransparent in half to get
50% blending. */
blue = gdTrueColorAlpha(0, 0, 255, gdAlphaTransparent / 2);
/* Draw with blending. Result will be 50% red, 50% blue: yellow
(emitted light, remember, not reflected light. What you learned
in Kindergarten is wrong here). */
gdImageAlphaBlending(im, 1);
gdImageFilledRectangle(im, 0, 0, 25, 25, blue);
/* Draw without blending. Result will be 50% blue, 50%
the background color of the image viewer or web browser
used; results in browsers that don't support
semi-transparent pixels are unpredictable! */
gdImageAlphaBlending(im, 0);
gdImageFilledRectangle(im, 75, 75, 25, 25, blue);
/* Write the image to disk, etc. */
Query Functions
... inside a function ...
FILE *in;
gdImagePtr im;
int c;
in = fopen("mypng.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
c = gdImageGetPixel(im, gdImageSX(im) / 2, gdImageSY(im) / 2);
printf("The value of the center pixel is %d; RGB values are %d,%d,%d\n",
c, im->red[c], im->green[c], im->blue[c]);
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
if (gdImageBoundsSafe(im, 50, 50)) {
printf("50, 50 is within the image bounds\n");
} else {
printf("50, 50 is outside the image bounds\n");
}
gdImageDestroy(im);
Fonts and text-handling functions
#include "gd.h"
#include "gdfontl.h"
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a character. */
gdImageChar(im, gdFontLarge, 0, 0, 'Q', white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
#include "gd.h"
#include "gdfontl.h"
... inside a function ...
gdImagePtr im;
int black;
int white;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a character upwards so it rests against the top of the image. */
gdImageCharUp(im, gdFontLarge,
0, gdFontLarge->h, 'Q', white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
#include "gd.h"
#include "gdfontl.h"
#include <string.h>
... inside a function ...
gdImagePtr im;
int black;
int white;
/* String to draw. */
char *s = "Hello.";
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a centered string. */
gdImageString(im, gdFontLarge,
im->w / 2 - (strlen(s) * gdFontLarge->w / 2),
im->h / 2 - gdFontLarge->h / 2,
s, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
#include "gd.h"
#include "gdfontl.h"
#include <string.h>
... inside a function ...
gdImagePtr im;
int black;
int white;
/* String to draw. */
char *s = "Hello.";
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a centered string going upwards. Axes are reversed,
and Y axis is decreasing as the string is drawn. */
gdImageStringUp(im, gdFontLarge,
im->w / 2 - gdFontLarge->h / 2,
im->h / 2 + (strlen(s) * gdFontLarge->w / 2),
s, white);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
0
lower left corner, X position
lower left corner, Y position
lower right corner, X position 3
lower right corner, Y position 4
upper right corner, X position 5
upper right corner, Y position 6
upper left corner, X position 7
upper left corner, Y position
#include "gd.h"
#include <string.h>
... inside a function ...
gdImagePtr im;
int black;
int white;
int brect[8];
int x, y;
char *err;
char *s = "Hello."; /* String to draw. */
double sz = 40.;
char *f = "/usr/local/share/ttf/Times.ttf"; /* User supplied font */
/* obtain brect so that we can size the image */
err = gdImageStringFT(NULL,&brect[0],0,f,sz,0.,0,0,s);
if (err) {fprintf(stderr,err); return 1;}
/* create an image big enough for the string plus a little whitespace */
x = brect[2]-brect[6] + 6;
y = brect[3]-brect[7] + 6;
im = gdImageCreate(x,y);
/* Background color (first allocated) */
white = gdImageColorResolve(im, 255, 255, 255);
black = gdImageColorResolve(im, 0, 0, 0);
/* render the string, offset origin to center string*/
/* note that we use top-left coordinate for adjustment
* since gd origin is in top-left with y increasing downwards. */
x = 3 - brect[6];
y = 3 - brect[7];
err = gdImageStringFT(im,&brect[0],black,f,sz,0.0,x,y,s);
if (err) {fprintf(stderr,err); return 1;}
/* Write img to stdout */
gdImagePng(im, stdout);
/* Destroy it */
gdImageDestroy(im);
Color-handling functions
... inside a function ...
gdImagePtr im;
int black;
int red;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color red. */
red = gdImageColorAllocate(im, 255, 0, 0);
/* Draw a dashed line from the upper left corner to the lower right corner. */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
int red;
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color red, 50% transparent. */
red = gdImageColorAllocateAlpha(im, 255, 0, 0, 64);
/* Draw a dashed line from the upper left corner to the lower right corner. */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
FILE *in;
int red;
/* Let's suppose that photo.png is a scanned photograph with
many colors. */
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* Try to allocate red directly */
red = gdImageColorAllocate(im, 255, 0, 0);
/* If we fail to allocate red... */
if (red == (-1)) {
/* Find the closest color instead. */
red = gdImageColorClosest(im, 255, 0, 0);
}
/* Draw a dashed line from the upper left corner to the lower right corner */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
FILE *in;
int red;
/* Let's suppose that photo.png is a scanned photograph with
many colors. */
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* Try to allocate red, 50% transparent, directly */
red = gdImageColorAllocateAlpha(im, 255, 0, 0, 64);
/* If we fail to allocate red... */
if (red == (-1)) {
/* Find the closest color instead. */
red = gdImageColorClosestAlpha(im, 255, 0, 0, 64);
}
/* Draw a dashed line from the upper left corner to the lower right corner */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
FILE *in;
int red;
/* Let's suppose that photo.png is a scanned photograph with
many colors. */
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* Try to allocate red directly */
red = gdImageColorAllocate(im, 255, 0, 0);
/* If we fail to allocate red... */
if (red == (-1)) {
/* Find the closest color instead. */
red = gdImageColorClosestHWB(im, 255, 0, 0);
}
/* Draw a dashed line from the upper left corner to the lower right corner */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int red;
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* The image may already contain red; if it does, we'll save a slot
in the color table by using that color. */
/* Try to allocate red directly */
red = gdImageColorExact(im, 255, 0, 0);
/* If red isn't already present... */
if (red == (-1)) {
/* Second best: try to allocate it directly. */
red = gdImageColorAllocate(im, 255, 0, 0);
/* Out of colors, so find the closest color instead. */
red = gdImageColorClosest(im, 255, 0, 0);
}
/* Draw a dashed line from the upper left corner to the lower right corner */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int red;
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* The image may already contain red; if it does, we'll save a slot
in the color table by using that color. */
/* Get index of red, or color closest to red */
red = gdImageColorResolve(im, 255, 0, 0);
/* Draw a dashed line from the upper left corner to the lower right corner */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int red;
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* The image may already contain red; if it does, we'll save a slot
in the color table by using that color. */
/* Get index of red, 50% transparent, or the next best thing */
red = gdImageColorResolveAlpha(im, 255, 0, 0, 64);
/* Draw a dashed line from the upper left corner to the lower right corner */
gdImageDashedLine(im, 0, 0, 99, 99, red);
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int red, blue;
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* Look for red in the color table. */
red = gdImageColorExact(im, 255, 0, 0);
/* If red is present... */
if (red != (-1)) {
/* Deallocate it. */
gdImageColorDeallocate(im, red);
/* Allocate blue, reusing slot in table.
Existing red pixels will change color. */
blue = gdImageColorAllocate(im, 0, 0, 255);
}
/* ... Do something with the image, such as saving it to a file... */
/* Destroy it */
gdImageDestroy(im);
... inside a function ...
gdImagePtr im;
int black;
FILE *in, *out;
in = fopen("photo.png", "rb");
im = gdImageCreateFromPng(in);
fclose(in);
/* Look for black in the color table and make it transparent. */
black = gdImageColorExact(im, 0, 0, 0);
/* If black is present... */
if (black != (-1)) {
/* Make it transparent */
gdImageColorTransparent(im, black);
}
/* Save the newly-transparent image back to the file */
out = fopen("photo.png", "wb");
gdImagePng(im, out);
fclose(out);
/* Destroy it */
gdImageDestroy(im);
Copying and resizing functions
dst
argument is the destination image to which the
region will be copied. The src
argument is the source
image from which the region is copied. The dstX
and dstY
arguments specify the point in the destination
image to which the region will be copied. The srcX
and srcY
arguments specify the upper left corner
of the region in the source image. The w
and h
arguments specify the width and height
of the region.
... Inside a function ...
gdImagePtr im_in;
gdImagePtr im_out;
int x, y;
FILE *in;
FILE *out;
/* Load a small png to tile the larger one with */
in = fopen("small.png", "rb");
im_in = gdImageCreateFromPng(in);
fclose(in);
/* Make the output image four times as large on both axes */
im_out = gdImageCreate(im_in->sx * 4, im_in->sy * 4);
/* Now tile the larger image using the smaller one */
for (y = 0; (y < 4); y++) {
for (x = 0; (x < 4); x++) {
gdImageCopy(im_out, im_in,
x * im_in->sx, y * im_in->sy,
0, 0,
im_in->sx, im_in->sy);
}
}
out = fopen("tiled.png", "wb");
gdImagePng(im_out, out);
fclose(out);
gdImageDestroy(im_in);
gdImageDestroy(im_out);
dst
argument is the destination image to which the
region will be copied. The src
argument is the source
image from which the region is copied. The dstX
and dstY
arguments specify the point in the destination
image to which the region will be copied. The srcX
and srcY
arguments specify the upper left corner
of the region in the source image. The dstW
and dstH
arguments specify the width and height
of the destination region. The srcW
and srcH
arguments specify the width and height
of the source region and can differ from the destination size,
allowing a region to be scaled during the copying process.
... Inside a function ...
gdImagePtr im_in;
gdImagePtr im_out;
int x, y;
FILE *in;
FILE *out;
/* Load a small png to expand in the larger one */
in = fopen("small.png", "rb");
im_in = gdImageCreateFromPng(in);
fclose(in);
/* Make the output image four times as large on both axes */
im_out = gdImageCreate(im_in->sx * 4, im_in->sy * 4);
/* Now copy the smaller image, but four times larger */
gdImageCopyResized(im_out, im_in, 0, 0, 0, 0,
im_out->sx, im_out->sy,
im_in->sx, im_in->sy);
out = fopen("large.png", "wb");
gdImagePng(im_out, out);
fclose(out);
gdImageDestroy(im_in);
gdImageDestroy(im_out);
dst
argument is the destination image to which the
region will be copied. The src
argument is the source
image from which the region is copied. The dstX
and dstY
arguments specify the point in the destination
image to which the region will be copied. The srcX
and srcY
arguments specify the upper left corner
of the region in the source image. The dstW
and dstH
arguments specify the width and height
of the destination region. The srcW
and srcH
arguments specify the width and height
of the source region and can differ from the destination size,
allowing a region to be scaled during the copying process.
... Inside a function ...
gdImagePtr im_in;
gdImagePtr im_out;
int x, y;
FILE *in;
FILE *out;
/* Load a large png to shrink in the smaller one */
in = fopen("large.png", "rb");
im_in = gdImageCreateFromPng(in);
fclose(in);
/* Make the output image four times as small on both axes. Use
a true color image so that we can interpolate colors. */
im_out = gdImageCreateTrueColor(im_in->sx / 4, im_in->sy / 4);
/* Now copy the large image, but four times smaller */
gdImageCopyResampled(im_out, im_in, 0, 0, 0, 0,
im_out->sx, im_out->sy,
im_in->sx, im_in->sy);
out = fopen("large.png", "wb");
gdImagePng(im_out, out);
fclose(out);
gdImageDestroy(im_in);
gdImageDestroy(im_out);
... Inside a function ...
gdImageCopyMerge(im_out, im_in, 100, 200, 0, 0, 30, 50, 50);
... Inside a function ...
gdImageCopyMergeGray(im_out, im_in, 100, 200, 0, 0, 30, 50, 50);
Miscellaneous Functions
... Inside a function ...
cmpMask = gdImageCompare(im1, im2);
gdImagePtr im;
FILE *out;
/* ... Create or load the image... */
/* Now turn on interlace */
gdImageInterlace(im, 1);
/* And open an output file */
out = fopen("test.png", "wb");
/* And save the image -- could also use gdImageJpeg */
gdImagePng(im, out);
fclose(out);
gdImageDestroy(im);
free()
that is ultimately called will
be intended for use with the version of malloc()
that
originally allocated the block.
Constants
gdMaxColors
(CONSTANT)
About the additional .gd image file format
In addition to reading and writing the PNG and JPEG formats and reading the
X Bitmap format, gd has the capability to read and write its
own ".gd" format. This format is not intended for
general purpose use and should never be used to distribute
images. It is not a compressed format. Its purpose is solely to
allow very fast loading of images your program needs often in
order to build other images for output. If you are experiencing
performance problems when loading large, fixed PNG images your
program needs to produce its output images, you may wish
to examine the functions
gdImageCreateFromGd and gdImageGd,
which read and write .gd format images.
About the .gd2 image file format
In addition to reading and writing the PNG format and reading the
X Bitmap format, gd has the capability to read and write its
own ".gd2" format. This format is not intended for
general purpose use and should never be used to distribute
images. It is a compressed format allowing pseudo-random access
to large image files. Its purpose is solely to
allow very fast loading of parts of images
If you are experiencing
performance problems when loading large, fixed PNG or JPEG images your
program needs to produce its output images, you may wish
to examine the functions
gdImageCreateFromGd2,
gdImageCreateFromGd2Part and gdImageGd2,
which read and write .gd2 format images.
About the gdIOCtx structure
Version 1.5 of GD added a new style of I/O based on an IOCtx
structure (the most up-to-date version can be found in gd_io.h):
typedef struct gdIOCtx {
int (*getC)(struct gdIOCtx*);
int (*getBuf)(struct gdIOCtx*, void*, int);
void (*putC)(struct gdIOCtx*, int);
int (*putBuf)(struct gdIOCtx*, const void*, int);
int (*seek)(struct gdIOCtx*, const int);
long (*tell)(struct gdIOCtx*);
void (*free)(struct gdIOCtx*);
} gdIOCtx;
Most functions that accepted files in previous versions now also have a
counterpart that accepts an I/O context. These functions have a 'Ctx'
suffix.
All Must have 'free', Anything that reads from the context Must have 'getC' and 'getBuf', Anything that writes to the context Must have 'putC' and 'putBuf'. If gdCreateFromGd2Part is called Must also have 'seek' and 'tell'. If gdImageGd2 is called Must also have 'seek' and 'tell'. Please tell us you're using gd!
When you contact us and let us know you are using gd,
you help us justify the time spent in maintaining and improving
it. So please let us know. If the results are publicly
visible on the web, a URL is a wonderful thing to receive, but
if it's not a publicly visible project, a simple note is just
as welcome.
If you have problems
If you have any difficulties with gd, feel free to contact
the author, Thomas Boutell.
Problems relating to the gd2 format should be addressed to
Philip Warner.
Alphabetical quick index
gdBrushed |
gdDashSize |
gdFont |
gdFontPtr |
gdFree |
gdImage |
gdImageAlphaBlending |
gdImageArc |
gdImageBlue |
gdImageBoundsSafe |
gdImageChar |
gdImageCharUp |
gdImageColorAllocate |
gdImageColorAllocateAlpha |
gdImageColorClosest |
gdImageColorClosestAlpha |
gdImageColorDeallocate |
gdImageColorExact |
gdImageColorExactAlpha |
gdImageColorResolve |
gdImageColorResolveAlpha |
gdImageColorTransparent |
gdImageCopy |
gdImageCopyMerge |
gdImageMergeGray |
gdImageCopyResized |
gdImageCopyResampled |
gdImageCreate |
gdImageCreatePalette |
gdImageCreateTrueColor |
gdImageCreateFromGd |
gdImageCreateFromGd2 |
gdImageCreateFromGd2Part |
gdImageCreateFromJpeg |
gdImageCreateFromPng |
gdImageCreateFromPngSource |
gdImageCreateFromXbm |
gdImageCreateFromXpm |
gdImageDashedLine |
gdImageDestroy |
gdImageFill |
gdImageFilledArc |
gdImageFilledEllipse |
gdImageFillToBorder |
gdImageFilledRectangle |
gdImageGd |
gdImageGd2 |
gdImageGetInterlaced |
gdImageGetPixel |
gdImageGetTransparent |
gdImageGreen |
gdImageInterlace |
gdImageJpeg |
gdImageLine |
gdImageFilledPolygon |
gdImagePaletteCopy |
gdImagePng |
gdImagePngToSink |
gdImagePolygon |
gdImagePtr |
gdImageWBMP |
gdImageRectangle |
gdImageRed |
gdImageSetBrush |
gdImageSetPixel |
gdImageSetStyle |
gdImageSetTile |
gdImageString |
gdImageString16 |
gdImageStringFT |
gdImageStringTTF |
gdImageStringUp |
gdImageStringUp16 |
gdImageWBMP |
gdMaxColors |
gdPoint |
gdStyled |
gdStyledBrushed |
gdTiled |
gdTransparent


Module : config
Module Overview
This module provides the Config API to read configurations from environment variables, TOML files, and command-line parameters and build a consolidated set of configurations.
The precedence order for configuration lookup is as follows:
- CLI arguments (used with the --)
- Environment variables
- Configuration files in the TOML format
This configuration resolution happens at the start of the program execution. Configurations can be set programmatically as well.
The Config API provides the capability to feed sensitive data (e.g., passwords) to Ballerina programs securely by encrypting them.
Setting configurations
To specify a configuration file explicitly, the --b7a.config.file=<path to configuration file>
property can be used. If
this property is not set when
running a project, Ballerina looks for a ballerina.conf
file in the project root. When running a single file or a
.jar
, it's picked from the same directory in which the .jar
or source resides. The path to the configuration
file can either be an absolute or a relative path.
ballerina run my-program.bal --b7a.config.file=/path/to/conf/file/custom-config-file-name.conf
A configuration file should conform to the TOML format. Ballerina only supports the following features of TOML: value types (string, int, float and boolean), tables, and nested tables. Given below is a sample:
[b7a.http.tracelog]
console=true
path="./trace.log"
[b7a.http.accesslog]
console=true
path="./access.log"
A key given inside a bracket forms a namespace. Any configuration that is specified between two such keys belongs to the namespace of the first of these keys. To access a configuration in a namespace, the fully qualified key should be given (e.g., b7a.http.tracelog.path
).
The following types can be given through a configuration file: string
, int
, float
, and boolean
. If the configuration value is not an int
, float
, or a boolean
, it is considered a string
and should always be quoted.
The same configs can be set using CLI parameters as follows.
ballerina run my-program.bal --b7a.http.tracelog.console=true --b7a.http.tracelog.path=./trace.log
--b7a.http.accesslog.console=true --b7a.http.accesslog.path=./access.log
Configurations in a file can be overridden by environment variables. To override a particular configuration, an environment variable that matches the configuration key must be set. As periods are not allowed in environment variables, periods in a configuration key should be replaced by underscores.
// In Linux and Mac.
$ export b7a_http_tracelog_path=”./trace.log”
$ export b7a_http_accesslog_path=”./access.log”
// In Windows.
$ set(x) b7a_http_tracelog_path=”./trace.log”
$ set(x) b7a_http_accesslog_path=”./access.log”
If the configurations need to be shared during runtime, they can be set using the setConfig()
function.
config:setConfig("john.country", "USA");
Reading configurations
The API provides functions to read configurations in their original type. Check function descriptors for example usages.
A set of configurations belonging to a particular namespace can be retrieved as a map
using the getAsMap()
function. Here is an example:
[b7a.http.tracelog]
console=true
path="./trace.log"
host="localhost"
port=5757
[b7a.http.accesslog]
console=true
path="./access.log"
The configurations for HTTP trace logs can be retrieved as a map
as follows:
// Reads a configuration section as a map.
// Here, the map’s key-value pairs represent config key-value pairs.
map<anydata> serverAlphaMap = config:getAsMap("b7a.http.tracelog");
Securing configuration values
Sensitive values can be encrypted using the encrypt
command as follows:
$ ballerina encrypt
Enter value:
Enter secret:
Re-enter secret to verify:
Add the following to the runtime config:
@encrypted:{JqlfWNWKM6gYiaGnS0Hse1J9F/v48gUR0Kxfa5gwjcM=}
Or add the following to the runtime command-line:
-e<param>=@encrypted:{JqlfWNWKM6gYiaGnS0Hse1J9F/v48gUR0Kxfa5gwjcM=}
This encrypted value can then be placed in a configuration file or provided as a CLI parameter.
[admin]
password=”@encrypted:{JqlfWNWKM6gYiaGnS0Hse1J9F/v48gUR0Kxfa5gwjcM=}”
Reading config files with encrypted values
When trying to run a Ballerina program with a configuration file or CLI parameters that contain encrypted values, Ballerina will first check to see if the b7a.config.secret
configuration is set. This configuration is used to set the path to a file containing the secret required to decrypt the configurations. If it is set, the secret is read, and the secret file is deleted.
If a secret file is not provided, the user is prompted to enter the secret. Values are decrypted only on demand when an encrypted value is looked up using the getAsString()
function.
$ ballerina run program.bal
ballerina: enter secret for config value decryption:
Note: The same config file cannot contain values that are encrypted using different secrets.
| contains |
Checks whether the given key is in the configuration registry. |
| getAsArray |
Retrieves the specified configuration value as an array. |
| getAsBoolean |
Retrieves the specified configuration value as a boolean. |
| getAsFloat |
Retrieves the specified configuration value as a float. |
| getAsInt |
Retrieves the specified configuration value as an int. |
| getAsMap |
Retrieves the specified configuration value as a map. |
| getAsString |
Retrieves the specified configuration value as a string. |
| setConfig |
Sets the specified key/value pair as a configuration. |


Breach: How you will notify the user and protect the user's data in case of an improper disclosure
You must comply with all applicable laws regarding breaches. Describe how you will notify the user and protect the user’s data in the case of a breach. Provide link to section in privacy policy.


Rectangle
Rounded
Pill
Circle
Dot
Inline
Rect
Round
Pill
99+
^ RTL
Rect
Round
Pill
99+
top start
top end
bottom start
bottom end
Inside
Rect
Rect
Rect
Rect
Edge
Rect
Rect
Rect
Rect
Outside
Rect
Rect
Rect
Rect
Inside RTL
Rect
Rect
Rect
Rect
Edge RTL
Rect
Rect
Rect
Rect
Outside RTL
Rect
Rect
Rect
Rect


Our favorite places
These are a few of our favorite things.
Here are some of Benjamin's favorite Race Tracks
PIR/
Californa Drift Park
Woodburn drag strip
My Horse Ranch
Here are some of Bo's favorite places
home
Epicouds
road from home to Epicouds


Two story buildings with spacious 850 ft² apartments—recently upgraded
Each with:
■ 2 Large Bedrooms
■ 1 Bathroom
■ Open Living Room & Dining Room
■ Kitchen with a Stove & Refrigerator
■ Walk-in Closets
■ Washer & Dryer
Hot & cold water + easy trash pick-up is covered for you—you only need to pay for electricity


--- layout: default title: 404 - Page not found permalink: /404.html img: - "/assets/404Fun.png" - "/assets/404Pixar.png" ---


{# Put your view macros here. If you find yourself repeating the same markup a lot, consider wrapping it in a macro. They're basically view helper functions that output HTML. #} {% macro renderMessagePanel(ctx, message) %} {% if can(ctx.currUser, 'READ_MESSAGE', message) %}


CHAPTER 5.4.2: The Ethernet
- Ethernet was the first widely deployed high-speed LAN.
- Token ring, FDDI, and ATM were more complex and expensive than Ethernet, which further discouraged network administrators from switching over.
- The most compelling reason to switch to another LAN technology (such as FDDI or ATM) was usually the higher data rate of the new technology
- The original Ethernet LAN used a coaxial bus to interconnect the nodes.
- A hub is a physical-layer device that acts on individual bits rather than frames. When a bit, representing a zero or a one, arrives from one interface, the hub simply re-creates the bit, boosts its energy strength, and transmits the bit onto all the other interfaces.
-
Frame Structure:
- Data field (46 to 1,500 bytes)
- Destination address (6 bytes)
- Source address (6 bytes)
- Type field (2 bytes)
- Cyclic redundancy check (CRC) (4 bytes)
- Preamble (8 bytes)


There should be a sentence before this, and one after, forming a single paragraph.
There should be a sentence before this, and one after, each as its own block.
This should have chonky quotation marks.
This is some text. Each link should have a little icon before it, and this one has a tooltip too.


flow - setup helper - requirements
home
Some platforms have post requirements, which are listed on the index page as step two.
If you already have any of the requirements installed, you can skip to the next step.
mac and ios target requirements
Xcode
Xcode is a free development environment provided by Apple for Mac.
You need version 4 or 5 installed as well as the command line tools.
linux target requirements
GCC / G++
To build native applications on linux you need a gcc/g++ install using the method that best suites your distro.
distro specific suggestions
Ubuntu
apt-get
can be used to install the requirements using the following commands in the terminal Ubuntu 12~14
sudo apt-get install gcc-multilib g++-multilib libxext-dev
windows target requirements
Visual C++
Visual C++ is a development environment provided by Microsoft for Windows.
You need 2010 C++ or higher, the link above is for Visual C++ Express 2010.
android target requirements
Android SDK
You only need the SDK Tools, as long as you know the path to the SDK.
You need to manually install target platforms you want to target,
documented in the Android SDK, available by running the android sdk manager.
Android NDK
Since android applications are often built as native applications, the NDK install is a good idea.
web target requirements
When building against the web target, there is no setup required.
You can skip to the next step.


It's been awhile since we've had a Remains of the Day post, so it's good to get back at it. This edition comes to you courtesy of Midwest Ultimate's Wisconsin Swiss afterparty. The tournament party's beers of choice were from Madison's own Capital Brewery, and the selection included the famous Capital Amber, the delightful Island Wheat, and their summer seasonal, the Lakehouse Lager. I was blessed with the opportunity to bartend for this wonderful party, which of course meant I got to take a little home with me at the end of the day, so of course, pancakes.
As with all RotD, the downside is the beer is from the night before, so it's usually a little flat and not exactly the fairest representation. That being said, it's still beer, and it's only a day old, and they're becoming pancakes either way, so how pure it is might be debatable in the first place. Either way, the two beers we have today are the Amber and the Island Wheat.
Pretty much anyone who's been to Madison before has had Capital's Amber, an if you haven't, you're doing it wrong. The amber is delightfully malty while still being light enough to be drinkable (all the while clocking in at 5.8% ABV). The Island Wheat is a wonderfully summery beer that's crisp yet flavorful in all of its wheaty glory. As pancakes, though, the story gets much more interesting.
As with all RotD, the downside is the beer is from the night before, so it's usually a little flat and not exactly the fairest representation. That being said, it's still beer, and it's only a day old, and they're becoming pancakes either way, so how pure it is might be debatable in the first place. Either way, the two beers we have today are the Amber and the Island Wheat.
| Yes, those are water bottles in the background. And frozen pork shoulder. |
Prep/Cooking:
When it comes to batters, there wasn't anything particularly special about these two. Their distinct colors from beer form almost entirely vanished in the batter, and they came out looking almost identical from a color standpoint. This color indistinguishability carried through in the pancakes, as well.
There was one interesting property, though. I wish I had an explanation as to why it happened, too. Despite being pretty flat in beer form (no thanks to their wonderful storage mechanism), the amber pancakes were extremely bubbly while cooking. It was weird. I could see right through them the bubbles were so big/extensive.
There was one interesting property, though. I wish I had an explanation as to why it happened, too. Despite being pretty flat in beer form (no thanks to their wonderful storage mechanism), the amber pancakes were extremely bubbly while cooking. It was weird. I could see right through them the bubbles were so big/extensive.
| I'mma be poppin' that bubbly... |
Results:
The not-so-speciality of the batter carried through to the pancakes for the Amber, unfortunately. They weren't exactly bad, but there was nothing really about them to make them memorable or worthwhile. Much better in beer form. The wheat, however, is an entirely different story.
| Prepare yourselves |
One of the things I've discovered over the course of this blog is that wheat beers tend to make better pancakes than any other beer type I've come across, and the Island Wheat does not disappoint. The pancakes had a delicious, almost sweet flavor to them. The pancakes really brought out the wheat qualities of the beer all the while maintaining the crisp, summery feel it has in liquid form.
The Ternary Scale:
Amber
Pancakes: 1 - Meh. If you have it, try it, but I wouldn't go out of your way or really say it's something you have to have.
Syrup: 1 - Meh again. Didn't really help or hurt the pancakes.
Wheat
Pancakes: 2 - HOLY JESUS YES. These might be some of the best pancakes I've ever made on this blog. You need to make these
Syrup: 0 - I wouldn't bother wasting the syrup or the pancakes, as it didn't really help or hurt at all.
| Nom nom nom |


Properties
Static anyBoolean
anyBoolean: number = 1
Static checksum
checksum: number = 18
Static cmpId
cmpId: number = 12
Static cmpVersion
cmpVersion: number = 12
Static consentLanguage
consentLanguage: number = 12
Static consentScreen
consentScreen: number = 6
Static created
created: number = 36
Static encodingType
encodingType: number = 1
Static isServiceSpecific
isServiceSpecific: number = 1
Static lastUpdated
lastUpdated: number = 36
Static maxId
maxId: number = 16
Static numCustomPurposes
numCustomPurposes: number = 6
Static numEntries
numEntries: number = 12
Static numRestrictions
numRestrictions: number = 12
Static policyVersion
policyVersion: number = 6
Static publisherCountryCode
publisherCountryCode: number = 12
Static publisherLegitimateInterest
publisherLegitimateInterest: number = 24
Static publisherPurposeConsents
publisherPurposeConsents: number = 24
Static purposeConsents
purposeConsents: number = 24
Static purposeId
purposeId: number = 6
Static purposeLegitimateInterest
purposeLegitimateInterest: number = 24
Static purposeOneTreatment
purposeOneTreatment: number = 1
Static restrictionType
restrictionType: number = 2
Static segmentType
segmentType: number = 3
Static singleOrRange
singleOrRange: number = 1
Static specialFeatureOptIns
specialFeatureOptIns: number = 12
Static useNonStandardStacks
useNonStandardStacks: number = 1
Static vendorId
vendorId: number = 16
Static vendorListVersion
vendorListVersion: number = 12
Static version
version: number = 6


Wanna know your fortune? Look no further!  Just answer the questions below and we'll let you know!
Which of these have you seen in the past week? Select all that apply:
What do you see in these tea leaves?
Pick your favorite colors:


WITNESS LIST Nominations Committee February 17, 1997-2:00P Texas State Board of Education For: Jack R. Christie (himself), Houston Tx A&M Board of Regents For: Anne L. Armstrong (herself), Armstrong Dionel E. Aviles (himself), Houston Erle A. Nye (himself), Dallas Tx Higher Ed Coordinating Board For: Dolores Carruth (herself), Irving Jodie L. Jiles (himself), Houston Leonard Rauch (himself), Houston Martin Basaldua (himself), Kingswood Pamela P. Willeford (herself), Austin Robert I. Fernandez (himself), Fort Worth Robert W. Shepard (himself), Harlingen Steve Late (himself), Odessa William C. Atkinson (himself), Bryan


Documentation
Github link:
https://github.com/pmservice/drug-selection
This sample application adopts SPSS Modeler stream Drug1N.str, Watson Machine Learning service on Bluemix platform for drug selection.
With this application you are able to:
- provide patient personal data and patient blood test result using web application form
- run scoring model by pressing "Check Now" button
- display information about recommended drug (scoring result) in form of table


Live from Thoughtworks
Talk to us on Twitter using the hashtags #PanelForParity and #WomenHack
Eli is a Software Developer and recently moved to the UK from her sunny home country of Nicaragua to pursue a Master's Degree in Advanced Computing at Birkbeck College, University of London. When she is not in class, you can find her working at a digital marketing agency, trying to fight the bitter british cold, and attending tech meetups.
Tweet nice things at her @elibelly
Funmi holds a Bachelor of Science degree in Electrical Engineering from Howard University in Washington DC, but decided to follow her passion for coding into a career in software development instead. She spent three exciting years in New York working on a variety of server-side, front-end, and scripting projects, before relocating to London in search of a new type of adventure. She is currently a Vice President and full stack software developer and product manager at an investment bank in the city.
Funmi is an avid runner and world explorer, jumping at every opportunity she gets to race or travel. She also enjoys volunteering and experimenting with various technologies in her free time. She is currently an active volunteer and board member for Women Hack for Non-Profits.
Women Hack for Non-Profits matchmakes skilled women in technology to open source projects for non-profits, charities and individuals with a good social cause. By doing so, we aim to enhance the skill set of Women in Tech to support their growth and increase their footprint in the open source community.
From planning and design to build and deployment, we offer non-profits a professional community of volunteers dedicated to bringing life to meaningful projects.
We provide our volunteers with a supportive environment to contribute and learn new skills through real-world practice, a growing shared knowledge base, workshops and ongoing tech events. If this sounds like something you are passionate about, join us!
Parity is the state or condition of being equal, especially as regards status or pay. Women all over the world are still fighting for equality, not just economically but representation, media treatment and many other ways.
The primary aim of WHFNP is encourage women to contribute to the open source community. Currently the male to female ratio in technology roles in the UK is unbalanced, with women only taking up roughly 14% of the roles in the industry.
Everyday our volunteers are actively striving to make that balance happen. Including taking part in this panel discussion.
An ex-Vice President Goldman Sachs, London, Vinita is a Tech Architect and Product Manager with 10+ years technology experience and the founder of Systango, an IT agency that helps founders and companies build tech products.
In her community time, Vinita is Director of the Women Who Code, London Chapter and is one of the founders of Women Hack For Non-Profits
Hera co-founded Chayn, an open-source project empowering women against oppression and enabling them through technology. She also partners with Empowerhack, an organisation aiding female refugees which she represented during the Techfugees Global Consultation Week live stream, and recently gave a TedX talk highlighting Chayn's outstanding work and mission.
Jade is part of the recruitment team at ThoughtWorks and is usually touring the UK in order to ensure her company have an awesome and diverse intake. She is not just extremely passionate about women in tech, but about equality in general.
Jade's ambitious dream is to inspire our future generation to be braver and proud of who they are.
Programme Manager at Code First: Girls, a social enterprise which works with companies and women to increase the proportions of women in tech and entrepreneurship. Prior to this she worked at The Cultural Institute at King's managing a broad portfolio of collaborative projects and co-founded an edutech startup Eulergy.com.
She recently completed her PhD at King's College London and is now learning to code with support of Code First: Girls.
Outside of his consultancy role Eddie enjoys attending and contributing to hackathons and conferences around the world which deal with a variety of technical and social issues. His first foray into the realm of Women's issues was EmpowerHack's "Empowering women and girl refugees" hackathon. Since then Eddie has contributed to EmpowerHack's Open Source projects from a technical perspective and has also brought his expertise and infectious enthusiasm to actively support the growth of women in tech at WHFNP and AcornAspirations. He has been likened to Sheldon Cooper from "The Big Bang Theory" with marginally more social skills.


Emmerdale SPOILERS: Pregnancy fears for Leanna as she sleeps with Jacob
Jacob was groomed by Leanna's ex-stepmother Maya
by Charlotte RodriguesIt looks like Leanna could be expecting after she throws up the morning after pill after sleeping with Jacob Gallagher in next week's Emmerdale.
David reveals to Leyla that paedophile Maya Stepney, who groomed their son Jacob, is being released from prison leaving her worried she may try to contact the teen.
They make the decision to tell Jacob about Maya's release and they are surprised at how composed he is.
Later Leanna tries to be supportive but Jacob tries to leave quickly and quietly.
Realising he's gone, David and Leyla worry that he's gone to try to meet Maya. Will they manage to track him down before it's too late?
Later, back at the village Jacob tries to speak to Leanna and after a passionate kiss, they end up sleeping together.
Afterwards, Jacob begins to act distant and quickly leaves, leaving Leanna upset.
She later decides to tell her dad's fiancée Bernice about sleeping with Jacob, but the beautician is left conflicted when Leanna asks her not to tell her dad Liam.
However when Leanna throws up in front of Liam as a result of taking the morning after pill, Bernice is forced to come clean and tell her soon-to-be husband about Leanna and Jacob.
Read More: Emmerdale viewers heartbroke as Vanessa dumps Charity
Before long, Liam is barging into the shop and accusing Jacob of forcing his daughter into sleeping with him.
Things soon turn violent when the doctor punches the teenager and later everyone is in shock when Liam is arrested under suspicion on assault.
Read More: FIRST LOOK: Next week's Emmerdale in 10 p ictures
But will Leanna fall pregnant with Jacob's baby after throwing up her emergency contraception?
Viewers know Leanna is Maya's former stepdaughter and that the pair never got on. Could this be the latest twist following Maya's release?
Emmerdale airs weeknights at 7pm on ITV, with an extra episode at 8pm on Thursdays.
Leave us a comment on our Facebook page @EntertainmentDailyFix and let us know what you think!


The Sneakers Game
In 1934 the
New York Giants beat the
Chicago Bears, by
30-13,
in nine-degree temperatures
[ at the Polo Grounds ]
in a game that has become famous as the "Sneakers Game". With the Giants trailing
10-3 at the half, head coach Steve Owen provided his squad
with basketball
shoes to increse traction on the icy turf. The team responded with four touchdowns in the second half to turn
the game into a
Giants rout.


Post of the Week The Information Commisssioner’s Office and The Alan Turing Institute are teaming up to publish their first draft of guidance into the use of ‘AI’.
Yippie kayak, other buckets!
A New Hope
Who’s more foolish? The fool or the fool who follows him?
Party all the time
Time is limited this week, so expect a rushed description of the content, but it is still better than no content!

The fast and the furious
Hobbs & Shaw wasn’t actually that bad… Post of the week This week has been spent mostly reading mathematics (which I won’t bore you with) so my post of the week is the light summary of OpenAI releasing that they said was too dangerous.