The Image class
The Image class is simply put a class with methods to make it easier to mainpulate images: Creating thumbnails, scaling, cropping and so on. To have any kind of use of this module the PHP Image extension needs to be installed. In most cases I believe it is by default.
Let's get on it!
Using the Image module
The first thing you need to is importing the Image module. This is done like this (in all examples I presume PLib.php is included):
- PLib::Import('Graphics.Image');
In the Graphics namespace there is two static members that you can set that
will affect the quality/compression of PNG and JPEG images. By default the JPEG
quality is set to 80 and the PNG compression is set to level 9. If you
want other settings you can set these members before you manipulate your images:
- PLib::Import('Graphics.Image');
- Graphics::$JPEG_QUALITY = 90;
- Graphics::$PNG_QUALITY = 1;
The Graphics namespace also has one static helper methods that can be useful
to know about - Hex2RGB - which simply convert a
hexadecimal color to RGB values and returns an associative array with three
keys: r, g, b:
- PLib::Import('Graphics.Image');
- $hex1 = "0x445566";
- $hex2 = "#445566";
- $hex3 = "456";
- print_r(Graphics::Hex2RGB($hex1));
- print_r(Graphics::Hex2RGB($hex2));
- print_r(Graphics::Hex2RGB($hex3));
- //! The result for all three variants will be
- Array
- (
- [r] => 68
- [g] => 85
- [b] => 102
- )