Archive for January, 2010

Greasemonkey Script: Remove Wikipedias liquid layout for article content to ease reading

January 21st, 2010

I’ve recently upgraded to a new large screen monitor. It’s great for many things–but browsing the internet is not one of them. Fixed width web pages look awkward in the middle of my browser with massive amounts of space on either side and liquid layouts cause LONGGGGGGG lines of text, which makes reading much more difficult. I forget the exact study, but I remember reading a study that anything more than 60 words per line and your reader will lose their much more often.

Wikipedia uses a liquid layout for their articles, and this makes reading articles on hard-to-understand topics that much more difficult to comprehend.

This Greasemonkey script for Firefox will adjust the width of the content to make it easier to digest. Nothing fancy here. Just few changes to the styles–but helpful nonetheless!

Click through to get the script.

» Read more: Greasemonkey Script: Remove Wikipedias liquid layout for article content to ease reading

Separate RGB Channels from an Image in PHP

January 20th, 2010

Divide an conquer! That’s what I always say. But how do you go about dividing an image up into it’s separate channels–like Photoshop does it?

There are actually two ways to go about doing it. First, is displaying the actual amount of red, green, or blue that is contained in each pixel which results in images that are made up entirely of shades of the color channel that you are viewing. The second is to to simply display the information in an easily understood visual representation by using shades of grey. Both are detailed below.
» Read more: Separate RGB Channels from an Image in PHP

pr() a print_r enhancement for your HTML web page

January 18th, 2010
function pr ($mixed)
{
	echo '<pre>' . htmlentities( utf8_encode( print_r( $mixed, true ) ), ENT_QUOTES, 'utf-8' ) . '</pre>' ;
}

When writing PHP, I often find that I need quick debug access to an Object or Array to see what it contains. PHP provides print_r, which works great–except that the data appears without all the tabbing in regular ol’ HTML. This is annoying for large Arrays or complex Objects.

That is why I created the pr() function. It basically just wraps the output of print_r in pre tags and then your formatting is back.

Depending on the encoding of the data you are passing to and getting from print_r, you may run across problems when combining print_r and htmlentities (with utf-8). If the encodings don’t match, it may return nothing at all! This could either mean that the variable is some kind of empty, or it could mean that htmlentities didn’t like the encoding that was returned by print_r, and crapped all over itself.

So, you first have to convert the data returned by print_r to utf8 (or whatever the encoding of your web page is) before passing it along to htmlentities. Since I try to keep every web page I work on in utf8, I keep this function set up to compliment that.

As long as you have a working utf8_encode, this function should always output pretty, utf-8 encoded data in HTML. If you need to convert to some other encoding beside utf8, you can use mb_convert_encoding.

More examples of image manipulation with PHP

January 14th, 2010

All of these examples use the PHP simple image manipulation class that I created.

Every now and then I write a batch image converter snippet that others might find useful. I figure I’ll post them here for my benefit and yours. These snippets will also serve as a way to better understand the class. As I come up with these in life, I’ll update this post.

All of these examples assume that you’ve already included the class in your file.

» Read more: More examples of image manipulation with PHP