Voting

: six plus three?
(Example: nine)

The Note You're Voting On

szamil at ginf dot pl
18 years ago
I've changed a little switch251's code and here we have sephia effect
<?php
// replace with your files
$originalFileName = $filename;
$destinationFileName = "2".$filename;

// create a copy of the original image
// works with jpg images
// fell free to adapt to other formats ;)
$fullPath = explode(".",$originalFileName);
$lastIndex = sizeof($fullPath) - 1;
$extension = $fullPath[$lastIndex];
if (
preg_match("/jpg|jpeg|JPG|JPEG/", $extension))
{
$sourceImage = imagecreatefromjpeg($originalFileName);
}

// get image dimensions
$img_width = imageSX($sourceImage);
$img_height = imageSY($sourceImage);

// convert to grayscale
// note: this will NOT affect your original image, unless
// originalFileName and destinationFileName are the same
for ($y = 0; $y <$img_height; $y++)
{
for (
$x = 0; $x <$img_width; $x++)
{
$rgb = imagecolorat($sourceImage, $x, $y);
$red = ($rgb >> 16) & 0xFF;
$green = ($rgb >> 8) & 0xFF;
$blue = $rgb & 0xFF;

//sephia
$red2 = min($red*.393 + $green*.769 + $blue*.189,255);
$green2 = min($red*.349 + $green*.686 + $blue*.168,255);
$blue2 = min($red*.272 + $green*.534 + $blue*.131,255);
// shift gray level to the left

$grayR = $red2 << 16; // R: red
$grayG = $green2 << 8 ; // G: green
$grayB = $blue2; // B: blue

// OR operation to compute gray value
$grayColor = $grayR | $grayG | $grayB;


// set the pixel color
imagesetpixel ($sourceImage, $x, $y, $grayColor);
imagecolorallocate ($sourceImage, $gray, $gray, $gray);
}
}

// copy pixel values to new file buffer
$destinationImage = ImageCreateTrueColor($img_width, $img_height);
imagecopy($destinationImage, $sourceImage, 0, 0, 0, 0, $img_width, $img_height);

// create file on disk
imagejpeg($destinationImage, $destinationFileName);

// destroy temp image buffers
imagedestroy($destinationImage);
imagedestroy($sourceImage);
?>

<< Back to user notes page

To Top