18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Working with Files and Images<br />

Once we have the color values, we use imagecolorallocate() to create a color<br />

identifier representing this color. Finally we can call imagestring(), a GD function<br />

that plots text on a string. Without going into too much detail, the following are the<br />

arguments this function takes:<br />

• A handle to the image (in this example the resource property of the<br />

image object)<br />

• A font size from 1-5 (5 being the largest)<br />

• The x and y coordinates of where the text should be plotted with (0, 0) being<br />

the top left corner of the image<br />

• The text to be plotted, in this example, the $data['text'] as submitted by<br />

the user through our configuration form<br />

• The color identifier we created with the user-submitted color choice<br />

You should now be able to install this module and have the option to watermark an<br />

image on the Image Styles admin screen, as shown in the following screenshot:<br />

You can now add this effect, alone or in combination with other effects to a new<br />

image style. This image style can then be applied to images in nodes by adjusting<br />

the display settings in the administration screens for the node's content type.<br />

The following image shows our previous example node with a user-configured<br />

watermark applied to the image:<br />

[ 338 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!