Hosting Grumpydev Imageflair locally
Posted by jpluimers on 2017/04/06
Even though StackOverflow and StackExchange now have implemented their own ImageFlair, I still like the original imageFlair that Grumpydev made at Stack Overflow – Share Your Flair – Now in PNG! | GrumpyDev
Grumpydev Imageflair

Stackoverflow imageflair
Alas, the Grumpydev site doesn’t properly support https and Grumpydev cannot change it because of shared hosting limitations, so I wanted to host ImageFlair locally and even see if I could make it StackExchange aware:

Stackexchange flair
Well, I need to do that propertly another time as the first thing I bumped into was this:
PHP Fatal error: Call to undefined function imagecreatefrompng() in /srv/www/vhosts/pluimers.com-ssl/stackoverflow/imageFlair/imageFlair.php on line 42
For now I’ve fixed the first by installing php5-gd (although an SO answer suggests php-gd, openSuSE uses the php-version number for installing modules).
zypper install php5-gd php -m rcapache2 stop rcapache2 start rcapache2 status
This will install the module, check with php if it is indeed installed, then restart apache to let it use the updated module.
After that, I bumped into a second thing: the image is blank.
I also bumped into a third thing: the .htaccess file rewrite doesn’t work:
https://www.pluimers.com/stackoverflow/imageFlair/so/1.png gave me a 404 error whereas https://www.pluimers.com/stackoverflow/imageFlair/imageFlair.php?userid=1&mode=so “works” (i.e. generates a blank image).
That one was sort of easy to solve.
First of all, apparently I didn’t have all the required apache modules installed. The not-so-easy part is that apache uses two different aliases for modules: the ones listed by apache2ctl -M 2>&1 | sort are in a different format than the ones you mention in .htaccess and .conf files. Oh and of course the -M (nor the -t -D DUMP_MODULES) aren’t listed ore hinted in the apachectl documentation: that would be too easy. They are listed in the httpd2 documentation.
The .htaccess file needs mod_rewrite and mod_expires, but apache2ctl names them rewrite_module and expires_module.
Enabling these was easy, but you have to remember that a2enmod strips the prefix/suffix of the module name (I already had expires_module (shared) installed so this only shows how to enable mod_rewrite):
a2enmod rewrite
rcapache2 stop
rcapache2 start
rcapache2 status
NB: mod_rewrite wasn’t enable by default and before enabling it, read about the risks of mod_rewrite.
Then it still didn’t work, and then it occurred to me that likely I didn’t even have Apache2 allow for using .htaccess as the regexes in the .htaccess were fine. And indeed: .htaccess wasn’t enabled according to the steps at Making sure .htaccess and mod_rewrite are working as they should | Bolt Documentation. And indeed, the Apache documentation indicates when (not) to use .htaccess.
By setting the AllowOverride to both FileInfo as specified by RewriteRule and Indexes as specified by ExpiresActive (trying to refrain from AllowOverride All) for only this specific directory, I think I struck the right balance:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Directory "/srv/www/vhosts/pluimers.com-ssl/stackoverflow/imageFlair"> | |
| # for .htaccess in that directory | |
| AllowOverride FileInfo Indexes | |
| </Directory> |
And the final thing is that the logic around StackExchange flair is a tad more complex than I hoped for. And on that bombshell…
–jeroen







Hosting Grumpydev Imageflair locally – part 2 – trying to get the text and images to display « The Wiert Corner – irregular stream of stuff said
[…] Hosting Grumpydev Imageflair locally ended with two issues left: an empty image and my wish to include more complete StackExchange bits like the current StackExchange flair does. […]