<?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>Marco Pracucci &#187; PHP</title>
	<atom:link href="http://blog.pracucci.com/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pracucci.com</link>
	<description>Marco Pracucci - Technology news and blog</description>
	<lastBuildDate>Thu, 25 Feb 2010 12:39:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend Framework and Session Cookies across Subdomains</title>
		<link>http://blog.pracucci.com/2008/09/24/zend-framework-and-session-cookies-across-subdomains/</link>
		<comments>http://blog.pracucci.com/2008/09/24/zend-framework-and-session-cookies-across-subdomains/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 17:00:06 +0000</pubDate>
		<dc:creator>Marco Pracucci</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[subdomain]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.pracucci.com/2008/09/24/zend-framework-and-session-cookies-across-subdomains/</guid>
		<description><![CDATA[Session support in PHP consists of a way to preserve certain data    across subsequent accesses. Each visitor accessing the web site is assigned a unique id, the    session id. This session id is either stored in a cookie or propagated in the url. The best solution is to store [...]]]></description>
			<content:encoded><![CDATA[<p>Session support in PHP consists of a way to preserve certain data    across subsequent accesses. Each visitor accessing the web site is assigned a unique id, the    <strong>session id</strong>. This session id is either stored in a <strong>cookie</strong> or propagated in the url. The best solution is to store it in a cookie.</p>
<p>The cookie used to store the session id sets, by default, the cookie domain to the current domain. This means that if you are visiting www.domain.com, the session id will be stored in a cookie bounded to the domain www.domain.com. This behavior leads to a problem: if your site uses multiple subdomains, the session won&#8217;t be shared between the site&#8217;s subdomains.</p>
<p>To solve this problem you have to share the cookie between all subdomains, setting its domain it to &#8220;.domain.com&#8221;. The following code shows how to change the session cookie domain with <strong>Zend Framework</strong>:</p>
<pre class="prettyprint">
Zend_Session::start(array('cookie_domain' =&gt; '.domain.com'));</pre>
<h3>Browers compatibility</h3>
<p>The prefix dot in &#8220;.domain.com&#8221; is not always necessary, but it&#8217;s <strong>highly recommended</strong> to support all browsers.</p>
<h3>References</h3>
<ul>
<li><a href="http://www.jontodd.com/2006/08/10/php-session-cookie-multiple-domains/" title="PHP session cookie multiple domains" target="_blank">PHP session cookie multiple domains</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.pracucci.com/2008/09/24/zend-framework-and-session-cookies-across-subdomains/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Watermarks with PHP and IMagick</title>
		<link>http://blog.pracucci.com/2008/08/30/watermarks-with-php-and-imagick/</link>
		<comments>http://blog.pracucci.com/2008/08/30/watermarks-with-php-and-imagick/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 16:52:10 +0000</pubDate>
		<dc:creator>Marco Pracucci</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[watermark]]></category>

		<guid isPermaLink="false">http://blog.pracucci.com/2008/08/30/automatic-selection-of-the-best-image-corner-where-apply-a-watermark-with-php-and-imagick/</guid>
		<description><![CDATA[There are a lot of web sites, online communities and social networks that apply a watermark over photos uploaded from users. This watermark, usually a logo or a text with the service name, should be applied in a region of the image where there are no important things, because no one likes to see a [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of web sites, online communities and social networks that apply a <strong>watermark over photos uploaded from users</strong>. This watermark, usually a logo or a text with the service name, should be applied in a region of the image where there are no important things, because no one likes to see a text over his face.</p>
<p>This simple feature requires an algorithm to automatically select the best corner where apply the watermark.</p>
<h3>The algorithm</h3>
<p>The watermark should be placed in the corner with the lowest number of graphic details, in order to be as less invasive as possible. To select the best corner, the proposed algorithm <strong>counts the number of different colours inside each corner</strong> and applies the watermark to the <strong>corner with the lowest number of different colours</strong>.</p>
<p>This algorithm is very simple but effective, and can be described with the following steps:</p>
<ol>
<li>For each candidate image region (corners) calculate the number of different colours</li>
<li>Select the image region with the lowest number of different colours</li>
<li>Apply the watermark to the selected region</li>
</ol>
<h3>The code</h3>
<p>Here is the code the <strong>PHP</strong> code of a function that selects the best corner of an image and then apply the watermark.</p>
<pre class="prettyprint">
/**
 * Draw a watermark over an image (the watermark position is
 * selected automatically) and returns true. If the watermark
 * is bigger than the image, this method returns false.
 *
 * @param IMagick $image
 * @param IMagick $watermark
 * @param int $padding
 * @return bool
 */
private function drawWatermark($image, $watermark, $padding = 0)
{
	// Check if the watermark is bigger than the image
	$image_width 		= $image-&gt;getImageWidth();
	$image_height 		= $image-&gt;getImageHeight();
	$watermark_width 	= $watermark-&gt;getImageWidth();
	$watermark_height 	= $watermark-&gt;getImageHeight();

	if ($image_width &lt; $watermark_width + $padding || $image_height &lt; $watermark_height + $padding) {
		return false;
	}

	// Calculate each position
	$positions = array();
	$positions[] = array(0 + $padding, 0 + $padding);
	$positions[] = array($image_width - $watermark_width - $padding, 0 + $padding);
	$positions[] = array($image_width - $watermark_width - $padding, $image_height - $watermark_height - $padding);
	$positions[] = array(0 + $padding, $image_height - $watermark_height - $padding);

	// Initialization
	$min 		= null;
	$min_colors = 0;

	// Calculate the number of colors inside each region
	// and retrieve the minimum
	foreach($positions as $position)
	{
		$colors = $image-&gt;getImageRegion(
			$watermark_width,
			$watermark_height,
			$position[0],
			$position[1])-&gt;getImageColors();

		if ($min === null || $colors &lt;= $min_colors)
		{
			$min 		= $position;
			$min_colors = $colors;
		}
	}

	// Draw the watermark
	$image-&gt;compositeImage(
		$watermark,
		Imagick::COMPOSITE_OVER,
		$min[0],
		$min[1]);

	return true;
}</pre>
<p><span id="more-104"></span></p>
<h3>Testing the algorithm</h3>
<p>I have taken three photos from <a href="http://www.tonight.eu" title="Tonight - European nightlife social network" target="_blank">www.tonight.eu</a> and tried to apply the watermark, using the proposed algorithm. For each photo there are two images:</p>
<ol>
<li>the first one shows the number of different colours in each candidate region</li>
<li>the second one shows the photo after the watermark has been applied.</li>
</ol>
<p>The results are quite good.</p>
<p><a href="http://milano.tonight.eu/locale/old_fashion_cafe" title="Milano tonight - Old fashion cafe" target="_blank"><img src="http://blog.pracucci.com/wp-content/uploads/2008/08/1a.jpg" alt="1a.jpg" /></a></p>
<p><a href="http://milano.tonight.eu/locale/old_fashion_cafe" title="Milano tonight - Old fashion cafe" target="_blank"><img src="http://blog.pracucci.com/wp-content/uploads/2008/08/1b.jpg" alt="1b.jpg" /></a></p>
<p><a href="http://milano.tonight.eu/locale/nottingham_forest" title="Milano tonight - Nottingham forest" target="_blank"><img src="http://blog.pracucci.com/wp-content/uploads/2008/08/2a.jpg" alt="2a.jpg" /></a></p>
<p><a href="http://milano.tonight.eu/locale/nottingham_forest" title="Milano tonight - Nottingham forest" target="_blank"><img src="http://blog.pracucci.com/wp-content/uploads/2008/08/2b.jpg" alt="2b.jpg" /></a></p>
<p><a href="http://milano.tonight.eu/locale/plastic" title="Milano tonight - Plastic" target="_blank"><img src="http://blog.pracucci.com/wp-content/uploads/2008/08/3a.jpg" alt="3a.jpg" /></a></p>
<p><a href="http://milano.tonight.eu/locale/plastic" title="Milano tonight - Plastic" target="_blank"><img src="http://blog.pracucci.com/wp-content/uploads/2008/08/3b.jpg" alt="3b.jpg" /></a></p>
<h3>Feedback</h3>
<p>Please, give me a feedback and leave a comment to this post.</p>
<h3>References</h3>
<ul>
<li><a href="http://www.php.net/manual/en/book.imagick.php" target="_blank" title="IMagick">IMagick </a></li>
<li><a href="http://www.tonight.eu" title="Tonight - European nightlife social network" target="_blank">Tonight.eu</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.pracucci.com/2008/08/30/watermarks-with-php-and-imagick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Archive_Tar 1.3.2 &#8211; Gzip/bzip2 bug fix</title>
		<link>http://blog.pracucci.com/2008/03/25/archive_tar-132-gzipbzip2-bug-fix/</link>
		<comments>http://blog.pracucci.com/2008/03/25/archive_tar-132-gzipbzip2-bug-fix/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 15:57:08 +0000</pubDate>
		<dc:creator>Marco Pracucci</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[archive_tar]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[fix]]></category>

		<guid isPermaLink="false">http://blog.pracucci.com/2008/03/25/archive_tar-132-gzipbzip2-bug-fix/</guid>
		<description><![CDATA[Ho trovato un bug nella classe Archive_Tar che si verifica quando si prova ad aggiungere ad un archivio compresso (gzip o bzip2) un file che, al suo interno, contiene il blocco utilizzato per delimitare la fine dell&#8217;archivio tar stesso (null padding di 1024 byte).
Questa patch, applicata alla versione 1.3.2 di Archive_Tar, dovrebbe risolvere il problema.
Riferimenti

PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Ho trovato un bug nella classe <strong>Archive_Tar</strong> che si verifica quando si prova ad aggiungere ad un archivio compresso (gzip o bzip2) un file che, al suo interno, contiene il blocco utilizzato per delimitare la fine dell&#8217;archivio tar stesso (null padding di 1024 byte).</p>
<p>Questa <a href="http://download.pracucci.com/php/archive_tar-1.3.2-end_block_fix.diff">patch</a>, applicata alla versione 1.3.2 di Archive_Tar, dovrebbe risolvere il problema.</p>
<h3>Riferimenti</h3>
<ul>
<li><a href="http://pear.php.net/package/Archive_Tar">PHP &#8211; Archive_Tar</a></li>
<li><a href="http://download.pracucci.com/php/archive_tar-1.3.2-end_block_fix.diff">Patch</a></li>
<li><a href="http://en.wikipedia.org/wiki/Tar_(file_format)" title="Tar file format">Formato tar</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.pracucci.com/2008/03/25/archive_tar-132-gzipbzip2-bug-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
