<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LAMP with ·dotmanila &#187; PHP</title>
	<atom:link href="http://dotmanila.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotmanila.com/blog</link>
	<description>Linux, Apache, PHP, MySQL Musings</description>
	<lastBuildDate>Sun, 01 Apr 2012 17:24:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Where&#8217;s My PHP Debug Symbols?</title>
		<link>http://dotmanila.com/blog/2012/01/wheres-php-debug-symbols/</link>
		<comments>http://dotmanila.com/blog/2012/01/wheres-php-debug-symbols/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 13:52:19 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=258</guid>
		<description><![CDATA[While working on a PHP script recently when I stumble upon a nasty bug that leaves only a &#8220;Segmentation fault&#8221; while preparing statements with Zend_Db_Adapter_Mysqli. Attempting to gdb the same process only results in gibberish like below and nothing more. The problem is that, the PHP cli is a stripped binary and on CentOS (and [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a PHP script recently when I stumble upon a <a href="https://bugs.php.net/bug.php?id=55414">nasty bug</a> that leaves only a &#8220;Segmentation fault&#8221; while preparing statements with Zend_Db_Adapter_Mysqli. Attempting to gdb the same process only results in gibberish like below and nothing more. The problem is that, the PHP cli is a stripped binary and on CentOS (and Fedora 14 at least with PHP 5.3.8) there is no debuginfo package to provide these symbols, you&#8217;ll have to compile PHP yourself to debug further.</p>
<p><code><br />
#19635 0x000000000046b13b in ?? ()<br />
#19636 0x000000000046b231 in ?? ()<br />
#19637 0x000000000046b13b in ?? ()<br />
#19638 0x000000000046b231 in ?? ()<br />
#19639 0x000000000046cb3f in ?? ()<br />
#19640 0x000000000047c76f in php_pcre_exec ()<br />
#19641 0x0000000000480d46 in php_pcre_replace_impl ()<br />
---Type to continue, or q to quit---<br />
#19642 0x0000000000481f0d in ?? ()<br />
#19643 0x0000000000482504 in ?? ()<br />
#19644 0x0000000000482a33 in ?? ()<br />
#19645 0x00000000005e8f19 in ?? ()<br />
#19646 0x00000000005e847b in execute ()<br />
#19647 0x00000000005c1395 in zend_execute_scripts ()<br />
#19648 0x0000000000571418 in php_execute_script ()<br />
#19649 0x000000000064b5a0 in ?? ()<br />
#19650 0x000000314821d994 in __libc_start_main () from /lib64/libc.so.6<br />
#19651 0x00000000004222b9 in _start ()<br />
</code></p>
<p>My appeal to the PHP package builders (CentOS/Fedora mainstream, RPMForge, Atomic) &#8211; please please please &#8211; include a debuginfo package on your repo <img src='http://dotmanila.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2012/01/wheres-php-debug-symbols/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internal Server Error (500) From Your PHP Application</title>
		<link>http://dotmanila.com/blog/2010/07/internal-server-error-500-from-your-php-application/</link>
		<comments>http://dotmanila.com/blog/2010/07/internal-server-error-500-from-your-php-application/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 03:29:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[http 500]]></category>
		<category><![CDATA[internal server error]]></category>
		<category><![CDATA[virtual server]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=136</guid>
		<description><![CDATA[virtual server, php, php-ldap, internal server error, http 500]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a script on a fresh virtual server. The script was pulled from a production server and was being actively used. When I try to run it on the test server, it was mysteriously not working, Apache access_log shows 500 HTTP response code, PHP <strong>log_errors</strong> is <strong>ON</strong>,even <strong>display_errors</strong> is set to <strong>ON</strong> but there were no errors being displayed or logged. Thoroughly deducing my .htaccess, Apache virtual host configuration and doing a sanity check on the application itself, the mysterious error was being caused by one PHP extension missing, in this case <strong>php-ldap</strong>.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">/var/www/sites/mediaweb</div>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2010/07/internal-server-error-500-from-your-php-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Validate_StringEquals</title>
		<link>http://dotmanila.com/blog/2010/01/zend_validate_stringequals/</link>
		<comments>http://dotmanila.com/blog/2010/01/zend_validate_stringequals/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 14:54:23 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Application Security]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>
		<category><![CDATA[Zend_Input_Filter]]></category>
		<category><![CDATA[Zend_Validate]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=121</guid>
		<description><![CDATA[If you ever wonder where that &#8216;StringEquals&#8217; validator rule taken as example from the Zend_Filter_Input documentation page results in an error like below, well read again. It was clearly stated as &#8216;hypothetical&#8217;. Plugin by name &#8216;StringEquals&#8217; was not found in the registry; used paths: Zend_Validate_: Zend/Validate/ Given such validator would be useful on a number [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever wonder where that &#8216;StringEquals&#8217; validator rule taken as example from the Zend_Filter_Input documentation page results in an error like below, well read again. It was clearly stated as &#8216;hypothetical&#8217;.</p>
<blockquote>
<h3>Plugin by name &#8216;StringEquals&#8217; was not found in the registry; used paths: Zend_Validate_: Zend/Validate/</h3>
</blockquote>
<p>Given such validator would be useful on a number of situations i.e. confirming passwords, emails, etc. I present to you my own version of the class.</p>
<pre class="brush: php;ruler: true;">
&lt;?php
"%field1% and %field2% are not equal.",
        self::MISSING	=&gt; "One or both strings are missing."
    );

    /**
     * @var array
     */
    protected $_messageVariables = array(
        'field1' =&gt; '_field1',
        'field2' =&gt; '_field2'
    );

    protected $_case = false;
    protected $_field1 = null;
    protected $_field2 = null;

    /**
     * Sets validator options
     *
     * @param  boolean $case
     * @return void
     */
    public function __construct($case = false)
    {
        $this-&gt;_case = $case;
    }

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if the the 2 strings are equal
     *
     * @param  array $value
     * @return boolean
     */
    public function isValid($value)
    {
    	if(!is_array($value) OR sizeof($value) &lt; 2) {
			$this-&gt;_error(self::MISSING);
    	}

    	$this-&gt;_field1 = array_shift($value);
    	$this-&gt;_field2 = array_shift($value);

        if($this-&gt;_case === true) $function = 'strcmp';
        else $function = 'strcasecmp';

        if(0 !== $function($this-&gt;_field1,$this-&gt;_field2)) $this-&gt;_error(self::NOT_EQUAL);

        if (count($this-&gt;_messages)) {
            return false;
        } else {
            return true;
        }
    }
}
?&gt;</pre>
<p>Here is a sample test case. Validate password and confirm password elements represented by &#8216;password&#8217; and &#8216;cpassword&#8217; element names respectively.</p>
<pre class="brush: php">$filters = array('password' =&gt; 'StringTrim', 'cpassword' =&gt; 'StringTrim');
$validators = array(
    'Password' =&gt; array(
        'presence' =&gt; 'required',
        array('StringLength',5,15),
        'fields' =&gt; 'password',
        'messages' =&gt; "Passwords must be between 5 and 15 characters in length."),
    'Confirm password' =&gt; array(
        array('StringEquals'),
        'fields' =&gt; array('password','cpassword'),
        'messages' =&gt; array(
            0 =&gt; array(
                Zend_Validate_StringEquals::NOT_EQUAL =&gt; "Passwords does not match.",
                Zend_Validate_StringEquals::MISSING =&gt; "Both password fields must be filled."))));

$inputdata = new Zend_Filter_Input($filter,$validators,$_POST,$options);</pre>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2010/01/zend_validate_stringequals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FFMpeg-PHP: undefined symbol: php_gd_gdImageSetPixel</title>
		<link>http://dotmanila.com/blog/2009/10/ffmpeg-php-undefined-symbol-php_gd_gdimagesetpixel-86/</link>
		<comments>http://dotmanila.com/blog/2009/10/ffmpeg-php-undefined-symbol-php_gd_gdimagesetpixel-86/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 15:01:32 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[ffmpeg-php]]></category>
		<category><![CDATA[php-gd]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=86</guid>
		<description><![CDATA[I was recently updating ffmpeg-php on one of our servers to the latest SVN release  of the 0.6.3 branch. On a 64bit CentOS 5.3 with PHP 5.2.11, the extension compiled and installed fine however Apache will not load it and spit out the error below: PHP Warning:  PHP Startup: Unable to load dynamic library &#8216;/usr/lib64/php/modules/ffmpeg.so&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently updating ffmpeg-php on one of our servers to the latest SVN release  of the 0.6.3 branch. On a 64bit CentOS 5.3 with PHP 5.2.11, the extension compiled and installed fine however Apache will not load it and spit out the error below:</p>
<blockquote><p>PHP Warning:  PHP Startup: Unable to load dynamic library &#8216;/usr/lib64/php/modules/ffmpeg.so&#8217; &#8211; /usr/lib64/php/modules/ffmpeg.so: undefined symbol: php_gd_gdImageSetPixel in Unknown on line 0</p></blockquote>
<p>Surely enough, the GD extension was there, but why is ffmpeg complaining about not finding that shared symbol? Because, ffmpeg is loading first than GD (alphabetically) and such symbol has not been loaded. After adding the GD extension line on top of ffmpeg making sure it loads first the error went away and all is well again.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/10/ffmpeg-php-undefined-symbol-php_gd_gdimagesetpixel-86/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Do you favor a &#8220;LAMP (Linux, Apache, PHP, MySQL) Integrator&#8221;?</title>
		<link>http://dotmanila.com/blog/2009/08/do-you-favor-a-lamp-linux-apache-php-mysql-integrator/</link>
		<comments>http://dotmanila.com/blog/2009/08/do-you-favor-a-lamp-linux-apache-php-mysql-integrator/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 03:41:16 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Certifications]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache tuning]]></category>
		<category><![CDATA[LAMP Integrator]]></category>
		<category><![CDATA[linux administrator]]></category>
		<category><![CDATA[mysql administrator]]></category>
		<category><![CDATA[php developer]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=75</guid>
		<description><![CDATA[I have been reading on a number of project management articles lately and trends on open source projects. There seems to be a lot of fellow PHP developers who are as well Linux administrators for many server functions inluding HTTP servers like Apache and database administrators like for MySQL. Many of them are certified for [...]]]></description>
			<content:encoded><![CDATA[<p>I have been reading on a number of project management articles lately and trends on open source projects. There seems to be a lot of fellow PHP developers who are as well Linux administrators for many server functions inluding HTTP servers like Apache and database administrators like for MySQL. Many of them are certified for one or more while many are jumping between careers that emphasizes one to the other thus gaining essential experiences for each.</p>
<p>Looking at job posts from all over the internet, you should&#8217;ve noticed at one time a PHP gig that requires MySQL administration skills and/or knows their way around Linux. PHP does not come by itself anymore, at least commonly, thus I&#8217;ve thought the term &#8220;LAMP Integrator&#8221;.  A quick Google search does not seem to turn much on how to define such, thus I have a simple one.</p>
<blockquote><p><strong>LAMP Integrator</strong> &#8211; is a PHP developer primarily using MySQL as data backend with strong Linux administration and Apache tuning skills.</p></blockquote>
<p>It may sound primitive, I am writing as I am thinking so comments and revisions are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/08/do-you-favor-a-lamp-linux-apache-php-mysql-integrator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gumblar .cn &#8211; Infiltrating Hosting Accounts</title>
		<link>http://dotmanila.com/blog/2009/05/gumblar-cn-infiltrating-hosting-accounts/</link>
		<comments>http://dotmanila.com/blog/2009/05/gumblar-cn-infiltrating-hosting-accounts/#comments</comments>
		<pubDate>Wed, 20 May 2009 11:46:15 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Security]]></category>
		<category><![CDATA[ftp trojan]]></category>
		<category><![CDATA[gumblar]]></category>
		<category><![CDATA[hosting malware]]></category>
		<category><![CDATA[php hijacking]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=52</guid>
		<description><![CDATA[Hosting accounts being compromised has been a common incident, however a sudden surge of this variant is quite alarming. This trojan does not target any particular software or script and is commonly exploited from a users computer where he usually FTP files to hosting accounts. The trojan scans for FTP usernames and passwords and use [...]]]></description>
			<content:encoded><![CDATA[<p>Hosting accounts being compromised has been a common incident, however a sudden surge of this variant is quite alarming. This trojan does not target any particular software or script and is commonly exploited from a users computer where he usually FTP files to hosting accounts. The trojan scans for FTP usernames and passwords and use them to inject PHP scripts to the FTP server.</p>
<p>So far I have seen two variations, one being a slave for XSS attack and another as proxy or zombie perhaps for a DoS attack.</p>
<p>What to do or how do you know if you are infected? There is no simple prevention measure I can offer aside from asking you to scan and thoroughly clean your computer first. Download all your files from the ftp server, you can do PHP files only, however there is a probability a JS based file may exist as well. After downloading, scan all your files and reupload. Not too neat but it&#8217;s the only method that works for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/05/gumblar-cn-infiltrating-hosting-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloak PHP Files as Directories and Force Trailing Slash via mod_rewrite</title>
		<link>http://dotmanila.com/blog/2009/05/cloak-php-files-as-directories-and-force-trailing-slash-via-mod_rewrite/</link>
		<comments>http://dotmanila.com/blog/2009/05/cloak-php-files-as-directories-and-force-trailing-slash-via-mod_rewrite/#comments</comments>
		<pubDate>Wed, 06 May 2009 11:43:51 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[force trailing slash]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[php cloaking]]></category>
		<category><![CDATA[Search Engine Optimization]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=50</guid>
		<description><![CDATA[In an effort to turn a client's website to be more SEO friendly, they wanted to have all PHP files appear as directories on URLs i.e. http://dotmanila.com/blog/php-cloak-and-force-traling-slash.php will end up as http://dotmanila.com/blog/php-cloak-and-force-traling-slash/. We've thought of creating a simple controller combined with mod_rewrite to handle this change on their 30+ websites, however it'll be inefficient to use a two-fold process. So we toyed with mod_rewrite and came up below.]]></description>
			<content:encoded><![CDATA[<p>In an effort to turn a client&#8217;s website to be more SEO friendly, they wanted to have all PHP files appear as directories on URLs i.e. http://dotmanila.com/blog/php-cloak-and-force-traling-slash.php will end up as http://dotmanila.com/blog/php-cloak-and-force-traling-slash/. We&#8217;ve thought of creating a simple controller combined with mod_rewrite to handle this change on their 30+ websites, however it&#8217;ll be inefficient to use a two-fold process. So we toyed with mod_rewrite and came up below.</p>
<pre class="brush: text; ruler: true;">
Options +FollowSymLinks
RewriteEngine On

RewriteBase /

# These first set of rules makes sure that visitors
# are viewing the WWW domain i.e. www.dotmanila.com
Rewritecond %{HTTP_HOST} !^www\.dotmanila\.com
RewriteRule (.*) http://www.dotmanila.com/$1/ [R=301,L]

# The next set of rules checks that if the URL
# does not have a trailing slash and
# the requested file/directory when appended
# with the .php extension physically exist on the server
# the we will append a traling slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.dotmanila.com/$1/ [L,R=301]

# The last set of rules makes sure that if
# the requested URL is in proper format the
# corresponding PHP file is mapped.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/$ /$1.php [NS,L]</pre>
</pre>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/05/cloak-php-files-as-directories-and-force-trailing-slash-via-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fetch Smarty Templates From MySQL Database</title>
		<link>http://dotmanila.com/blog/2009/03/fetch-smarty-templates-from-mysql-database/</link>
		<comments>http://dotmanila.com/blog/2009/03/fetch-smarty-templates-from-mysql-database/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 11:40:57 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php smarty]]></category>
		<category><![CDATA[smarty mysql]]></category>
		<category><![CDATA[templates database]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=48</guid>
		<description><![CDATA[I was recently working on a mailing application. With the nature of the bulk mailing routine, it was designed to store templates made by its users and email designers. Since most of them have been exposed to Smarty templating before we decided to base our email template parsing to Smarty.]]></description>
			<content:encoded><![CDATA[<p>I was recently working on a mailing application. With the nature of the bulk mailing routine, it was designed to store templates made by its users and email designers. Since most of them have been exposed to Smarty templating before we decided to base our email template parsing to Smarty.</p>
<p>Smarty does not come with the ability to parse templates from database natively, but it is easy to extend it to do just that.</p>
<p>DISCLAIMER: This is a quick and dirty hack I provided with my colleagues. Improvement required!</p>
<p>This approach should work on both PHP 4 and PHP 5, since Smarty.class.php is written on PHP 4.</p>
<p>What we will need to do is extend Smarty.class.php on a new class and override function <code>_fetch_resource_info</code> and replace the <code>if</code> clause demonstrated below to use our code that actually fetches database stored templates.</p>
<pre>
class Smarty
{
    function _fetch_resource_info(&amp;$params) {
        ....
        if ($this->_parse_resource_name($_params)) {
            .....
        }
        ....
    }
}
</pre>
<p>Our resulting class would look something like:</p>
<pre>
require_once 'Smarty.class.php';

class Smarty_Db extends Smarty
{
    function _fetch_resource_info(&amp;$params) {
        ....
        $_resource_type = $_params['resource_type'];
        $_resource_name = $_params['resource_name'];

	$db = new Template_Db;
	if ($params['get_source']) {
            $params['source_content'] = $db->fetchTemplate($myTemplateId);
        }
	$params['resource_timestamp'] = now();
        $_return = true;
        ....
    }
}
</pre>
<p>So you would then use your Smarty extended class like:</p>
<pre>
$smarty = new Smarty_Db;
$smarty->compile_dir = '/path/to/my/compile/dir';

$compiledTemplateFromDb = $smarty->fetch($myTemplateId);
</pre>
<p>That is all there is to it actually. I haven&#8217;t went through all the Smarty pre and post processing, but this should suffice the requirements for now.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/03/fetch-smarty-templates-from-mysql-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Image Resize with PHP and ImageMagick Maintaining Proportions</title>
		<link>http://dotmanila.com/blog/2009/02/image-resize-with-php-and-imagemagick-maintaining-proportions/</link>
		<comments>http://dotmanila.com/blog/2009/02/image-resize-with-php-and-imagemagick-maintaining-proportions/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 11:39:33 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[imagemagick resize]]></category>
		<category><![CDATA[php image resize]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=46</guid>
		<description><![CDATA[There are many examples found on the web on resizing images using PHP while maintaining aspect ratio. However most of them are based on a single maximum dimension i.e. should not exceed a certain size with on either height or width.]]></description>
			<content:encoded><![CDATA[<p>There are many examples found on the web on resizing images using PHP while maintaining aspect ratio. However most of them are based on a single maximum dimension i.e. should not exceed a certain size with on either height or width.</p>
<p>I have written the code below that will accept a desired height and width and downsize the source image without exceeding either <code>$maxheight</code> or <code>$maxwidth</code> but still maintain proportions.</p>
<p>Adjust your path to ImageMagick accordingly (<code>/usr/bin/convert</code>)</p>
<pre>
function resizeimage($source,$dest,
	$maxwidth = 200,$maxheight = 160)
{
	list($width,$height) = getimagesize($source);

	/**
	 * We need to get both ratios so we can
	 * find which reduced height and width
	 * will fix the max allowed dimensions.
	 */
	$hRatio = $maxheight / $height;
	$wRatio = $maxwidth / $width;

	/**
	 * Test Dimensions based on height reduction ratio.
	 */
	$tHeightHR = $maxheight;
	$tWidthHR = ceil($hRatio * $width);

	/**
	 * Test dimenstions based on width reduction ratio.
	 */
	$tWidthWR = $maxwidth;
	$tHeightWR = ceil($wRatio * $height);

	if($width < $maxwidth AND $height < $maxheight)
	{
		echo 'Source already below maximum dimensions: '
			. $source . " {$width}x{$height}\n";
		return false;
	}

	if($tWidthHR <= $maxwidth) {
		$height = $tHeightHR; $width = $tWidthHR;
	}
	if($tHeightWR <= $maxheight) {
		$height = $tHeightWR; $width = $tWidthWR;
	}

	$cmd = "/usr/bin/convert -resize {$width}x{$height} "
		. "\"{$source}\" \"{$dest}\" 2>&amp;1";
	@exec($cmd,$output,$retvar);

	if($retvar != 0)
	{
		echo implode(" -- ",$output);
		return false;
	}

	return true;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/02/image-resize-with-php-and-imagemagick-maintaining-proportions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Face Detection with PHP</title>
		<link>http://dotmanila.com/blog/2009/01/face-detection-with-php/</link>
		<comments>http://dotmanila.com/blog/2009/01/face-detection-with-php/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 11:34:30 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php face detection]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=40</guid>
		<description><![CDATA[I was enjoying playing photofunia.com a while ago when I got interested on how I can implement such a thing with opensource tools, specifically LAMP. In less than a minute, with "php face detection" on Google I found this.]]></description>
			<content:encoded><![CDATA[<p>I was enjoying playing photofunia.com a while ago when I got interested on how I can implement such a thing with opensource tools, specifically LAMP. In less than a minute, with &#8220;php face detection&#8221; on Google I found this.</p>
<blockquote><p>The headline does say face detection &#8211; but what does this mean? Easy said, this article focus on how to find faces on images with PHP. Faces have a certain form and so it is possible to search for it. At the end of the search you will say how many human faces are on the image or better: Where are human faces on my image. This article is not intended to be mathematically.</p>
<p>Intel works on the OpenCV library to search for structures on images. The library is shipped with training files, what was trained with hundrets of photos to detect faces from different perspectives on images and so we can focus on the PHP part.</p></blockquote>
<p><a href="http://www.xarg.org/2008/07/face-detection-with-php/" target="_blank">http://www.xarg.org/2008/07/face-detection-with-php/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/01/face-detection-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

