Thumbnail generation with PHP

In this tutorial we will be taking a look at how we can open existing images, check on their current dimensions and then intelligently do a proportionate resize on them., dynamically creating thumbnails on the fly to display in the browser.

In previous tutorials we have looked at how we can set up PHP so that our extensions are correctly installed. Rather than covering that again, this week we will look at ways that you can check if the extension that you want is installed and supports the things that you want to do. We will be working with the free GD extension.

$2.79
- OR -

Overview

Table of Content:

  • Checking that the installation is up to scratch
  • Checking if the extension is installed
  • Checking that the functions you need are present
  • Getting information about the file
  • Width and height from a file on disk
  • Getting the width and height from an image resource
  • Determining the new width and height
  • A percentage of the original
  • Constrain the thumbnail to specific sizes
  • Constraining the longest edge to a specific size
  • Creating a new image
  • Resizing the original image to a thumbnail
  • Displaying the thumbnail
  • Conclusion

Allan Kent

Allan KentAllan comes from Cape Town, South Africa. He has been implicated in writing for several WROX, glasshaus, Wiley and Apress publications, generally in the 'cool stuff that PHP can do' sections.

You can catch up with him at his website http://www.mediafrenzy.co.za.

See All Postings From Allan Kent >>

Reviews

Be the first to write a review

You must me logged in to write a review.