Re: Image_Transform - new effects

From: Date: Wed, 14 Sep 2005 07:24:53 +0000
Subject: Re: Image_Transform - new effects
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39811@lists.php.net to get a copy of this message
Hi, Very nice, but since I'm not involved in Image_Transform I have no saying there :) Have two points, but the solution to both is the same: There must be a _huge_ overhead on these scrips since you create not 1 (which is already alot - for a small image 100 x 50 you create 5.000 objects!!!) but 2 objects for every pixel, just to hold the RGB values. (Solution later) You could of course just send them along as an array and return an array to the callback function - which leads me to point 2. Why not create the operations by subclassing instead of having the user function? This is more in line with OO. What I mean is having: /** * ... * * @abstract */ class Image_PixelOperations { /** * Performs the operations of the pixel * * @param array $color Color representing the pixel * @param array $params Parameters for the operation, fx. 'factor' => 0.5 * @abstract function performOperation(&$color, $params = false) { // .. doing the magic either by modifying $color or perhaps // returning the modified color - (not important) } function pixelOperation($input_image, $output_image, $factor = false) { // do the same but instead of using the callback function use // $this->performOperation($color, $params); // where $params is an array like array('factor' => $factor, ...); } } Then adding a new operation simply implies: class PixelOperation_Noise extends PixelOperation { /** * Adds noise to a pixel * * @param array $color Color representing the pixel * @abstract function performOperation(&$color, $params = false) { $random = mt_rand(-$factor, $params['factor']); return new array( 'r' => $color['r'] + $random, 'g' => $color['g'] + $random, 'b' => $color['b'] + $random ); } } Best regards Jesper > Hi guys, > > I was playing with GD and came up with a few effects. I've posted them > here: > http://www.phpied.com/image-fun/ > > Some of them may be added as enhancements to the Image_Transform package. > > Let me know what you think. I can cooperate in cleaning up, > documenting and adding them to Image_Transform or to another class > that extends Image_Transform, for example > Image_Transform_PixelOperations. Because these are in essence pixel > operations, performed on a single pixel. Image_Transform_Filters might > be another extension that can have effects such as blur, edge detect, > sharpen, etc. > > My current code is concentrates on the operations themselves, not so > much on reading, validating and writing images, something that > Image_Transform already does pretty well. Also my implementation is > designed to be extensible, one can easily add a new effect by > providing a callback function that does something and returns a Pixel > object. > > Regards, > Stoyan > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.pear.dev (#39811) next »