imagethumbnail_blackandwhite

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

imagethumbnail_blackandwhite

Post by onion2k »

Another extension to my imagethumbnail class .. this time it makes black and white thumbnails..

Usage:

Code: Select all

$i = new imagethumbnail_blackandwhite();

    $i->open("xxx.jpg");
    $i->setX(100);
    $i->blackandwhite();
    
    header("Content-type: image/jpeg;");
    $i->imagejpeg();
Same as before .. just remember to call blackandwhite()..

Code: Select all

class imagethumbnail_blackandwhite extends imagethumbnail {

		function imagethumbnail_blackandwhite() {

		}
		
		function blackandwhite() {

			if (!isset($this->thumbnail)) { $this->generate(); }
			for ($x=0;$x<256;$x++) {
				$palette[$x] = imagecolorallocate($this->thumbnail,$x,$x,$x);
			}
			for ($x=0;$x<imagesx($this->thumbnail);$x++) {
				for ($y=0;$y<imagesy($this->thumbnail);$y++) {
					$rgb = imagecolorat($this->thumbnail,$x,$y);
					$r   = ($rgb >> 16) & 0xFF;
					$g   = ($rgb >>  & 0xFF;
					$b   = $rgb & 0xFF;
					$val = (($r*0.299)+($g*0.587)+($b*0.114));
					imagesetpixel($this->thumbnail,$x,$y,$palette[$val]);
				}
			}
		}

	}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Code Snipplets.... aargg Onion.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Jcart wrote:Moved to Code Snipplets.... aargg Onion.
Well.. to be fair (to myself).. I've posted a number of image functions in the graphics folder and they've not been moved before. But in future I'll put them in here. ;)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

So John, move onion2k completely to Code Snippets :lol:
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Noooo.. don't taken me from the haven of the Graphics folder.. nooooo.

:wink:
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I said that so that all those yummy delightful snippets may be found in one place instead of half lying in graphics folder & other half in code snippets... i guess you love graphics like crazy :lol:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

If you would be so kind to give me links to all your snipplets, I will do so.

Edit | I've moved about 5 threads over, most of them were deprecated code (thanks to PHPBB version changes) but I had fixed them.
It seems you have a couple function on clipping corners.. lol
Also I had left a couple of your larger scripts that were corrupted in the phpbb version.. blah.. so I'll leave that up to you to convert.
Post Reply