{"id":278,"date":"2015-02-23T18:24:54","date_gmt":"2015-02-23T17:24:54","guid":{"rendered":"http:\/\/hobbykeller.spdns.de\/?p=278"},"modified":"2018-06-10T20:00:03","modified_gmt":"2018-06-10T18:00:03","slug":"openwrt-freetype-support-for-libgd-in-php5-mod-gd","status":"publish","type":"post","link":"https:\/\/hobbykeller.spdns.de\/?p=278","title":{"rendered":"OpenWRT: Compiling libgd in php5-mod-gd with FreeType support"},"content":{"rendered":"<p>If simply activated in menuconfig, default <code>libgd<\/code> compiles without <code>freetype<\/code> support in OpenWRT. This holds true even if you<\/p>\n<ul>\n<li>activate <code>libgd<\/code> and <code>libfreetype<\/code> in <code>menuconfig<\/code> (Libraries section), &#8230;<\/li>\n<li>and activate <code>php5-mod-gd<\/code> in <code>menuconfig<\/code> (Languages \/ PHP section)<\/li>\n<\/ul>\n<p>The following post shows how to compile a complete OpenWRT firmware with <code>libgd<\/code> and <code>php5-mod-gd<\/code> supporting <code>freetype<\/code>.<\/p>\n<p><!--more--><\/p>\n<h2>When lack of freetype support in libgd can be a problem<\/h2>\n<figure id=\"attachment_230\" aria-describedby=\"caption-attachment-230\" style=\"width: 175px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/captcha_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-230\" src=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/captcha_2.png\" alt=\"FSCF generating &quot;background-only&quot; captchas\" width=\"175\" height=\"60\" \/><\/a><figcaption id=\"caption-attachment-230\" class=\"wp-caption-text\">FSCF generating &#8220;background-only&#8221; captchas<\/figcaption><\/figure>\n<p>One example where a <code>libgd<\/code> and <code>php5<\/code> without <code>freetype<\/code> bindings will lead to problems is <strong>captcha generation<\/strong> on an OpenWRT based LAMP-like stack. This happens because the workhorse of all PHP based captcha generators is a third-party code developed by <a href=\"https:\/\/www.phpcaptcha.org\/faq\/#no_captcha_text\" target=\"_blank\">phpcaptcha.org<\/a> &#8211; and that code relies on <code>libgd<\/code> running with <code>freetype<\/code> support on the server. If it is not present, typical captcha plugins like Fast Secure Contact Form or Contact Form 7 will either fail silently (as in the FSCF example) or refuse to start at all informing the user that the <a href=\"https:\/\/wordpress.org\/support\/topic\/captcha-not-working-but-gd-libraries-are-installed-1\" target=\"_blank\">server is lacking support of libgd and freetype<\/a> (CF7) .<\/p>\n<h2>Uneffective solutions offered on the net<\/h2>\n<p>A <a href=\"https:\/\/www.phpcaptcha.org\/faq\/#no_captcha_text\" target=\"_blank\">typical recommendation<\/a> given to those googling for help with the above captcha problem is to &#8230;<\/p>\n<ol>\n<li>Update PHP version from 5.4.3 as this version has a bug that prevents the captcha from being generated correctly.<\/li>\n<li>Set <code>use_transparent_text<\/code> to <code>false<\/code>. In FSCF, this variable is set in <code>si-contact-form\/captcha\/securimage.php<\/code>.<\/li>\n<li>Make sure the path to the folder containing the ttf fonts is correct.<\/li>\n<\/ol>\n<p>Unsurprisingly, neither of these solutions can solve the problem, if <code>libgd<\/code> and PHP&#8217;s gd module are lacking <code>freetype<\/code> support right from the start. The only way ahead is to produce <code>libgd<\/code> and the corresponding <code>php5-mod-gd<\/code> with <code>freetype<\/code> support. Unfortunately, this seems rather complicated as the postings on the OpenWRT board show. But as always with Linux, anything can be done if you only tinker long enough over it. So let&#8217;s give it a shot.<\/p>\n<h1>Complilation walk-through<\/h1>\n<p>We will make the following assumptions for our walk-through:<\/p>\n<ul>\n<li>We clone a fresh OpenWRT source folder into <code>~\/codelab\/owrt3<\/code> so that our root directory for the source code will be <code>~\/codelab\/owrt3\/openwrt<\/code>.<\/li>\n<li>Our target is an <code>x86<\/code> image so that it can be tested on a virtual machine &#8211; in real life though, you would try to compile a router-specific target<\/li>\n<li>The current trunk release on which the compilation was done is <code>OpenWRT Barrier Breaker r44441<\/code>.<\/li>\n<\/ul>\n<h2>Step 1: Get an OpenWRT image<\/h2>\n<p>We are going to start from scratch. So the first thing is to check out the current snapshot from the OpenWRT git repo.<\/p>\n<p>Issue the following command:<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:~\/codelab\/owrt3$ git clone git:\/\/git.openwrt.org\/14.07\/openwrt.git<\/pre>\n<p>The command will download all sources into the folder <code>~\/codelab\/owrt3\/openwrt<\/code>.<\/p>\n<p>After that, change into that directory and update the feeds:<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:~\/codelab\/owrt3\/openwrt$ .\/scripts\/feeds update -a<\/pre>\n<p>Among others, this will download the php language packages. Do <strong>not<\/strong> issue an <code>install<\/code> command yet, as we first need to do some patching before the feeds are transferred into the <code>~\/codelab\/owrt3\/openwrt\/package<\/code> directory (the <code>install<\/code> command essentially copies the whole <code>feeds<\/code> directory to the <code>package<\/code> directory which will then be used for compiling).<\/p>\n<h2>Step 2: Some patch work<\/h2>\n<h3>libgd Makefile<\/h3>\n<p>First, make a copy of the default libgd <code>Makefile<\/code> &#8211; one never knows&#8230;<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:~\/codelab\/owrt3\/openwrt\/feeds\/packages\/libs\/libgd$ cp Makefile Makefile.old<\/pre>\n<p>Then download the <a href=\"https:\/\/hobbykeller.spdns.de\/index.php\/s\/ucjJDBkMrLuMeGM\" target=\"_blank\">following patch<\/a> to your directory and issue the following command to patch the Makefile:<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:~\/codelab\/owrt3\/openwrt\/feeds\/packages\/libs\/libgd$ patch &lt; libgd_makefile.patch<\/pre>\n<p>The patch will add a dependency to <code>libfreetype<\/code> in the <code>DEPENDS<\/code> section and set the &#8211;<code>-with-freetype<\/code> flag with the path to the <code>freetype-config<\/code> file.<\/p>\n<h3>php5 Makefile<\/h3>\n<p>Patching the libgd <code>Makefile<\/code> won&#8217;t be enough, though. You also need to apply a patch to the php5 <code>Makefile<\/code>.<\/p>\n<p>Download the <a href=\"https:\/\/hobbykeller.spdns.de\/index.php\/s\/QfEDBp95LEsoBjw\" target=\"_blank\">php5 patch<\/a> and save it to the <code>~\/codelab\/owrt3\/openwrt\/feeds\/oldpackages\/lang\/php5<\/code> directory. Inside that directory, backup the default <code>Makefile<\/code> to <code>Makefile.old<\/code> again. Then issue the following command:<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:~\/codelab\/owrt3\/openwrt\/feeds\/oldpackages\/lang\/php5$ patch &lt; php5_makefile.patch<\/pre>\n<p>This patch will &#8211; again &#8211; replace the <code>--without-freetype<\/code> flag against the <code>--with-freetype<\/code> flag in the <code>CONFIGURE ARGS<\/code> section and set the path to the <code>freetype-config<\/code> file in the staging directory.<\/p>\n<p>Additionally the patch will extend the <code>BuildModule<\/code> call, adding <code>libbz2<\/code> and <code>libfreetype<\/code> support. This last modification is most often missing with failing patches. I got the idea while reading <a href=\"http:\/\/stackoverflow.com\/questions\/19184631\/package-is-missing-dependencies-for-libraries-openwrt\" target=\"_blank\">this post<\/a> in which someone reported a similar problem.<\/p>\n<h3>\u00a0Install packages<\/h3>\n<p>With all files patched, we are now ready to install the packages for compilation. <code>cd<\/code> to your OpenWRT source root and issue the following command:<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:$ cd ~\/codelab\/owrt3\/openwrt\/\r\nilek@i7:~\/codelab\/owrt3\/openwrt$ .\/scripts\/feeds install -a<\/pre>\n<p>This will basically copy the <code>feeds<\/code> directory with men, mice and patches applied into the <code>package<\/code> directory.<\/p>\n<h2>Step 3: Compile the firmware<\/h2>\n<p>Before we can compile the firmware, we have to run through a make menuconfig. Make sure to select at least <code>libgd<\/code> and <code>libfreetype<\/code>, <code>php5<\/code> and the <code>php5-mod-gd<\/code> module. Additionally, it makes sense to select a web server.<\/p>\n<p>For those keen on a short cut, there is an <a href=\"https:\/\/hobbykeller.spdns.de\/index.php\/s\/vk4LfgvDKqIWUf6\" target=\"_blank\">example config file<\/a> for an <code>x86<\/code> compile. Just download it, copy it to the source root and rename it to <code>.config<\/code>:<\/p>\n<pre class=\"font:droid-sans-mono height-set:true height:250 width-set:true nums:false lang:default decode:true\">ilek@i7:$~\/codelab\/owrt3\/openwrt$ mv x86_sample.config .config\r\nilek@i7:$~\/codelab\/owrt3\/openwrt$ make -j 5<\/pre>\n<h1>Checking the results<\/h1>\n<p>We will check the results by installing the firmware as a virtual machine on VirtualBox and having a WordPress instance with a FSCF run on it.<\/p>\n<h2>gd in phpinfo()<\/h2>\n<p>First thing we check is whether <code>freetype<\/code> support shows up if we call the <code>phpinfo()<\/code> function in some example page. The figure below is a screenshot from the OpenWRT image compiled above. Together with the version and linkage info, it explicitly shows FreeType Support enabled.<\/p>\n<dl id=\"attachment_297\" class=\"wp-caption aligncenter\" style=\"width: 631px;\">\n<dt class=\"wp-caption-dt\"><a href=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/phpinfo_libgd.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-297\" src=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/phpinfo_libgd.jpg\" alt=\"libgd section in phpinfo() with freetype support showing\" width=\"621\" height=\"353\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/phpinfo_libgd.jpg 621w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/phpinfo_libgd-300x171.jpg 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/phpinfo_libgd-500x284.jpg 500w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/a><\/dt>\n<dd class=\"wp-caption-dd\">libgd section in phpinfo() with freetype support showing<\/dd>\n<\/dl>\n<h2>\u00a0Checking a captcha<\/h2>\n<figure id=\"attachment_298\" aria-describedby=\"caption-attachment-298\" style=\"width: 175px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/captcha_working.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-298\" src=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2015\/02\/captcha_working.gif\" alt=\"Working Captcha\" width=\"175\" height=\"60\" \/><\/a><figcaption id=\"caption-attachment-298\" class=\"wp-caption-text\">Working Captcha<\/figcaption><\/figure>\n<p>After a quick install of WordPress, we can download and activate the Fast Secure Contact Form plugin and see if the capture is now generated correctly. As the matter of fact, this is the case as we can already see in the preview of the default form shipped with FSCF after installation.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If simply activated in menuconfig, default libgd compiles without freetype support in OpenWRT. This holds true even if you activate libgd and libfreetype in menuconfig (Libraries section), &#8230; and activate<span class=\"more-button\"><a href=\"https:\/\/hobbykeller.spdns.de\/?p=278\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">OpenWRT: Compiling libgd in php5-mod-gd with FreeType support<\/span><\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[36,41,17],"class_list":["post-278","post","type-post","status-publish","format-standard","hentry","category-openwrt","tag-freetype","tag-libgd","tag-openwrt"],"_links":{"self":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=278"}],"version-history":[{"count":25,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/278\/revisions"}],"predecessor-version":[{"id":1096,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/278\/revisions\/1096"}],"wp:attachment":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}