LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Creating static images through programming (https://www.linuxquestions.org/questions/programming-9/creating-static-images-through-programming-918786/)

hydraMax 12-14-2011 08:56 PM

Creating static images through programming
 
Hi. I wanted to try the pngwriter library (http://pngwriter.sourceforge.net/) so I could play around with creating art through programming functions, but I couldn't get it to compile. (Lots of errors and warnings.) I was wondering if there was some other library or tool out there with similar functionality that would work on 64-bit Linux. I am fairly open-minded about the programming language involved, as long as it isn't tied to anything proprietary (like Java).

Nominal Animal 12-14-2011 09:56 PM

Why don't you create the images in PPM format and use the netpbm package to convert to other formats (PNG, GIF, JPEG)? Specifically, write your programs to output images in the PPM format, then use the netpbm package to convert the PPM files to JPEG, GIF, and/or PNG formats.

The PPM format is very simple. The file has an ASCII header, followed by uncompressed/raw binary data describing each pixel in the image. See man ppm for details.

For most PPM images, you'll want to use a header similar to what is produced using command
Code:

printf 'P6\n%d %d\n255\n' width height
This is followed by height rows of width pixels each. Each pixel is three bytes long, and uses the RGB color model: first byte is for red, second is for green, and third for blue. The interpretation is the same as HTML/CSS colors, i.e. #FFFFFF (255,255,255) for white, #FF0000 (255,0,0) for red, #00FF00 (0,255,0) for green, #0000FF (0,0,255) for blue, and #000000 (0,0,0) for black. You have 16777216 colors/shades to play with, although many LCD displays will only really display 262144 of them.

In general, PPM format allows either one or two bytes per component, depending on whether the maximum (specified in the header, 255 in my example) is less than 256, or between 256 and 65535 (inclusive). For this kind of use, where the result is soon converted to PNG or GIF or JPEG format anyway, I recommend just sticking with the example above.

If you wish to experiment with High Dynamic Range images, then using two bytes per component (0 to 65535) is useful; but not really otherwise.

I'm doing some research on how to generate better visualizations for atomic simulations (molecular dynamics simulations), and I've used PPM format extensively: it allows you to concentrate on just generating the pixel images, and let specialized tools worry about compression and conversion to other formats.

timetraveler 12-14-2011 10:10 PM

Gnuplot can do amazing things, especially have a look at splot.
Also have a look at Graphviz.
Both have programatic interfaces.
If you're looking for something low-level check out OpenGL

firstfire 12-14-2011 11:40 PM

Hi.

You may take a look at OpenCV (Open Computer Vision), especially the python bindings for it. It should be not too hard to create and apply filters to achieve effects available in most graphics editors (gimp etc.).

By the way, you can write your own extensions to GIMP in python, see here and here.

theNbomr 12-15-2011 02:30 AM

The GD library is intended specifically for creating bitmap images using code. It has bindings for several common programming languages. It is best for 'presentation graphics', such as plots and graphs.

--- rod.

hydraMax 12-15-2011 02:47 AM

As a point of curiosity, is there a format like ppm that also supports a byte for an alpha value?

hydraMax 12-15-2011 04:53 AM

libgd is exactly what I was looking for.


All times are GMT -5. The time now is 07:11 AM.