site stats


PNGwriter logo




PNGwriter is a C++ library for creating PNG images.


(If you can't see the navigation frame at the left of the page, then click here).


Latest News:
New version and a new team member — August 2015 Update

A long time has passed since PNGwriter's last release. Thanks to the skilled and generous help of Axel Hübl (@ax3l) many bugs have been fixed, a new compilation procedure is in place, and PNGwriter is now on GitHub. Axel is now an active and invaluable member of the PNGwriter Team, joining Paul Blackburn, who created PNGwriter in 2002. Welcome aboard, Axel!

This nudge to action could not have come at a better time, since the once-respectable host to the PNGwriter project, SourceForge.net, is no longer what we consider a positive contribution to the Open Source community. This website and currently-hosted files will remain on SourceForge.net, but the current and all future releases will be via PNGwriter's GitHub repository. Don't forget!

Thank you, PNGwriter users, for your patience, bug fixes, and suggestions. I hope you are as excited as we are to see where the next thirteen years take PNGwriter!

Paul Blackburn
San Jose, California  Flag of California
August 31st, 2015

Summary

PNGwriter is a very easy to use open source graphics library that uses PNG as its output format. The interface has been designed to be as simple and intuitive as possible. It allows:
  • Plotting and reading pixels in the following colour spaces:
    • RGB (red, green, blue)
    • HSV (hue, saturation, value/brightness)
    • CMYK (cyan, magenta, yellow, black);
  • Basic shapes;
  • Scaling;
  • Bilinear interpolation;
  • Full TrueType antialiased and rotated text support;
  • Bezier curves;
  • Opening existing PNG images;
  • And more!
Also:
  • Documentation in English (and Spanish up to v0.5.4).
  • Runs under Linux, Unix, Mac OS X and Windows.
  • Requires libpng and optionally FreeType 2 for the text support.

The PNGwriter project's online presence consists of:



Frequently Asked Questions:















If your questions are not answered here, then come and ask us on the PNGwriter Issue Tracker on GitHub.





Why use the PNGwriter library?

Because it is a fast and easy way of plotting directly from your C++ program.

PNGwriter lets you focus on your program, and saves you the trouble of learning how to create, use and read PNG images from scratch. You just need to specify what size you want your image, and then you plot pixel by pixel in a given colour with the plot function.

PNGwriter was originally written with scientists in mind. The need to create an image from the result of a scientific computer simulation arises as a natural part of scientific and engineering programming. Getting the data out of the program and into a high quality image in an efficient way can sometimes be hard, especially if the user is not a very experienced programmer. The methods used can often be highly inefficient or too complex to be feasible, especially if there isn't much time available.

PNGwriter was written as a possible solution to this issue. Its interface is extremely intuitive, there is only one new object to learn about (the PNGwriter class)—in other words, no classes and subclasses for pixels, colours, bitmaps, filenames, etc. As long as you know what colour you want the pixel at position (x, y) to be, you can implement any algorithm you want. Want to play with cellular automata but are tired of seeing you results as an array of 1s and 0s in text? Want to have a go at exploring fractals yourself? Need a quick way to feed images into that reverse neural network algorithm you are working on? Want to simulate gravitational lensing but haven't yet been able to create an actual image from your algorithm? PNGwriter can help!



What can I do with PNGwriter?

PNGwriter enables you to do the following with an image:

  •       Plot pixels
  •       Get the colour of a pixel
  •       Open an existing PNG file.
  •       Plot in the HSV and CMYK colour spaces.
  •       Get the colour of a pixel in the HSV and CMYK colour spaces.
  •       Plot lines, filled or hollow circles and rectangles, opaque and translucent.
  •       Plot text, using any TrueType font.
  •       Adjust the image's gamma.
  •       Choose the level of compression.
  •       Change the file name.
  •       Scale the image.
  •       Get the height, width and bit depth of an image.
  •       …and much more!.


Since one can generate an arbitrary number of PNG images with only one run of your program, and given that PNGwriter provides an easy way to rename files given just an index number, creating movies of sequential images is now extremely easy. For this, one would just use FFmpeg, MEncoder, or Apple's QuickTime Player.



What *can't* I do with PNGwriter?

There are certain things that PNGwriter will not do. For example, though PNGwriter (as of version 0.5.5) can read a very wide variety of PNG images, there are some variants that it has problems with. In summary:

  • Alpha channel information is completely discarded when reading PNG images.
  • Images with GIF-style transparency will not be read properly.
  • Some images will be read with a slightly different chromatic quality.

Despite these limitations, PNGwriter will most likely read the majority of PNGs that you throw at it. Please see the Examples section for a detailed list of test images and how PNGwriter deals with them.



Why use PNG images?

Because they are widely known and they use lossless compression.

They share some characteristics with GIF images, but unlike this format, PNG images are not tied to the copyright of the LZW compression that GIFs use.

The PNG format is open, free, and good.

They allow for Alpha Channels (better than simple uniform transparency, though please note that PNGwriter does not support alpha channels) and a whole lot of other useful and interesting things.

You don't even have to convert the PNG images your program can make with PNGwriter if you want to use them on a web page, for example: as a matter of fact, PNG stands for Portable Network Graphics—they were designed for internet use and any decent browser can view them. Most of the graphics on this site are PNG images.

For more information, please visit www.libpng.org.



Who might benefit from using this C++ library?

In 2002 created PPMWriter, the precursor to PNGwriter, because I wanted something that would allow me to plot pixel by pixel to an image, giving the coordinates and colour coefficients. I chose the PPM format because I couldn't wrap my head around the more complex image formats, the standard libraries required to use them, and their interfaces. It was useful, yet limited by the extreme simplicity of the PPM format, and there weren't many programs that could open PPM images properly. So I wrote PNGwriter.

In principle it could be useful to anyone that needs to plot images of high quality generated by their C++ programs (simulations, calculations, etc.), and not diagrams or (x, y) line plots.



What do I need to be able to use PNGwriter?

A C++ compiler, and libpng. libpng works on Unix, DOS, OS/2, Windows, Mac OS, BeOS, Amiga, etc. If your compiler is old, my personal recommendation is to get GCC. Also, if you wish to compile PNGwriter with text support, you will need FreeType 2. If you're on Windows, check the How can I use PNGwriter under Windows? section.



Sounds interesting, how is PNGwriter used?

If you want to see an example of the simplest possible use of PNGwriter, go to Quickstart. That is the bare minimum that you need to know to be able to use PNGwriter (and all you need to know, in most cases).
If you want to see more examples of PNGwriter in use, go to Examples.
If you want to have a look at the PNGwriter manual go to Manual. The PNGwriter package available on GitHub contains two complete examples and a PDF Manual. The header file for the library is also extensively commented.
If you want to ask a question, post it on the PNGwriter Issue Tracker on GitHub.


Can PNGwriter draw text and graph axes?

Yes, PNGwriter now has full text support capabilities (including UTF-8 support), but it does not do axes. Here is the official reason: PNGwriter is aimed at the fast and intuitive creation of high quality images in scientific and image processing contexts. Any bitmap image requiring axes and that must be published at publication-quality should be using vector graphics for the axes (and maybe the text), not bitmap, and combine both in an SVG or EPS.

So, is all lost? Is there nothing that can be done? Of course not! Here's a solution: Create PNG images of the graph axes you want to add using your method of choice (The Gimp, Photoshop, etc.). Make it black on white, for example. From your program, open this file with PNGwriter. Write a simple routine that takes all black pixels, and plots them onto your image, at the position you specify, and in whatever colour you want. This can be automated so that it is done after every image has been completed.


How do I use PNGwriter under Windows?

Please note: Though there are guides on this site for compiling PNGwriter under Windows using some popular compilers, I cannot offer support for this task.

You should get hold of a Windows implementation of GCC, the free GNU C/C++ compiler (two possible ways to do this are www.mingw.org and www.cygwin.com). You can also use the Borland C++ Builder or Microsoft Visual C++ .NET on Windows XP. Here are two clear, step-by-step HowTos: " Setting Up PNGWriter for Borland C++ Builder Version 6 on Windows XP" and "Setting Up PNGWriter for Microsoft Visual C++ .NET on Windows XP".
Also, using PNGwriter with Bloodshed Dev C++ is quite easy, as pointed out by Siva Chandra: "You can download the pre-compiled libraries for freetype from the GnuWin32 web-site: gnuwin32.sf.net. To build PNGwriter itself, create a new C++ library project called libpngwriter. Include the PNGwriter header file and the implementation file into this new project. Then compile. And thats it. You will have a libpngwriter.a file ready for use. Note that this will by default assume availability of freetype. To remove such assumption, you will have to compile with this option: -DNO_FREETYPE".
Please note: pngwriter.cc has to be renamed to pngwiter.cpp for MSVC7. If the extension is not changed then the C/C++ folder for the project property does not become visible and hence the MSVC7's default of using compiled headers in its project build will always return an error about being unable to find some precompiled header. It is necessary to change that feature in the project property in order to successfully build the PNGwriter library using this compiler.



What's in the PNGwriter package?

The source tarball/zip file contains the following items:


pngwriter-release-x.y.z
 |-- CHANGELOG.md
 |-- CMakeLists.txt
 |-- Makefile
 |-- README.md
 |-- doc
 |   |-- CHANGES
 |   |-- EXAMPLES
 |   |-- LICENSE
 |   |-- PNGwriterQuickReference.pdf
 |   |-- PNGwriterQuickReference.rtf
 |   `-- README
 |-- examples
 |   |-- Makefile
 |   |-- burro.png
 |   |-- lyapunov.cc
 |   `-- pngtest.cc
 |-- fonts
 |   |-- FreeMonoBold.ttf
 |   `-- FreeSansBold.ttf
 |-- make.include -> make.include.linux
 |-- make.include.linux
 |-- make.include.osx
 |-- src
 |   |-- Makefile
 |   |-- pngwriter.cc
 |   `-- pngwriter.h
 `-- tests
     |-- blackwhite.cc
     |-- diamond.cc
     `-- performance.cc




How can I link to the PNGwriter project from my page?

Did you find PNGwriter useful? If so, spread the word, and tell others about it, by placing the following button on you project page. You never know, it might be just what someone was looking for!


Made With PNGwriter


If you want, you can link directly to the image on the PNGwriter site. In that case, the code to add to your page would be:

<a href="http://pngwriter.sourceforge.net/"><img src="http://pngwriter.sourceforge.net/site_images/madewith.png" width="88" height="31" alt="Made With PNGwriter" BORDER="0" target="_blank"></a>




What is PNGwriter's current development status?

As of release 0.5.5 (August 2015), PNGwriter is back in active maintenance and development status. Check the PNGwriter GitHub page for updates.




SourceForge.net Logo Valid HTML 4.01! Valid CSS!


© 2002-2015 Paul Blackburn

eXTReMe Tracker