Tag Archives: PHP

PHP: How to proportionally resize an uploaded image

Big mug and tiny mug
Say you have a form where someone can upload a profile image. The uploaded image can be of any size of course, but you want all the profile images to fit inside a certain frame. You could just set the dimensions on the image tag to this size, but in most browsers that would look ugly, and it would also most likely stretch the image. It would look awful. In addition you would be serving a image which most likely was a lot larger than you wanted it to be. This would cost you bandwidth.

In this case you might want to proportionally resize the image to the appropriate size when you get it uploaded. You can then store the resized image instead and serve it directly with no problems afterwards. It doesn’t have to be difficult! Here’s how 🙂

Continue reading PHP: How to proportionally resize an uploaded image

PHP: Output a number of bytes in human readable form

Would you be able to say how much 167892598784 bytes are without spending quite some time thinking about it first? Large amounts of bytes are rarely very readable to people. Not for me anyways.

Just stumbled over a handy function to make that number of bytes a bit more readable for us humans. I found it in a comment in the PHP manual and figured I could note it down here so I don’t lose it and in case someone else could need it. A function like that is just bound to come in handy some day…

Continue reading PHP: Output a number of bytes in human readable form

PHP Tutorial: PayPal Payment Data Transfers (PDT)

MoneySay you have a PayPal “Buy Now”-button on your website and you have assigned return URLs like http://example.com/order?done and http://example.com/order?canceled. You can then welcome the user back after a successful payment. But what if you wanted to say something more interesting than just “hey, welcome back” when they click on that “Return to Merchant”-button? And can you know if the order was actually done or canceled? Maybe you’d like to log the transaction in your database and mark a payment as complete or something like that too? In that case you sure can’t trust a simple flag in the address bar…

Payment Data Transfer (PDT) is a secure method to retrieve the details about a PayPal transaction so that you can display them to your customer. It is used in combination with Website Payments Standard, so that after a customer returns to your website after paying on the PayPal site, they can instantly view a confirmation message with the details of the transaction. — PayPal

I’ve tried to figure out how to use PDT and found that most samples and classes to build from are usually quite ugly, old or outdated. I didn’t find them too useful anyways… So, therefore, I’ve tried to do my own thing based on the documentation found on the PayPal Developer websites. (Seriously, how many versions of documents and developer websites do they have anyways? It’s like a complete jungle…)

Since the documentation was a bit of a mess, I thought I make a small tutorial on the steps needed to get started. That way I can learn it better myself and hopefully help some other poor souls that need to figure this stuff out as well. Please provide feedback if you have any! Would love to make this page nicer and clearer if possible 🙂

Continue reading PHP Tutorial: PayPal Payment Data Transfers (PDT)

PHP: Generating transparent PNG fillers

So, I was fooling around the other day with an HTML table and wanted to make the odd rows slightly darker. Figured I could use for example an 80% transparent black PNG to do that (or could have just assigned a darker color, but where’s the fun in that?). Either way, ended up making a little something that I thought I could share just for the fun of it. I learned a few things, so maybe someone else can too 🙂

So, here’s how to make a small transparent PNG filler image on-the-fly using PHP 🙂

Continue reading PHP: Generating transparent PNG fillers

Kohana PHP framework

As you might know, I am developing some internal software for LifeStyleTV at the moment. Because of various slightly annoying circumstances I am stuck using PHP and MySQL for this. Not the worst of course, but I must say I really do prefer C# over PHP for oh so many reasons. But anyways, that wasn’t the point of this post. The point is that for my life to become hopefully quite a bit easier and hopefully a lot more organized I decided to go looking for a framework I can use as a base for the software I will be developing.

After much looking I finally stumbled over a framework called Kohana.

Continue reading Kohana PHP framework