note 74523 added to function.imagecopymergegray

From: Date: Sun, 15 Apr 2007 21:17:59 +0000
Subject: note 74523 added to function.imagecopymergegray
Groups: php.notes 
Request: Send a blank email to php-notes+get-125427@lists.php.net to get a copy of this message
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); ?> ---- Server IP: 84.47.204.3 Probable Submitter: 83.29.196.227 ---- Manual Page -- http://www.php.net/manual/en/function.imagecopymergegray.php Edit -- https://master.php.net/note/edit/74523 Del: integrated -- https://master.php.net/note/delete/74523/integrated Del: useless -- https://master.php.net/note/delete/74523/useless Del: bad code -- https://master.php.net/note/delete/74523/bad+code Del: spam -- https://master.php.net/note/delete/74523/spam Del: non-english -- https://master.php.net/note/delete/74523/non-english Del: in docs -- https://master.php.net/note/delete/74523/in+docs Del: other reasons-- https://master.php.net/note/delete/74523 Reject -- https://master.php.net/note/reject/74523 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125427) next »