markiemrboo Posted July 26, 2005 Posted July 26, 2005 <?php $im = imagecreatefromjpeg($_GET['image']); if ($_GET['invert'] == 1 || $_GET['bw'] == 1) { imagetruecolortopalette($im, true, 256); $tc = imagecolorstotal($im); $maxcol = 255; for ($i = 0; $i < $tc; $i++) { $col = imagecolorsforindex($im, $i); if ($_GET['bw'] == 1) { $min = min($col['red'],$col['green'],$col['blue']); $max = max($col['red'],$col['green'],$col['blue']); $bw = ($max + $min) / 2; imagecolorset($im, $i, $bw, $bw, $bw); $col['red'] = $col['green'] = $col['blue'] = $bw; } if ($_GET['invert'] == 1) { // make jpeg compressed black proper black so inverting will make white proper white if ($col['red'] <= 10 && $col['green'] <= 10 && $col['blue'] <= 10) { $col['red'] = 0; $col['green'] = 0; $col['blue'] = 0; } imagecolorset($im, $i, $maxcol - $col['red'], $maxcol - $col['green'], $maxcol - $col['blue']); } } } header("Content-type: image/jpeg"); imagejpeg($im); imagedestroy($im); ?> Just a little something I hacked up that I thought I might share. It'll open a jpeg image and invert the colours or make it greyscale (or both). If you've using PHP 5 you can use imagefilter() but, well, I am still using 4.x. Might be useful to someone out there I suppose.... Quote Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.