i implemented this in GD, however it takes about 4seconds to calculate on 1024x768. and i found that COMPOSITE_THRESHOLD provides exactly this functionality.
does anyone know how i can vary the factor for compositeImage()?
i tried setImageCompose() and setOption(), with every permutation of 'option:', 'compose', 'composite', 'compose:args', 'composite:args' and factors of 0.1, 0.5, 1, 50, 255, 500 but the factor is always 50%.
Code: Select all
$f = 0.3;
$srcImg = imagecreatefromjpeg( 'src.jpg' );
$destImg = imagecreatefromjpeg( 'dest.jpg' );
$width = imagesx( $srcImg );
$height = imagesy( $srcImg );
$outImg = imagecreatetruecolor( $width, $height );
for( $y = 0; $y < $height; $y++ )
{
for( $x = 0; $x < $width; $x++ )
{
$srcRGB = imagecolorat( $srcImg, $x, $y );
$srcR = ($srcRGB >> 16) & 0xFF;
$srcG = ($srcRGB >> 8) & 0xFF;
$srcB = ($srcRGB >> 0) & 0xFF;
$destRGB = imagecolorat( $destImg, $x, $y );
$destR = ($destRGB >> 16) & 0xFF;
$destG = ($destRGB >> 8) & 0xFF;
$destB = ($destRGB >> 0) & 0xFF;
$r = (int)($srcR + $f * ($destR - $srcR));
$g = (int)($srcG + $f * ($destG - $srcG));
$b = (int)($srcB + $f * ($destB - $srcB));
$rgb = (int)(($r << 16) | ($g << 8) | $b);
imagesetpixel( $outImg, $x, $y, $rgb);
}
}
imagejpeg( $outImg, 'corrected.jpg' );
[/size]