Image Re-hoster

I have been following the progress of a start-up called microPledge for a while now. The site lets you post an idea for software you would use and pledge money towards its creation. I came across a proposal for a piece of software that lets you copy an image from any website to your server in a few clicks. It is a problem I have had before, and I figured I could use the software too, so I made a bid to create it for $10 and I got the project. Before I finished, a few more people pledged on it, so I ended up making $23 for it. This was still not much money for the work I did, but the cool part is that at the end of the project I can release it to the public (in fact, microPledge does this automatically). So the way I look at it is, I would have spent that time writing open-source code anyway, I might as well get a free lunch or two out of it.

hoster_2.png

As far as I can tell, this was the first open-source project to be completed through microPledge. We ran into a few bugs, but Ben Hoyt, one of the site’s founders, was very helpful and fixed all the bugs we ran into within hours. If you want to pitch an open-source project idea to programmers, microPledge is the place to go. Greg, the guy who pitched the idea and pledged towards it, had a good experience as well.

As for the script, basically it sits on your server and lets you add a little button (a bookmarklet) to your browser. When you click the button, all the images on the page you are on have a little cross-hair over them when you mouse-over them, and when you click them they are downloaded to your server and you are shown the URL. This is great for when you come across a GPL or fair-use image so you don’t have to go through the process of manually uploading it to your server, or hotlinking it. You can find the latest version hosted at microPledge.

Posted on Aug 19th, 2007 in PHP

Proper Image Resizing for WordPress

WordPress has a cool WYSIWIG editor that lets you easily resize images by dragging the corner around. The problem is that WordPress does not actually resize the image, it just tells the browser to display it smaller. This means that the full sized image is being sent to the browser, which makes the page load slower and take up more bandwidth. Additionally, most browsers are bad at resizing images, so the images look worse than if they were properly resized.

To get around this, I wrote a WordPress plugin called ImageScaler. I am still waiting for it to be approved by WordPress for hosting, so I have hosted it myself for now. It requires GD (almost all web hosts with PHP will have GD). It should work with PHP 4, but it has only been tested on PHP 5.

Here is an example of a scaled image (click it for the original):

fractal1.png

Download ImageScaler 0.1

Update: the plugin is now hosted by WordPress.

Posted on Jul 30th, 2007 in WordPress, PHP

Endless Google Search

I felt like coding today, so I put together a little hack from an idea I have had for a while. What I came up with is a web search (powered by Google), that loads new search results as you scroll the page down. Try it, it’s actually pretty cool.

Here is how it works: there is a large div element at the bottom of the page just to take up space. When it comes onto the screen, an ajax request is made to the server to get the next 10 results from Google. The requests are made through Google’s SOAP api, which is no longer available, but I had an old API key so I was able to get it to work. I had all the client stuff working within an hour, but Google’s API took a while to figure out. Google uses SOAP, which is powerful but hard to code for compared to a simple GET API. It took me a couple of hours to get the server-side stuff working but it is still a hack, so don’t be surprised if you get an error or some unexpected behaviour.

It was designed for FireFox/Mozilla browsers. The only other browser I have tried it with is IE, which it does not work with. So if you are using Internet Explorer, you won’t see anything interesting.

Try it here

Posted on Jun 06th, 2007 in Web Apps, PHP

A simple diff algorithm in PHP

A diff algorithm in its most basic form takes two strings, and returns the changes needed to make the old string into the new one. They are useful in comparing different versions of a document or file, to see at a glance what the differences are between the two. Wikipedia, for example, uses diffs to compare the changes between two revisions of the same article.

Solving the problem is not as simple as it seems, and the problem bothered me for about a year before I figured it out. I managed to write my algorithm in PHP, in 18 lines of code. It is not the most efficient way to do a diff, but it is probably the easiest to understand.

It works by finding the longest sequence of words common to both strings, and recursively finding the longest sequences of the remainders of the string until the substrings have no words in common. At this point it adds the remaining new words as an insertion and the remaining old words as a deletion.

You can download the source here: PHP SimpleDiff

Posted on May 15th, 2007 in PHP