Contents Previous Next

## 7.15 Using background images

Instead of having a single color background you can easily have an arbitrary image as the background. The image may be in either PNG, JPG or GIF format depending on what your installation supports.

A note on GD: If you are using GD 2.xx you must make sure that the define USE_TRUECOLOR is set to true. This is also the default. Failure to do so in combination with GD 2.xx will make the background image just look like a solid black square.

To use a specific image as the background you just have to use the method Graph::SetBackgroundImage() The arguments specify file-name, how the image should be positioned in the graph and finally the format of the image (if it is in JPG, PNG or GIF) format. If the format is specified as "auto" (the default) then the appropriate image format will be determined from the extension of the image file.

The file name is of course obvious but the second argument might not be. This arguments determine how the image should be copied onto the graph image. You can specify three different variants here

1. BGIMG_ COPY This will just copy the image unchanged onto the graph from the top left corner.
2. BGIMG_CENTER This will just copy the image unchanged onto the graph but it will center the image in the graph.
3. BGIMG_FILLFRAME This will scale the image to exactly fit the whole graph image.
4. BGIMG_FILLPLOT This will scale the image to exactly fit just the plot area of the graph.

The following section only applies to palette based images. True color images can NOT be manipulated this way. Applying the following sections to true-color images will have no affect.

You might often find yourself wanting to use a background image as a "waterstamp". This usually means taking the original image, import it to some image editing program and then "bleaching" the color saturation, reducing the contrast and so on. Finally you save the modified image which you then use as a background image.

This whole process can be automatically accomplished in JpGraph by using the method Graph::AdjBackgroundImage() which allow you to adjust color saturation, brightness and contrast of the background image.

`$graph-> AdjBackgroundImage(...)`

to achieve the "watercolor" effect to avoid the image being too intrusive in the graph.

Figure 93: Example on using a watermark type background image [src]

Note: The background image depicts a 1998 Triumph Tiger. This bike is a 900cc off-road bike.

Contents Previous Next