Important notice: the development of WideImage 1.0 branch is discontinued.
Please visit
http://wideimage.sourceforge.net for the new version of library and documentation.
This web site will remain accessible to serve as documentation for the old versions of the library.
For help on migration, please refer
to the
migration
guide.
Most recent edit on 2007-07-01 15:47:36 by GasperKozak
No differences.
Edited on 2007-07-01 15:47:11 by GasperKozak
Additions:
Note: The operation isn't supposed to modify the source image, it's supposed to return a newly created and modified image. This is not necessary, but it's a good and expected practice.
Deletions:
Note: The operation isn't supposed to modify the source image, it's supposed to return a newly created and modified image. This is not necessary, but it's a good practice.
Edited on 2007-06-05 16:48:11 by GasperKozak
Additions:
of course, the custom operation can be chained as well
$modified = $img->resize(200, 200)->drawWhiteDots(70)->rotate(45);
Edited on 2007-06-05 16:43:54 by GasperKozak
Additions:
~- Signature: execute($image[, custom parameters])
Deletions:
~- Signature: load($image[, custom parameters])
Edited on 2007-03-04 15:43:30 by GasperKozak
Additions:
$img = wiImage::load('/path/to/image.png');
Deletions:
$img = wiImage::load('/path/to/image.pcx');
Edited on 2007-03-03 16:07:46 by GasperKozak
Additions:
If you want to use a custom image operation, you only have to declare an operation class somewhere in your code or autoloader. The class has to conform to a few simple rules.
Deletions:
In order to support a custom image operation, you have to declare an operation class.
Edited on 2007-03-03 16:05:35 by GasperKozak
Additions:
class wioDrawWhiteDots
$modified = $img->drawWhiteDots();
$modified = $img->drawWhiteDots(100);
Deletions:
class wioMyOperation
$modified = $img->myOperation();
$modified = $img->myOperation(100);
Edited on 2007-03-03 16:04:58 by GasperKozak
Additions:
~- Return value must be a valid wiImage object (this means wiTrueColorImage or wiPaletteImage).
Note: The operation isn't supposed to modify the source image, it's supposed to return a newly created and modified image. This is not necessary, but it's a good practice.
Deletions:
~- Return value must be a valid wiImage object (this means wiTrueColorImage or wiPaletteImage).
Oldest known version of this page was edited on 2007-03-03 16:02:35 by GasperKozak []
Page view:
Custom Image Operations
In order to support a custom image operation, you have to declare an operation class.
Naming the class
You have to name the class properly:
wioOPERATION_NAME, for example wioMyOperation.
WideImage will automatically create and use the operation.
Methods
In order for the operation to work, two methods must be defined properly; a parameterless constructor and the execute method.
execute()
- Signature: load($image[, custom parameters])
- Parameters:
- $image wiImage - The object to perform the operation on.
- custom parameters can be defined. They are passed from the user call.
- Return value must be a valid wiImage object (this means wiTrueColorImage or wiPaletteImage).
Example of an operation
Let's define a simple operation that draws a number of white points at random location on the image.
class wioMyOperation
{
function execute
($image,
$n =
5)
{
// make a copy
$new =
$image->
copy();
// allocate a white color
$white =
$new->
allocateColor(255,
255,
255);
// draw a point $n times
for ($i =
0;
$i <
$n;
$i++
)
{
// random position
$x =
rand(0,
$image->
getWidth() -
1);
$y =
rand(0,
$image->
getHeight() -
1);
// draw the point
$new->
setRGBAt($x,
$y,
$white);
}
return $new;
}
}
And now let's use it:
$img = wiImage::load('/path/to/image.pcx');
// let's do it
$modified = $img->myOperation();
// let's draw 100 white points instead of 5
$modified = $img->myOperation(100);