Archive for December, 2009

Simple Image Manipulation in PHP (Rotate, Resize, Crop, Flip and Mirror, Thumbnails square and regular)

December 31st, 2009

UPDATE: I’ve added support for PNG alpha transparency which makes this class significantly more useful. Changelog in the class code below.

I keep misplacing this class so I figured I’d post it here so that I know where it is.

I wrote/assembled this class because I wasn’t happy with any of the image manipulation libraries out there. They are either way too complex with a steep learning curve or didn’t work all that great. (I didn’t see any reason to load up a class with 3,000 lines of code just to resize or rotate an image.)

So here it is, a simple class that allows you to open an image, perform common operations, and save. There are no bells and whistles or anything exciting here. Just a collection of commonly used image manipulation functions: Rotate, Flip, Resize, Thumbnail (square and regular), and Crop.

A lot of the class code is original but some of it has been gathered over my life as a programmer from long lost sources. If you recognize your work, leave a comment and I’d be happy to cite you!

» Read more: Simple Image Manipulation in PHP (Rotate, Resize, Crop, Flip and Mirror, Thumbnails square and regular)

Firefox and broken images: Help get the behavior changed

December 30th, 2009

Whenever I am working on a PHP script that generates an image, I am always frustrated by the standard Firefox broken image error.  The problem is that I have PHP output error messages to the screen while developing for the sake of simplicity.  These error messages mix with the binary data of the image, and it causes the image to break.  The end result is no image, and no error messages.

But what if I want to read those helpful error messages?

» Read more: Firefox and broken images: Help get the behavior changed

AdCenter SEMs lives just got easier (Greasemonkey script inside)

December 18th, 2009

If you are a search engine marketer that has used Microsoft’s AdCenter, you probably have found it a bit annoying that when creating text ads, it doesn’t tell you how many characters you have left.

This means that the genius PPC ad-copy that you just wrote will only be rejected when you go to save because it is too long.

This Greasemonkey script detects when the new text ad dialog is visible, and will update the remaining characters that you have left to use as you type.  Something that Microsoft should have done…. pay me MS, you lazy bastards.

This isn’t the only thing I find annoying about Microsoft AdCenter, but all the Greasemonkey scripts in the world won’t fix it. Click through for the script.
» Read more: AdCenter SEMs lives just got easier (Greasemonkey script inside)

Stop the toolbar and overlay madness!

December 11th, 2009

If you are thinking about putting a “toolbar” on your blog, please reconsider right now.

In recent months, I’ve noticed a resurgence of the website toolbar.  What is a website toolbar?  Usually, it takes the form of a small bar that is on your screen at all times, and it provides little links to supposedly helpful tasks for the visitors of the website.  It seems that this company is responsible for most of the madness through their freely available script.

In the toolbar pictured above, you can search the website, translate it, get the sites latest news, or share the page with the community of your choice. Helpful right?  Wrong.

» Read more: Stop the toolbar and overlay madness!

Piracy and the Myth of Lost Profits

December 7th, 2009

As some of you may know, I’ve made the horrible mistake of going back to school.  These days, I spend my free time doing homework instead of working on things that really matter to me, which I treasure and it is of the utmost importance to me.  I’m happy to be doing all this extra work, because it earns me a magical sheet of paper that won’t be worth the paper it’s printed on because of the rapidly evolving field of computers a BS in IT, which I will proudly display on my wall.

The good thing about this whole school thing is that I’m getting learned on dem books, and it has also given me the opportunity to complete a previous thought that I called my downloading is theft rant.  I’ve taken that idea there, twisted it, rubbed some spit on it, and turned it into some kind of research paper (with the help of my girlfriend who was able to remove all my sarcastic remarks from the final draft). After spending a bunch of hours on it, I figured I might as well put it up here for anyone who is interested and to prove that I can in fact write a complete sentence.

In case you were wondering… here is an example of the sheer brilliance that my girlfriend had to edit out:

So who is doing all this pirating?  Terrorists.  That’s according to a study by The RAND Corporation that was “made possible by a grant from the Motion Picture Association.”  That’s right; those vile individuals that are hell-bent on the destruction of America have lately taken to a more subtle approach to the complete and utter obliteration of the American way of life: pirating Black Hawk Down on DVD.  So, Osama Bin Laden is selling DVDs in the mountains of Pakistan?  Not exactly.  According to the study, there aren’t really any clear connections to terrorism.  It can be said that movie piracy is connected to terrorism in the same way that Iraq was connected to al Qaeda and weapons of mass destruction – not at all.

