GD2 not recognized by CB (Temporary Solution)

15 years 3 months ago #82167 by ecomecom
While working on my site, I ran into the problem of CB not initializing GD2.

Although PHP and Joomla (in System Info) says that GD2 is present, CB (in Configuration > Images tab) mentions that GD2 library Not installed. So, it generates the error "Error: PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed."

In my server GD2 was enabled with GIF and PNG support, but without JPEG support (probably due to scepticisim of the admins).

The errors generated by CB made it impossible to use the avatars although there was GIF and PNG support.

I searched the forum for a solution to this problem and could not find any. So I examined CB files. And I think I found the solution. Here it comes:

The problem is in imgToolbox.class.php file. In lines 134-142, CB tries to initialize the presence of GD2 using the existence of imagecreatefromjpeg() function. (see below)

[code:1]
GD2
case 4:
if (!function_exists('imagecreatefromjpeg')) {
$error=1;
$errorMSG = "Error: PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed";
}
if (!function_exists('imagecreatetruecolor')) {
$error=1;
$errorMSG = "Error: PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the config page";
}
[/code:1]

and when there is no JPEG support from GD2, CB assumes that there is no GD2 support although there is GIF and PNG support.

Anyway the shortcut to my solution was to simply delete those lines. I also modified lines 219-222 as

[code:1]
function acceptableImageList(){
//return array('jpg', 'jpeg', 'gif', 'png');
return array('gif', 'png');
}
[/code:1]

so that CB generates the error "Error: jpg is not a supported format." when a user tries to upload a jpg file.

I also added the line to comprofiler.html.php

[code:1]
echo "<br>"._UE_ACCEPTED_EXTENSION_STATEMENT;
[/code:1]

just after line 540 which is;

[code:1]
echo _UE_UPLOAD_DIMENSIONS.": ".$ueConfig."x".$ueConfig." - ".$ueConfig." KB";
[/code:1]

so that it displays the user to upload only GIF or PNG file. However you also have to define _UE_ACCEPTED_EXTENSION_STATEMENT in default_language.php
as

[code:1]
DEFINE('_UE_CAPTCHA_AUDIO_DOWNLOAD','Click to externally play or download audio file');
DEFINE('_UE_CAPTCHA_AUDIO_CLICK2DOWNLOAD','(right-click or control-click)');
DEFINE('_UE_CAPTCHA_AUDIO_POPUP_CLOSEWINDOW','Click to close window');
DEFINE('_UE_ACCEPTED_EXTENSION_STATEMENT','JPG and JPEG files are not accepted due to server restrictions. Only <b><u>PNG and GIF files</u></b> are accepted.');


// Watchout to NOT add any line or space or anything after the "?" and the ">" if you decide to add these at the end of the file !!!
// As they are not needed, we removed them to avoid page errors because of that.
[/code:1]

Hope this resolves "GD2 not recognized" issue. It is not a permanent solution but it works. However I recommend CB developers to initialize GD2 in an alternative way. The gd_info() function can be used to initialize the presence of GD2 instead of checking the presence of imagecreatefromjpeg() function.

Post edited by: ecomecom, at: 2008/12/12 16:11

Post edited by: ecomecom, at: 2008/12/12 17:48

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.249 seconds

Facebook Twitter LinkedIn