Thumbnails not working, no error messages!
-
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.
- The topic ‘Thumbnails not working, no error messages!’ is closed to new replies.