[PHP] Image manipulation on the fly

2007-11-08 Thread Merlin

Hi there,

I need to manipulate images on the fly. My goal is to make the image
very bright, or to add a sepia effect. The problem is, that this takes a 
lot of computing power on 1024 pictures. About 2s on my server until the 
image is delivered.


Does anybody know a high performing image funtion that would allow me to 
brighten up the picture on the fly, or any other effect similar to it?


I am attaching the sepia function I am using.
Thank you for any help or suggestion on how to solve that.

Best regards,

Merlin


function image_effect_sepia($im){
$start_red = 2; //red scale at black
$start_blue = 2.3;  //blue scale at black
$red_scale = ($start_red-1)/256;//red modifier as 
greyscale goes to white

$blue_scale = ($start_blue - 1)/256;//ditto for blue

//build a sepia lookup table
$sepia = array();
for($x = 0;$x  256;$x++){
$red = intval($x * ($start_red - ($x * $red_scale)));
if($red  255) $red = 255;
$blue = intval($x / ($start_blue - ($x * $blue_scale)));
$sepia[$x][0] = $red;
$sepia[$x][1] = $blue;
}

# modify the image
for($y = 0;$y  imagesy($im);$y++){
for($x = 0;$x  imagesx($im);$x++){
$pixel = imagecolorat($im, $x, $y);
$red = ($pixel  0xFF)  16;
$green = ($pixel  0x00FF00)  8;
$blue = $pixel  0xFF;
$alpha = $pixel  0x7F00;
//get a greyscale value
$gs = intval(($red * 0.3) + ($green * 0.59) + ($blue * 0.11));
$p = $alpha | $sepia[$gs][1] | ($gs  8) | ($sepia[$gs][0] 
 16);

imagesetpixel ($im, $x, $y, $p);
}
}
# return the moddifyed image
return $im;
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Image manipulation on the fly

2007-11-08 Thread Bojan Tesanovic
Hi Merlin, that is very fast for 1024 images, you will not get much  
more speed if you try doing anything smarter ,
though there are some image libraries that are faster than GD libs eg  
www.imagemagick.org


On Nov 8, 2007, at 5:13 PM, Merlin wrote:


Hi there,

I need to manipulate images on the fly. My goal is to make the image
very bright, or to add a sepia effect. The problem is, that this  
takes a lot of computing power on 1024 pictures. About 2s on my  
server until the image is delivered.


Does anybody know a high performing image funtion that would allow  
me to brighten up the picture on the fly, or any other effect  
similar to it?


I am attaching the sepia function I am using.
Thank you for any help or suggestion on how to solve that.

Best regards,

Merlin


function image_effect_sepia($im){
$start_red = 2; //red scale at black
$start_blue = 2.3;  //blue scale at black
$red_scale = ($start_red-1)/256;//red modifier  
as greyscale goes to white

$blue_scale = ($start_blue - 1)/256;//ditto for blue

//build a sepia lookup table
$sepia = array();
for($x = 0;$x  256;$x++){
$red = intval($x * ($start_red - ($x * $red_scale)));
if($red  255) $red = 255;
$blue = intval($x / ($start_blue - ($x * $blue_scale)));
$sepia[$x][0] = $red;
$sepia[$x][1] = $blue;
}

# modify the image
for($y = 0;$y  imagesy($im);$y++){
for($x = 0;$x  imagesx($im);$x++){
$pixel = imagecolorat($im, $x, $y);
$red = ($pixel  0xFF)  16;
$green = ($pixel  0x00FF00)  8;
$blue = $pixel  0xFF;
$alpha = $pixel  0x7F00;
//get a greyscale value
$gs = intval(($red * 0.3) + ($green * 0.59) + ($blue *  
0.11));
$p = $alpha | $sepia[$gs][1] | ($gs  8) | ($sepia[$gs] 
[0]  16);

imagesetpixel ($im, $x, $y, $p);
}
}
# return the moddifyed image
return $im;
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Bojan Tesanovic
http://www.classicio.com/






Re: [PHP] Image manipulation on the fly

2007-11-08 Thread Per Jessen
Merlin wrote:

 Hi there,
 
 I need to manipulate images on the fly. My goal is to make the image
 very bright, or to add a sepia effect. The problem is, that this takes
 a lot of computing power on 1024 pictures. About 2s on my server until
 the image is delivered.

Yeah, you're doing CPU-intensive stuff in an interpreted language -
it'll never be efficient unless you write it in C or similar. 



/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php