- 2.0.0
- 1.3.3
Installation
The class is designed for PHP version 5.3+, it includes new specifications like namespaces. If you use an older version, like PHP 5.2, it can work until you remove these specifications. See how to install and use the class depending of your PHP version:
The PHPImageWorkshop folder added in your lib directory, just use the class namespace in your main script and that's it:
// myscript.php: use PHPImageWorkshop\ImageWorkshop; $layer = new ImageWorkshop(array(...));
If you don't use an autoloader, this is a little more tricky but still easy to install: you just need to include files manually.
You have to load ImageWorkshopException class at the beginning of ImageWorkshop file with include() or require_once() functions:
// ImageWorkshop.php: require_once('ImageWorkshopException.php'); // Adapt the correct path, here ImageWorkshopException.php and ImageWorkshop.php are in the same folder
If you don't do that, when using ImageWorkshop not correctly, an error like that will be displayed instead of an exception:
Fatal error: Class 'PHPImageWorkshop\ImageWorkshopException' not found in /home/.../ImageWorkshop.php on line 1731
Where you need to use the class don't forget to include it !
// myscript.php: require_once('path/to/lib/PHPImageWorkshop/ImageWorkshop.php'); // Be sure of the path to the class
You can now initialize an object like this:
// myscript.php: $layer = new PHPImageWorkshop\ImageWorkshop(array(...));
Alternatively, a better thing is to use the namespace:
// myscript.php: use PHPImageWorkshop\ImageWorkshop; // Use the namespace of ImageWorkshop require_once('path/to/lib/PHPImageWorkshop/ImageWorkshop.php'); // Be sure of the path to the class
By this way, you can initialize an object simplier:
// myscript.php: // previous code ... $layer = new ImageWorkshop(array(...));
Even its not advisable to use ImageWorkshop on an old PHP version, the class can work if you remove all the specifications of 5.3, especially namespaces.
Without clearing files, you will have some parse errors like that:
Parse error: syntax error, unexpected T_STRING in /home/.../ImageWorkshop.php on line 3 // Or also: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/.../index.php on line 5
This is normal: old PHP versions don't recognized namespaces so they consider them as parse errors or illegal characters !
Add PHPImageWorkshop folder in your project and lets do this !
Remove the namespace declaration line 3:
namespace PHPImageWorkshop;
Remove also the backslash ("\") before Exception line 10:
class ImageWorkshopException extends \Exception
Open ImageWorkshop.php file, and then remove the namespace declaration line 3:
namespace PHPImageWorkshop;
And the namespace inclusion line 5:
use PHPImageWorkshop\ImageWorkshopException;
Then, with your text editor, replace all the founded occurences "static::" by "self::".
And also "new static" by "new self".
This is because late static binding only exists since 5.3 !
You have to load ImageWorkshopException class at the beginning of ImageWorkshop file with include() or require_once() functions:
// ImageWorkshop.php: require_once('ImageWorkshopException.php'); // Adapt the correct path, here ImageWorkshopException.php and ImageWorkshop.php are in the same folder
If you don't do that, when using ImageWorkshop not correctly, an error like that will be displayed instead of an exception:
Fatal error: Class 'PHPImageWorkshop\ImageWorkshopException' not found in /home/.../ImageWorkshop.php on line 1731
The last thing, where you need to use the class don't forget to include it !
// myscript.php: require_once('path/to/lib/PHPImageWorkshop/ImageWorkshop.php'); // Be sure of the path to the class
You can now use the class classically:
// myscript.php: $layer = new ImageWorkshop(array(...));