Thumbnail Generator in CakePHP

class ImagesController extends AppController {

var $name = ‘Images’;
var $uses = null;

// we want to ensure that the default layout doesn’t get rendered around your image data
// that was causing me lots of errors that i thought were BOM errors, until i commented
// out the header call in the view file

var $layout = null;

function thumbnail($filename=”) {

// create a thumbnail on the fly for product images

$parentImage = IMAGES_ROOT.’productImages/’.$image_file;
$thumbImage = IMAGES_ROOT.’productThumbs/’.$image_file;

// the thumbnail does not exist, create it before sending the location of it to the browser.
//header(“Content-type: image/jpeg”);
$im = imagecreatefromjpeg($parentImage);
$orig_height = imagesy($im);
$orig_width = imagesx($im);
$new_height = 60;
$new_width = (int) (($new_height / $orig_height) * $orig_width);
$new_im = imagecreatetruecolor($new_width,$new_height);
$image = ob_get_clean();
$thumb_pointer = fopen($thumbImage,’w+’);
header(“Location: /img/productThumbs/{$image_file}”);


About Tanveer
RIA (Rich Internet Application) Developer with a wide variety of business applications. Particularly interested in client/server and relational database design. Always interested in migration projects, as well as close interaction with the DB manufacturers.

7 Responses to Thumbnail Generator in CakePHP

  1. Alex says:

    I really don’t understand what do you want to explain with this short tut!!
    The red lines what they mean ?

  2. Tanveer says:

    Hi Alex,
    Thanks for your comment. It was just mistake i think.
    Now it’s OK 😉

  3. Gday, that was a superb article! Lots of high-quality material, I am thrilled that I seen it.

    I am definitly going to book mark your site! 🙂

  4. I think the admin of this site is genuinely working hard in support
    of his web site, because here every data is quality based material.

  5. Hobbies says:

    Paragraph writing iis also a excitement, if you be
    familiar with then yyou can write if not it is complex to write.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: