• That’s what I was faced with after I upgraded from B2, which I’d hacked to do thumbnails (so I knew that it was possible on my server.)
    Anyway, after some reading on php.net, apparently, if php was compiled with older versions of gd (which mine was,) then the “imagecreatetruecolor” function causes php to give a fatal error ??
    There’s a detection workaround posted at https://ca2.php.net/manual/en/function.imagecreatetruecolor.php (becuase “function_exists(imagecreatetruecolor)” still returns true) and a method that created the thumbnails properly for older versions of gd posted there as well.
    The end result is that in the file “wp-admin/admin-functions.php”
    the line
    $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
    needs to be replaced with

    if (gd_version() >= 2) {
    $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
    } else {
    $thumbnail = imagecreate($image_new_width, $image_new_height);
    imageJPEG($thumbnail, substr($file, 0, strrpos($file, '/')) . "temp.jpg");
    $thumb = @imagecreatefromjpeg(substr($file, 0, strrpos($file, '/')) . "temp.jpg");
    }

    and then add in the following function somewhere:

    function gd_version() {
    static $gd_version_number = null;
    if ($gd_version_number === null) {
    // Use output buffering to get results from phpinfo()
    // without disturbing the page we're in. Output
    // buffering is "stackable" so we don't even have to
    // worry about previous or encompassing buffering.
    ob_start();
    phpinfo(8);
    $module_info = ob_get_contents();
    ob_end_clean();
    if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i",
    $module_info,$matches)) {
    $gd_version_number = $matches[1];
    } else {
    $gd_version_number = 0;
    }
    }
    return $gd_version_number;
    }

    Hope this helped someone.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nodecam

    (@nodecam)

    The code for that function looks like it got messed up some – I got it from a comment posted by Justin Greer at: https://ca2.php.net/manual/en/function.imagecreatetruecolor.php

    Yea, the code above did get messed up. To revert back to GD 1.6.2 or anything before 2.0 you’ll have to replace the following two lines:

    $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
    @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);

    with this:

    if (gd_version() >= 2) {
    $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
    @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
    } else {
    $thumbnail = imagecreate($image_new_width, $image_new_height);
    @ imagecopyresized($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
    imagejpeg($thumbnail, substr($file, 0, strrpos($file, '/')) . "/temp.jpg");
    $thumb = @imagecreatefromjpeg(substr($file, 0, strrpos($file, '/')) . "/temp.jpg");
    }

    Then add the gd_version() function from above and you should be good to go. You’ll notice the code above is missing two forward slashes and fails to rename the ‘imagecoypresampled()’ function.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Thumbnails not working, no error messages!’ is closed to new replies.