note 77678 added to function.imagecopymergegray
| From: | timatleethostdotcom at osu1 dot php dot net | Date: | Fri, 07 Sep 2007 23:28:49 +0000 |
| Subject: | note 77678 added to function.imagecopymergegray | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130308@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 209.41.74.194
Probable Submitter: 72.240.221.30
----
Manual Page -- http://www.php.net/manual/en/function.imagecopymergegray.php
Edit -- https://master.php.net/note/edit/77678
Del: integrated -- https://master.php.net/note/delete/77678/integrated
Del: useless -- https://master.php.net/note/delete/77678/useless
Del: bad code -- https://master.php.net/note/delete/77678/bad+code
Del: spam -- https://master.php.net/note/delete/77678/spam
Del: non-english -- https://master.php.net/note/delete/77678/non-english
Del: in docs -- https://master.php.net/note/delete/77678/in+docs
Del: other reasons-- https://master.php.net/note/delete/77678
Reject -- https://master.php.net/note/reject/77678
Search -- https://master.php.net/manage/user-notes.php