Laconica, PHP5, and GD Woes - and a quick patch!
Tim July 26th, 2008
So, I’ve been playing around a bit with Laconica, an open source micro-blogging engine used to power Identi.ca. I finally have it up and running smoothly, however, I’ve found that the “official” installation documentation is a bit sparse and missing a few steps and dependencies. Because of this, a few snags in the setup process had me scratching my head. What did help me immensely in the process is the following blog entry on 0xDECAFBA - Getting Laconica up and running.
The problem I ran into was with the avatar upload. When I tried to upload my avatar, I would be greeted with a blank page (the “oh-crap-internal-server-error-where’s-my-whiskey” kind of blank page). I opened up my /var/log/httpd/error_log to seek out what exactly occurred. Here’s what I found:
[Wed Jul 23 13:01:55 2008] [error] [client 10.6.132.139] PHP Fatal error: Call to undefined function image_type_to_extension() in /var/www/html/laconica/classes/Profile.php on line 85, ...
Interesting. My brand new fancy avatar is now reduced to a broken image in Laconica. To revert back to the default gray and apathetic face avatar, simply remove all entries in the avatar table of your Laconica DB instance.
Some quick background about the configuration:
$ uname -srvpio
Linux 2.6.18-92.1.6.el5PAE #1 SMP Fri Jun 20 02:51:01 EDT 2008 i686 i386 GNU/Linux
$ php -version
PHP 5.1.6 (cli) (built: Jun 12 2008 05:02:35)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
A fairly recent setup. Since this was a fresh install, I figured something had to be wrong with the installation of the PHP GD libraries. Naturally the next step would be to do a var_dump(gd_info()); to confirm any issues:
array(12) {
["GD Version"]=>string(27) "bundled (2.0.28 compatible)"
["FreeType Support"]=>bool(true)
["FreeType Linkage"]=>string(13) "with freetype"
["T1Lib Support"]=>bool(false)
["GIF Read Support"]=>bool(true)
["GIF Create Support"]=>bool(true)
["JPG Support"]=>bool(true)
["PNG Support"]=>bool(true)
["WBMP Support"]=>bool(true)
["XPM Support"]=>bool(false)
["XBM Support"]=>bool(true)
["JIS-mapped Japanese Font Support"]=>bool(false)
}
Nope. Everything looks fine with the setup. And according to PHP.net, image_type_to_extension() should be available for >=PHP5.0. This, however, doesn’t appear to be the case. As Chris notes:
Function was added in PHP 5.2, not PHP 5 (you would assume this means 5.0)
So, evidently, my current version of PHP (and the most recent in the RHEL5 repos) does in fact not support the image_type_to_extension() function. If you have the most recent version of PHP, you should be fine. If not, here’s the fix: To work around this issue, I devised a simple modification that would overwrite the image_type_to_extension() functionality if you’re experiencing the same issues. Head to $LACONICA_HOME/classes/, back up Profile.php, and then open it up in your favorite editor. Head to Lines #84 and #85 $filename = common_avatar_filename($this->id, image_type_to_extension($info[2]), NULL, common_timestamp()); and replace it with the following code snippet below:
# Start - More RAM.
if(function_exists(image_type_to_extension))
{
$extension = strtolower(substr(image_type_to_extension($info[2]),1));
}
else
{
list(,,$imageType) = getimagesize($image);
switch($imageType)
{
case IMG_GIF:
$extension = ".gif";
break;
case IMG_JPG:
$extension = ".jpg";
break;
case IMG_PNG:
$extension = ".png";
break;
}
}
$filename = common_avatar_filename($this->id,$extension,NULL, common_timestamp());
#END - More whiskey.
Save Profile.php, and now try to upload a new avatar. Problem fixed!