So without further ado, break out your red pens and put away your fact checker…

Piracy and the Myth of Lost Profits, starring Johnny Depp.

» Read more: Piracy and the Myth of Lost Profits

Paypal support: down, Skype support: down, Ebay support: down

December 4th, 2009

ebayfail

You can’t make this stuff up.

» Read more: Paypal support: down, Skype support: down, Ebay support: down

Another look at Repeatable Random

December 3rd, 2009

My last post was about a similar subject only with an emphasis on generating an evenly distributed set of random numbers that existed between a minimum and maximum value.

I found this post from Jackson Dunstan about a repeatable random class written in AS3.  In that post, he mentioned that it could easily be ported to Javascript or other languages — and he was right.  Here is that class written in Javascript and as far as I can tell, it does indeed produce a repeatable random set of numbers.

His class works by taking an initial seed number, performs a simple mathematical calculation, and then returns it before making it the new seed number, and starting the cycle over. The result is a set of random numbers that are repeated based on the starting seed number.

A technique such as this is mainly used for video games but it could also be useful in web development to randomly place objects on a page. This code doesn’t do much of anything by itself but is a good jumping off point. See a working example at the bottom of this page.

» Read more: Another look at Repeatable Random

Repeatable Random: An even distribution of pseudo-randomness

December 2nd, 2009

duck_goose_medium

Does the concept of true randomness really exist?  To tackle that question we must first ask ourselves, does free will exist, or are all our lives pre-determined based on some cosmic event that happened billions of years ago?  That is a question I’m not going to even try to answer in this post. Instead, I will provide you with a simple PHP function that can provide you with a repeatable random number generator.

OK, maybe “random number generator” isn’t an accurate name for it. Perhaps hasher-to-evenly-distributed-values generator would be a much better title since that is exactly what it does.

Why would you need such a thing?

Random numbers are great. They allow you to give your web applications some personality. Let’s say you only want to display a message on a web page ~10% of the time. Random numbers allow you to do this. You would simply do something like: if ( rand ( 1, 10 ) == 5 ) echo ‘This is my message. I display about 10% of the time!’;

That’s all well and good, but what if I want to display a random message to my visitors AND make sure they see the exact same one each time? Not possible with plain ol’ random.

However, it is possible with this very simple repeatable_random PHP function.

» Read more: Repeatable Random: An even distribution of pseudo-randomness

Serious Facelift vulnerability discovered – Details and fix included

December 1st, 2009

Update immediately! A serious directory traversal vulnerability has been discovered that affects all versions of Facelift.  It could allow an attacker to retrieve plaintext versions of any file that PHP can read. This could include your WordPress database settings, for example. It is bad.

A patched version has already been made available at the facelift homepage.  If you downloaded facelift in the last couple days and the zip file was either *2.0b3-B or 1.2.2 then you have the patched version. If not you should either update your Facelift installation or remove generate.php immediately.

To update your Facelift installation, please download an updated version. Overwrite the generate.php in your install with the patched version from the download. You can leave your config-flir.php and all other files alone. The problem only affects generate.php.

Many Facelift plugins are available for Drupal, Joomla, WordPress  etc.  I’ve already contacted as many of these authors as I could and most have already issued fixes.

The problem exists in generate.php and is due to a variable not being properly sanitized. Big thanks goes out of Johannes Herbst for discovering the problem.

If you are using one of the third-party plugins, please update your plugin immediately.

Manually Fix:

The problem can be fixed by changing one line in generate.php:

Facelift v1.2:

$FLIR['output']        = isset($FStyle['output']) ? ($FStyle['output']=='jpeg'?'jpg':$FStyle['output']) : 'auto';

Change To

switch ( $FStyle['output'] ) {
	default: 	$FLIR['output'] = 'auto'; 	break;
	case 'png': $FLIR['output'] = 'png'; 	break;
	case 'gif': $FLIR['output'] = 'gif'; 	break;
}

Facelift v2.0b3

$FLIR['output']        		= isset($FStyle['output']) ? $FStyle['output'] : 'png';

Change To

switch ( $FStyle['output'] ) {
	default: 	$FLIR['output'] = 'auto'; 	break;
	case 'png': $FLIR['output'] = 'png'; 	break;
	case 'gif': $FLIR['output'] = 'gif'; 	break;
}