Get Thumbnail Issue

Hi there,

I am using the getthumbnail code to outut my thumbnail in the page list loop. However when it reaches the ciode it stopes rendering the page, but doesnt throw an error. When i attach a smaller image to the page attribute it works. But when i attach a larger image it stops the page rendering.

Is there a limit in file size for the get thumbnail function..?

My code is:

$ih = Loader::helper('image');
$img = $page->getAttribute('boat_main_image'); // Grab the image
 if(isset($img)) { // Make sure you have an image
         $thumb = $ih->getThumbnail($img, 100, 100, false); // Create the thumbnail
if(isset($thumb)) {
     <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />

View Replies:
goutnet replied on at Permalink Reply
The point is probably that for bigger sizes, the script will get killed by your server (because of the php script execution time restriction).

You can set it to something bigger if you need :

on shared hosts, you might not be able to change that value.
goutnet replied on at Permalink Reply
Oh, and another point :

using getThumbnail($img,100,100) will not preserve the aspect ratio of your image, if you want to keep the ratio, use something like this :

$ih->getThumbnail( $img, 9999, 100 )
obaudains replied on at Permalink Reply
Thank for the response.

No that doesn't work in afraid.
I have increased it by a lot and it still fails to render the remainder of the page from where the image is output.

I am quite confused as there doesnt appear to be limitations on size in the image helper documentation. Is there another function i should be using to output and resizxe images..?

jkoudys replied on at Permalink Reply
I'm on and also started seeing this. My site's working perfectly fine on my PHP5.3.22 host, and my PHP5.4 ubuntu machine (currently out of power as I forgot to bring my charger while visiting my family for the holidays). I set up a VM to work off of, which is PHP5.5.3, and this started happening. I've checked my PHP log settings, and my C5, and thrown a few test exceptions to make sure it's logging, and it is, it just doesn't log the image helper's failure on getThumbnail(). I even tried surrounding it by its own try-catch and it still just mysteriously stops rendering once that line's reached. The page loads instantly and it's not resizing that big of an image, so it's definitely not a timeout issue.

Since no exceptions were being properly reported, I debugged this the ugly way and just echoed __LINE__s through the image helper. The line it's failing on is 252 in the getThumbnail(), which on my version is:
$this->create($path, DIR_FILES_CACHE . '/' . $filename, $maxWidth, $maxHeight, $crop);

and inside the create function, it's line 148 that's failing:
//create "canvas" to put new resized and/or cropped image into
if ($crop) {
$image = @imageCreateTrueColor($width, $height);
} else {
$image = @imageCreateTrueColor($finalWidth, $finalHeight); // line 148

So you'll see a @ on the imageCreateTrueColor, which is what's eating our exception. Removing that, we get our exception:
<b>Fatal error</b>: Call to undefined function imageCreateTrueColor() in <b>/home/ubuntu/janes-walk/concrete/core/helpers/image.php</b> on line <b>146</b><br />

The imageCreateTrueColor() function is part of the gd php extension. Since this is an ubuntu 13.10 VM, I installed this easily enough:
sudo apt-get install php5-gd

Restarted apache, and now it all works!

While my VM is now ready to go, having gone through this I'm wondering what the rationale was behind having the @ on that function call. It is a real nuisance trying to debug this when you're getting no errors (either logged to the 'logs' table, to the apache2 error log, or written to the rendered page.) It's a pretty easy problem to solve once you have the exception. My biggest worry is that people will have their C5 apps deployed, their host does some big upgrade/migration, and then this breaks. Getting no exception on a live site would be pretty scary and might turn a lot of people off of C5, but with an error it'd be just another type of error people expect when doing a site migration. Maybe suppressing the error is fine, but it should just write it to the log and then continue processing. Breaking the entire page is pretty bad, but simply not showing an image thumb and logging the error would be a relatively small problem.