|
|
Subscribe / Log in / New account

Creating/Manipulating Images with gd (Linux Journal)

Linux Journal uses gd, an open source library, to create and manipulate images. "It lets you open images in formats such as JPEG, PNG, XPM and a few more. gd works something like this: it opens images in different formats and converts them to generic bit-mapped images in memory. It then lets you do graphical operations, such as drawing lines, arcs, ellipses or rectangles on that image, and stores the resulting image in any of the earlier-mentioned formats. For example, you could write a simple command-line program that converts a given file in JPEG format to PNG using gd. gd also can change colors in the image and copy, cut, merge or rotate it."

to post comments

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 10, 2006 20:27 UTC (Tue) by rknop (guest, #66) [Link] (14 responses)

Hmm- my first thought upon seeing the blurb was, "what does this do that we haven't done for years and years with the netpbm utilities?" However, the libraries may be more extensive and have better manipulation/drawing type abilities. (Netpbm is great for stringing together commands with a pipe to make an alias to do something you want.)

Before I decide that this is just another imitation of netpbm, then, I should actually look at the libraries. Of course, there's also the image magik libraries, and I haven't used those much.... Most images I really manipulate are all floating point science images, which are a different deal; when I've needed to do codeable drawing and such, I've written plugins for the Gimp in Perl.

-Rob

Has its uses

Posted Jan 10, 2006 20:51 UTC (Tue) by felixfix (subscriber, #242) [Link]

It's been a while since I used it, but it has a nice simple interface. You can use it from C and Perl and no doubt many other languages. I used it quite a bit at one job, making plots for dynamically loaded graphs for annuities and other such fun stuff. I don't know anything about ImageMagick libraries, and I thought netpbm was for shell scripts. But it's been a while since I needed any of this. I have some of my own projects on the way back burner for which I would use GD if I were to start them now.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 0:49 UTC (Wed) by jasone (subscriber, #2423) [Link]

gd provides lower-level interfaces than the netpbm programs do (and apparently higher level interfaces than libnetpbm). gd is more cumbersome for tasks that pipelines of netpbm programs can handle, but gd is also more powerful. It's straightforward to create images for which you control the value of every pixel.

I've found gd particularly useful for programmatically generating custom graphs. For example:

http://people.freebsd.org/~jasone/jemalloc/plots/kldxref.png

Jason Evans

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 2:24 UTC (Wed) by flewellyn (subscriber, #5047) [Link]

Among other things, GD is a core component of UMN Mapserver, the best free GIS webmapping tool out there, in my opinion. It creates dynamic maps from various GIS datasources, and uses GD to generate the images. Wouldn't exist without GD, at least for the output.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 8:15 UTC (Wed) by MortFurd (guest, #9389) [Link]

GD is commonly used with PHP. PHP includes its own enhanced GD libraries since PHP 4.3 came out.

I know of some photo gallery web sites that use GD to generate the preview pictures and to generate the watermarks in the photos.

I've also seen GD used to dynamically generate the text on graphical buttons on web sites. It looks like a waste of effort, but if the site changes often and you need to add new menu entries that match the existing buttons then it seems to work out well. It also beats having to have the graphic designer who dreamed up the buttons remember how he did the originals and go back to him to have new ones made.
The buttons are usually cached on the web server, so the buttons aren't regenerated on every access. GD uses the freetype libraries to create a bitmap with the text, so that may be one morething to set it apart from the other libraries.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 9:46 UTC (Wed) by evgeny (subscriber, #774) [Link] (8 responses)

> Netpbm is great for stringing together commands with a pipe to make an alias to do something you want

Unfortunately, the accompanying netpnm library is restricted to basic I/O stuff only. A lot of useful functionality (resizing/rotating/cropping/...) is stick into respective executables instead of being available as a C API. A pity - I, for example, can't find a simple portable library for the above tasks.

Regarding GD - it's simple and nice for simple tasks, but once you begin worring about the quality, it becomes inadequate. Drawing thin lines, patterned lines, control of beveling, linecaps,... If you're interested in an _accurate_ device-independent pixmap drawing, I strongly suggest libxmi (http://www.gnu.org/software/libxmi/). It's based on the X model, so everything that exist in the 2D X drawing API is there, too, with the same level of quality. And it's very fast as well.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 16:36 UTC (Wed) by bk (guest, #25617) [Link] (5 responses)

What about cairo? Isn't that what it's designed for?

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 22:25 UTC (Wed) by evgeny (subscriber, #774) [Link] (4 responses)

Cairo depends on quite a few libraries, the most annoying being the X11 stuff. Obviously, this makes it unusable in the [web]server deployments. Same problem as of imlib, libMagic, etc.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 12, 2006 11:47 UTC (Thu) by dcoutts (guest, #5387) [Link] (3 responses)

No, X11 is merely one of the many cairo backends. You can build it with just the PNG backend.

It doesn't depend on much else in fact, just fontconfig, freetype & zlib. In other words it has the same deps as gd (when gd is built with optional truetype and png support). It should be perfectly suitable for use on a web server.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 12, 2006 13:26 UTC (Thu) by evgeny (subscriber, #774) [Link] (2 responses)

> No, X11 is merely one of the many cairo backends.

I guess you're right. But all Linux distros ship it with the X11 backend, so you have no straightforward choice. Hopefully, they'll learn to make it as an optional loadable module.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 15, 2006 16:18 UTC (Sun) by bk (guest, #25617) [Link] (1 responses)

Gentoo is perfectly capable of building Cairo without the X backend.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 15, 2006 20:04 UTC (Sun) by evgeny (subscriber, #774) [Link]

... with the obvious result that most of the apps currently using Cairo [for drawing on X] stop working. All backends must be optional, but not at the compile time - at the run time.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 22:58 UTC (Wed) by sfeam (subscriber, #2841) [Link] (1 responses)

> once you begin worring about the quality, it becomes inadequate. Drawing thin lines, patterned lines, control of beveling, linecaps...

GD is used by recent versions of gnuplot, and produces very nice plots indeed. I agree that its handling of antialiasing is inadequate (except for fonts, where it uses libfreetype). However some of the other issues you mention, like beveling, are not an intrinsic limitation of the library, just an unfortunate choice of default settings. You can get better line quality and line joins by defining your own brushes rather than using the default.

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 12, 2006 14:24 UTC (Thu) by evgeny (subscriber, #774) [Link]

> GD is used by recent versions of gnuplot,

I thought gnuplot uses by default plotutils which in turn uses libxmi?

Creating/Manipulating Images with gd (Linux Journal)

Posted Jan 11, 2006 16:58 UTC (Wed) by ballombe (subscriber, #9523) [Link]

You can actually make drawing rather than just processing existing images.
For example the graphs at http://popcon.debian.org/ are made using gd
(through the Chart perl module).


Copyright © 2006, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds