Page 1 of 1

turn image sepia?

Posted: Mon Mar 10, 2008 10:51 am
by wmguk
hey guys,

I currently have a script for making an image B&W, but would like to make it sepia...

any thoughts on how to do it?

Code: Select all

<?PHP
//Get the image
$file = $_GET['image'];
    
// This sets it to a .jpg, but you can change this to png or gif if that is what you are working with
header('Content-type: image/jpeg'); 
 
// Get the dimensions
list($width, $height) = getimagesize($file); 
 
// Define our source image 
$source = imagecreatefromjpeg($file); 
 
// Creating the Canvas 
$bwimage= imagecreate($width, $height); 
 
//Creates the 256 color palette
for ($c=0;$c<256;$c++) 
{
$palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);
}
 
//Creates yiq function
function yiq($r,$g,$b) 
{
return (($r*0.299)+($g*0.587)+($b*0.114));
} 
 
//Reads the origonal colors pixel by pixel 
for ($y=0;$y<$height;$y++) 
{
for ($x=0;$x<$width;$x++) 
{
$rgb = imagecolorat($source,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> <!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) --> & 0xFF;
$b = $rgb & 0xFF;
 
//This is where we actually use yiq to modify our rbg values, and then convert them to our grayscale palette
$gs = yiq($r,$g,$b);
imagesetpixel($bwimage,$x,$y,$palette[$gs]);
}
} 
 
// Outputs a jpg image, but you can change this to png or gif if that is what you are working with
imagejpeg($bwimage); 
?>
 

Re: turn image sepia?

Posted: Mon Mar 10, 2008 5:56 pm
by wmguk
any ideas?