note 77677 added to function.imagecolorsforindex
| From: | timatleethostdotcom at osu1 dot php dot net | Date: | Fri, 07 Sep 2007 23:03:40 +0000 |
| Subject: | note 77677 added to function.imagecolorsforindex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130306@lists.php.net to get a copy of this message | ||
Here's a better grayscale, sepia, and general tinting function. This function is better
because:
1) Works with true color images (the other sepia code didn't).
2) Provides a more gooder grayscale conversion (yes, I said "more gooder"). The other
grayscale code used imagetruecolortopalette, which just doesn't work well for grayscale
conversion.
3) The other sepia code was really colorful, a little too much for my taste. This function allows
you to optionally set the tinting of the grayscale to anything you wish.
4) Single function for grayscale, sepia, and any other tinting you can dream up.
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.imagecolorsforindex.php
Edit -- https://master.php.net/note/edit/77677
Del: integrated -- https://master.php.net/note/delete/77677/integrated
Del: useless -- https://master.php.net/note/delete/77677/useless
Del: bad code -- https://master.php.net/note/delete/77677/bad+code
Del: spam -- https://master.php.net/note/delete/77677/spam
Del: non-english -- https://master.php.net/note/delete/77677/non-english
Del: in docs -- https://master.php.net/note/delete/77677/in+docs
Del: other reasons-- https://master.php.net/note/delete/77677
Reject -- https://master.php.net/note/reject/77677
Search -- https://master.php.net/manage/user-notes.php