note 77678 deleted from function.imagecopymergegray by nlopess

From: Date: Sat, 08 Sep 2007 11:13:25 +0000
Subject: note 77678 deleted from function.imagecopymergegray by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130312@lists.php.net to get a copy of this message
Note Submitter: tim at leethost dot com Reason: spam ---- Here's a much better grayscale, sepia, and general tinting function. The other methods listed here use "brute force" to change every pixel. With a small thumbnail image, brute force is probably fine. But, when doing a larger image, even average sized, brute force will take *forever*. This function creates high quality results, works with true color images, allows you to customize the sepia and tinting to your preference, and is *much* faster than the brute force methods. Here's some examples: imagegrayscaletint ($img); // Grayscale, no tinting imagegrayscaletint ($img,304,242,209); // What I use for sepia imagegrayscaletint ($img,0,0,255); // A berry blue image The RGB values for tinting are normally from 0 to 255. But, you can use values larger than 255 to lighten and "burn" the image. The sepia example above does this a little, the below example provides a better example of lightening the image and burning the light areas out a little: imagegrayscaletint ($img,400,400,400); // Lighten image imagegrayscaletint ($img,127,127,127); // Darken image <? function imagegrayscaletint (&$img, $tint_r = 255, $tint_g = 255, $tint_b = 255) { $width = imagesx($img); $height = imagesy($img); $dest = imagecreate ($width, $height); for ($i = 0; $i < 256; $i++) imagecolorallocate ($dest, $i, $i, $i); imagecopyresized ($dest, $img, 0, 0, 0, 0, $width, $height, $width, $height); for ($i = 0; $i < 256; $i++) imagecolorset ($dest, $i, min($i * abs($tint_r) / 255, 255), min($i * abs($tint_g) / 255, 255), min($i * abs($tint_b) / 255, 255)); $img = imagecreate ($width, $height); imagecopy ($img, $dest, 0, 0, 0, 0, $width, $height); imagedestroy ($dest); } ?> This function is used on http://www.freeringers.net/ to create an online image editing, cropping and processing tool.

« previous php.notes (#130312) next »