Image manipulation on the fly

From: Date: Thu, 08 Nov 2007 16:13:28 +0000
Subject: Image manipulation on the fly
Groups: php.general 
Request: Send a blank email to php-general+get-264233@lists.php.net to get a copy of this message
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 & 0xFF0000) >> 16;
            $green = ($pixel & 0x00FF00) >> 8;
            $blue = $pixel & 0x0000FF;
            $alpha = $pixel & 0x7F000000;
            //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; }

« previous php.general (#264233) next »