<?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>Mikko's blog</title>
	<atom:link href="http://valokuva.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://valokuva.org</link>
	<description>My Thoughts Exactly</description>
	<lastBuildDate>Sat, 19 Sep 2009 12:07:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Imagick and Gmagick builds available for Windows</title>
		<link>http://valokuva.org/?p=161</link>
		<comments>http://valokuva.org/?p=161#comments</comments>
		<pubDate>Sat, 19 Sep 2009 03:23:42 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=161</guid>
		<description><![CDATA[The new Windows build page http://valokuva.org/magick/ contains builds for both Imagick and Gmagick. All builds are done using VC9 and PHP 5.3. ImageMagick builds are QuantumDepth 16 (default). GraphicsMagick builds are QuantumDepth 8 (default). Please note that these builds won&#8217;t work with the official PHP.net binaries which are compiled using VC6. Edit: Pierre corrected me [...]]]></description>
			<content:encoded><![CDATA[<p>The new Windows build page <a href="http://valokuva.org/magick/">http://valokuva.org/magick/</a> contains builds for both Imagick and Gmagick. All builds are done using VC9 and PHP 5.3.</p>
<p>ImageMagick builds are QuantumDepth 16 (default).<br />
GraphicsMagick builds are QuantumDepth 8 (default).</p>
<p>Please note that these builds won&#8217;t work with the official PHP.net binaries which are compiled using VC6.</p>
<p><strong>Edit: </strong> Pierre corrected me that there are official VC9 builds of PHP available at <a href="http://windows.php.net/download/" onclick="urchinTracker('/outgoing/windows.php.net/download/?referer=');">http://windows.php.net/download/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=161</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>New and old extensions</title>
		<link>http://valokuva.org/?p=153</link>
		<comments>http://valokuva.org/?p=153#comments</comments>
		<pubDate>Sat, 12 Sep 2009 01:58:50 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Everything else]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=153</guid>
		<description><![CDATA[I&#8217;ve been fairly busy lately writing a few new PHP extensions. Here is a short introduction of each one of them and what they can do: 1. tokyo_tyrant This is an extension to connect to the Tokyo Tyrant key value store. It supports the normal key value API and the table API. The feature-set should [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been fairly busy lately writing a few new PHP extensions. Here is a short introduction of each one of them and what they can do:</p>
<p>1. <a href="http://php.net/tokyo_tyrant" onclick="urchinTracker('/outgoing/php.net/tokyo_tyrant?referer=');">tokyo_tyrant</a></p>
<p>This is an extension to connect to the Tokyo Tyrant key value store. It supports the normal key value API and the table API. The feature-set should match quite closely what Tokyo Tyrant client libraries expose. The first version of this extension has been released in PECL.</p>
<p>2. <a href="http://github.com/mkoppanen/php-zbarcode/tree/master" onclick="urchinTracker('/outgoing/github.com/mkoppanen/php-zbarcode/tree/master?referer=');">zbarcode</a></p>
<p>This is the latest extension under works: it wraps ImageMagick and ZBar libraries and provides an OO API for scanning barcodes from images. It is currently under heavy development but hopefully it will be in PECL later on.</p>
<p>3. <a href="http://github.com/mkoppanen/php-dmtx/tree/master" onclick="urchinTracker('/outgoing/github.com/mkoppanen/php-dmtx/tree/master?referer=');">dmtx</a></p>
<p>Another barcode extension. Reads and writes data matrices (2D barcode). The API would need some refactoring but it seems to be working fine as it is.</p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=153</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hardware failure</title>
		<link>http://valokuva.org/?p=150</link>
		<comments>http://valokuva.org/?p=150#comments</comments>
		<pubDate>Sat, 12 Sep 2009 01:52:13 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Everything else]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=150</guid>
		<description><![CDATA[Hi, my blog has been down for about the last week now because of problems with the server hardware. I am trying to provision new hardware and restore the service back to normal as soon as possible. Currently things are running from a backup VPS so the site might be a bit slow from time [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>my blog has been down for about the last week now because of problems with the server hardware. I am trying to provision new hardware and restore the service back to normal as soon as possible. Currently things are running from a backup VPS so the site might be a bit slow from time to time.</p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=150</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fake uploading files</title>
		<link>http://valokuva.org/?p=132</link>
		<comments>http://valokuva.org/?p=132#comments</comments>
		<pubDate>Thu, 05 Mar 2009 15:18:18 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=132</guid>
		<description><![CDATA[Fake uploading files A few days ago I encountered a problem where I needed to test a controller that handles file uploads. I couldn't find an easy way to unit test the code which used built-in uploading functionality so I decided to whip up this simple extension that allows to fake file uploads. The extension [...]]]></description>
			<content:encoded><![CDATA[<p>Fake uploading files</p>
<p>A few days ago I encountered a problem where I needed to test a controller that handles file uploads. I couldn't find an easy way to unit test the code which used built-in uploading functionality so I decided to whip up this simple extension that allows to fake file uploads. </p>
<p>The extension is doing things that shouldn't be done, it probably doesn't even run anywhere else than on CLI, it is insecure, it might behave incorrectly but in this scenario it worked fine so I decided to share it. Don't ask for support or any updates for this extension and use it on your own risk. I take no responsibility of anything (especially related to this extension).</p>
<p>The following example code <b>might</b> work with the extension:</p>
<div class="igBar"><span id="lphp-3"><a href="#" onclick="javascript:showCodeTxt('php-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-3">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fakeupload_file<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"userFile"</span>, <span style="color:#FF0000;">'/Users/test/test.txt'</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">"/tmp/upload.tmp"</span>, <span style="color:#FF0000;">"text/plain"</span>, <span style="color:#FF0000;">"This is a test upload"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/var_dump" onclick="urchinTracker('/outgoing/www.php.net/var_dump?referer=');"><span style="color:#000066;">var_dump</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/is_uploaded_file" onclick="urchinTracker('/outgoing/www.php.net/is_uploaded_file?referer=');"><span style="color:#000066;">is_uploaded_file</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/tmp/upload.tmp'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/var_dump" onclick="urchinTracker('/outgoing/www.php.net/var_dump?referer=');"><span style="color:#000066;">var_dump</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_FILES</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/var_dump" onclick="urchinTracker('/outgoing/www.php.net/var_dump?referer=');"><span style="color:#000066;">var_dump</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/move_uploaded_file" onclick="urchinTracker('/outgoing/www.php.net/move_uploaded_file?referer=');"><span style="color:#000066;">move_uploaded_file</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/tmp/upload.tmp"</span>, <span style="color:#FF0000;">"/tmp/test_file.txt"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/unlink" onclick="urchinTracker('/outgoing/www.php.net/unlink?referer=');"><span style="color:#000066;">unlink</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/tmp/test_file.txt"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>And it can be executed using:</p>
<div class="igBar"><span id="lphp-4"><a href="#" onclick="javascript:showCodeTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># php -dfakeupload.enabled=1 test.php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">bool<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"userFile"</span><span style="color:#006600; font-weight:bold;">&#93;</span>=&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"name"</span><span style="color:#006600; font-weight:bold;">&#93;</span>=&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; string<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">20</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#FF0000;">"/Users/test/test.txt"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"type"</span><span style="color:#006600; font-weight:bold;">&#93;</span>=&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; string<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#FF0000;">"text/plain"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"tmp_name"</span><span style="color:#006600; font-weight:bold;">&#93;</span>=&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; string<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">15</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#FF0000;">"/tmp/upload.tmp"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"error"</span><span style="color:#006600; font-weight:bold;">&#93;</span>=&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"size"</span><span style="color:#006600; font-weight:bold;">&#93;</span>=&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">21</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">bool<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The source can be found here: <a href="http://valokuva.org/outside-blog-content/fakeupload/fakeupload-0.0.2.tgz">fakeupload-0.0.2.tgz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=132</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Perspective transformations</title>
		<link>http://valokuva.org/?p=112</link>
		<comments>http://valokuva.org/?p=112#comments</comments>
		<pubDate>Wed, 04 Feb 2009 20:48:21 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=112</guid>
		<description><![CDATA[Finally (after a long break) I managed to force myself to update the PHP documentation and this time it was distortImage code example. Things have been hectic lately but that does not quite explain the 6 months(?) break between this and the previous post. As a matter of a fact there is no excuse for [...]]]></description>
			<content:encoded><![CDATA[<p>Finally (after a long break) I managed to force myself to update the PHP documentation and this time it was distortImage code example. Things have been hectic lately but that does not quite explain the 6 months(?) break between this and the previous post. As a matter of a fact there is no excuse for such a long silence so I will try to update this blog a bit more often from now on.</p>
<p>Back in the day I used to blog the examples and update the documentation if I remembered but I am trying to fix this bad habit. Most of the latest examples have been updated in to the manual. In the case of the two last examples I updated the documentation first and then blogged on the subject.</p>
<p>I took some time to actually understand the perspective transformations properly using the excellent <a href="http://imagemagick.org/Usage/distorts/#perspective" onclick="urchinTracker('/outgoing/imagemagick.org/Usage/distorts/_perspective?referer=');">ImageMagick examples</a> (mainly created by Anthony Thyssen) as a reference. The basic idea of perspective distortion seems simple: to distort the control points to new locations. Grabbing the syntax for Imagick was easy, an array of control point pairs in the form of:</p>
<div class="igBar"><span id="lphp-7"><a href="#" onclick="javascript:showCodeTxt('php-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-7">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span>source_x, source_y, dest_x, dest_y ... <span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The following example uses the built-in checkerboard pattern to demonstrate perspective distortion:</p>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showCodeTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create new object */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create new checkerboard pattern */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">newPseudoImage</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">100</span>, <span style="color:#CC66CC;color:#800000;">100</span>, <span style="color:#FF0000;">"pattern:checkerboard"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Set the image format to png */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">setImageFormat</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'png'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Fill background area with transparent */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">setImageVirtualPixelMethod</span><span style="color:#006600; font-weight:bold;">&#40;</span>Imagick::<span style="color:#006600;">VIRTUALPIXELMETHOD_TRANSPARENT</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Activate matte */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">setImageMatte</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Control points for the distortion */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$controlPoints</span> = <a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#CC66CC;color:#800000;">10</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#CC66CC;color:#800000;">5</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageHeight</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">20</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageHeight</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">5</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageWidth</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#CC66CC;color:#800000;">10</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageWidth</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#CC66CC;color:#800000;">20</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageWidth</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageHeight</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">10</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageWidth</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageHeight</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">30</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Perform the distortion */</span>&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">distortImage</span><span style="color:#006600; font-weight:bold;">&#40;</span>Imagick::<span style="color:#006600;">DISTORTION_PERSPECTIVE</span>, <span style="color:#0000FF;">$controlPoints</span>, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Ouput the image */</span>&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header" onclick="urchinTracker('/outgoing/www.php.net/header?referer=');"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-Type: image/png"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$im</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Here is the source image:<br />
<img src="http://valokuva.org/wp-content/uploads/2009/02/checker.png" alt="checker before" /></p>
<p>And the result:<br />
<img src="http://valokuva.org/wp-content/uploads/2009/02/checkerboard.png" alt="after" /></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=112</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Fill patterns</title>
		<link>http://valokuva.org/?p=102</link>
		<comments>http://valokuva.org/?p=102#comments</comments>
		<pubDate>Sat, 26 Apr 2008 09:15:28 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=102</guid>
		<description><![CDATA[My work life has been quite busy lately and I haven't had a chance to sit down and blog. I have been touring around London and some parts of the northern England consulting and organizing some training here and there. Luckily I have had the chance to do some work on Imagick and the 2.2.0 [...]]]></description>
			<content:encoded><![CDATA[<p>My work life has been quite busy lately and I haven't had a chance to sit down and blog. I have been touring around London and some parts of the northern England consulting and organizing some training here and there. Luckily I have had the chance to do some work on Imagick and the 2.2.0 beta release is getting closer. The internal structure was completely restructured and broken down into several smaller files. During this time Imagick was adapted to follow the PHP Coding Standards more closely. Still a work in progress <img src='http://valokuva.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I committed slightly modified version of this example to PHP Manual <a href="http://uk.php.net/manual/en/imagick.examples.php" onclick="urchinTracker('/outgoing/uk.php.net/manual/en/imagick.examples.php?referer=');">http://uk.php.net/manual/en/imagick.examples.php</a> page a few days ago. The example illustrates using an image as a part of a named fill pattern. The fill pattern is used to annotate text but the named pattern could also be used to fill any shapes that allow fill to be specified (include circles, ellipses, rectangles, polygons etc etc). The code itself is pretty straight forward: Read the image, create the pattern and use the pattern as a fill.</p>
<p>The ice formations image is from <a href="http://www.photoeverywhere.co.uk/west/winterholiday/slides/iceformations5679.htm" onclick="urchinTracker('/outgoing/www.photoeverywhere.co.uk/west/winterholiday/slides/iceformations5679.htm?referer=');">http://www.photoeverywhere.co.uk/west/winterholiday/slides/iceformations5679.htm</a>.</p>
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showCodeTxt('php-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-10">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create a new imagick object */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'iceformations5679.JPG'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create imagickdraw object */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span> = <span style="color:#000000; font-weight:bold;">new</span> ImagickDraw<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Start a new pattern called &quot;ice&quot; */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span>-&gt;<span style="color:#006600;">pushPattern</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'ice'</span>&nbsp; , <span style="color:#CC66CC;color:#800000;">0</span>&nbsp; , <span style="color:#CC66CC;color:#800000;">0</span>&nbsp; , <span style="color:#CC66CC;color:#800000;">50</span>&nbsp; , <span style="color:#CC66CC;color:#800000;">50</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Composite the image on the pattern */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span>-&gt;<span style="color:#006600;">composite</span><span style="color:#006600; font-weight:bold;">&#40;</span> Imagick::<span style="color:#006600;">COMPOSITE_OVER</span>, <span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#CC66CC;color:#800000;">50</span>, <span style="color:#CC66CC;color:#800000;">50</span>, <span style="color:#0000FF;">$im</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Close the pattern */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span>-&gt;<span style="color:#006600;">popPattern</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Use the pattern called &quot;ice&quot; as the fill */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span>-&gt;<span style="color:#006600;">setFillPatternURL</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'#ice'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Set font size to 52 */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span>-&gt;<span style="color:#006600;">setFontSize</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC66CC;color:#800000;">52</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Annotate some text */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$draw</span>-&gt;<span style="color:#006600;">annotation</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC66CC;color:#800000;">5</span>, <span style="color:#CC66CC;color:#800000;">50</span>, <span style="color:#FF0000;">"Hello World!"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create a new canvas and white image */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span>-&gt;<span style="color:#006600;">newImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC66CC;color:#800000;">310</span>, <span style="color:#CC66CC;color:#800000;">70</span>, <span style="color:#FF0000;">"white"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Add black border around the resulting image */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span>-&gt;<span style="color:#006600;">borderImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'black'</span>, <span style="color:#CC66CC;color:#800000;">1</span>, <span style="color:#CC66CC;color:#800000;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Draw the ImagickDraw on to the canvas */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span>-&gt;<span style="color:#006600;">drawImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$draw</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Set the format to PNG */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span>-&gt;<span style="color:#006600;">setImageFormat</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'png'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Output the image */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header" onclick="urchinTracker('/outgoing/www.php.net/header?referer=');"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Content-Type: image/png"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$canvas</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>And the result is here:</p>
<p><a href="http://valokuva.org/wp-content/uploads/2008/04/patternphp1.png"><img src="http://valokuva.org/wp-content/uploads/2008/04/patternphp1.png"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=102</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>phplondon conference 2008</title>
		<link>http://valokuva.org/?p=101</link>
		<comments>http://valokuva.org/?p=101#comments</comments>
		<pubDate>Sun, 02 Mar 2008 19:35:59 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Everything else]]></category>
		<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>
		<category><![CDATA[phplondon08]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=101</guid>
		<description><![CDATA[To summarize it: I had fun My conference preparations started about two weeks before the conference. The PHPLondon fellows (Paul, Matt and Richard) asked me to do a small presentation about Imagick at the pre-conference social event. The presentation I assembled ended up being a little over two hours, give or take. The hardest part [...]]]></description>
			<content:encoded><![CDATA[<p>To summarize it: I had fun <img src='http://valokuva.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  My conference preparations started about two weeks before the conference. The PHPLondon fellows (Paul, Matt and Richard) asked me to do a small presentation about Imagick at the pre-conference social event. The presentation I assembled ended up being a little over two hours, give or take. The hardest part was to trim down from two hours to about 40 minutes (I didn't want to bore the people with too many code examples). The slides are available at <a href="http://valokuva.org/talks">http://valokuva.org/talks</a> if you need them for some reason. </p>
<p>My conference day was pretty hectic from the beginning to the end. I gave a few demos about the products that we represent and the moment I opened my mouth for the first time people started leaving the room. I hope that it had something to do with the  "My Framework is better than yours?" talk starting at the same time <img src='http://valokuva.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I met quite a lot of new people at the conference and of course it was nice to see the familiar faces from other conferences and PHPLondon meetings. I was especially happy that I was able to answer the questions <a href="http://nigeljames.wordpress.com/2008/03/01/quick-update-from-phplondon-conference/" onclick="urchinTracker('/outgoing/nigeljames.wordpress.com/2008/03/01/quick-update-from-phplondon-conference/?referer=');">Nigel James</a> had <img src='http://valokuva.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>A huge thanks to the organizers for making this day possible!</p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=101</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Seam carving</title>
		<link>http://valokuva.org/?p=99</link>
		<comments>http://valokuva.org/?p=99#comments</comments>
		<pubDate>Wed, 13 Feb 2008 18:38:21 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=99</guid>
		<description><![CDATA[Today I was reading trough the ImageMagick ChangeLog and noticed an interesting entry. "Add support for liquid rescaling". I rushed to check the MagickWand API docs and there it was: MagickLiquidRescaleImage! After about ten minutes of hacking the Imagick support was done. Needless to say; I was excited For those who don't know what seam [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was reading trough the ImageMagick ChangeLog and noticed an interesting entry. "Add support for liquid rescaling". I rushed to check the MagickWand API docs and there it was: MagickLiquidRescaleImage! After about ten minutes of hacking the Imagick support was done. Needless to say; I was excited <img src='http://valokuva.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>For those who don't know what seam carving is check the demo <a href="http://www.youtube.com/watch?v=6NcIJXTlugc" onclick="urchinTracker('/outgoing/www.youtube.com/watch?v=6NcIJXTlugc&amp;referer=');">here</a>. More detailed information about the algorithm can be found here: <a href="http://www.faculty.idc.ac.il/arik/imret.pdf" onclick="urchinTracker('/outgoing/www.faculty.idc.ac.il/arik/imret.pdf?referer=');">"Seam Carving for Content-Aware Image Resizing" by Shai Avidan and Ariel Shamir</a></p>
<p>To use this functionality you need to install at least ImageMagick 6.3.8-2 and liblqr. Remember to pass --with-lqr to ImageMagick configuration line. You can get liblqr here: <a href="http://liblqr.wikidot.com/" onclick="urchinTracker('/outgoing/liblqr.wikidot.com/?referer=');">http://liblqr.wikidot.com/</a>. The Imagick side of the functionality should appear in the CVS today if everything goes as planned.</p>
<p>Here is a really simple example just to illustrate the results of the operation. The parameters might be far from optimal (didn't do much testing yet). The original dimensions of image are 500x375 and the resulting size is 500x200.</p>
<p><em><strong>Update: the functionality is pending until license issues are solved.</strong></em></p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showCodeTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create new object */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'test.jpg'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Scale down */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">liquidRescaleImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#CC66CC;color:#800000;">500</span>, <span style="color:#CC66CC;color:#800000;">200</span>, <span style="color:#CC66CC;color:#800000;">3</span>, <span style="color:#CC66CC;color:#800000;">25</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Display */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header" onclick="urchinTracker('/outgoing/www.php.net/header?referer=');"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'Content-Type: image/jpg'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$im</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The original image by flickr/jennconspiracy</p>
<p><img src="http://valokuva.org/wp-content/uploads/2008/02/landscape_orig.jpg" alt="result" /></p>
<p>And the result:</p>
<p><img src="http://valokuva.org/wp-content/uploads/2008/02/landscape.jpg" alt="result" /></p>
<p><em>Update. On kenrick's request here is an image which is scaled down to 300x300 </em></p>
<p><img src="http://valokuva.org/wp-content/uploads/2008/02/300x300_result.jpg" alt="result2" /></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=99</wfw:commentRss>
		<slash:comments>50</slash:comments>
		</item>
		<item>
		<title>Typesetting</title>
		<link>http://valokuva.org/?p=93</link>
		<comments>http://valokuva.org/?p=93#comments</comments>
		<pubDate>Wed, 16 Jan 2008 22:07:28 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=93</guid>
		<description><![CDATA[Ever had the situation where you have a piece of string which you need to overlay on an image? Maybe a situation where the area reserved for the string is known in pixels but you need to know the font size to fill most of the area? Think no more! Here is a small example [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had the situation where you have a piece of string which you need to overlay on an image? Maybe a situation where the area reserved for the string is known in pixels but you need to know the font size to fill most of the area? Think no more! </p>
<p>Here is a small example of how to fit a certain piece of a string on to an area of which you know the width and the height or only the width. The magic happens through the ImageMagick CAPTION: format. You can see from the example images how the parameters actually affect the image.</p>
<div class="igBar"><span id="lphp-14"><a href="#" onclick="javascript:showCodeTxt('php-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-14">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* How wide is our image */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$image_width</span> = <span style="color:#CC66CC;color:#800000;">200</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Give zero for autocalculating the height */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$image_height</span> = <span style="color:#CC66CC;color:#800000;">200</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Specify the text */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$text</span> = <span style="color:#FF0000;">"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Mauris lectus mi, mattis non, euismod vel, sagittis nec, ipsum."</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Instanciate imagick */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create new image using caption: pseudo format */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">newPseudoImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$image_width</span>, <span style="color:#0000FF;">$image_height</span>, <span style="color:#FF0000;">"caption:"</span> . <span style="color:#0000FF;">$text</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Put 1px border around the image */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">borderImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">'black'</span>, <span style="color:#CC66CC;color:#800000;">1</span>, <span style="color:#CC66CC;color:#800000;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* PNG format */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">setImageFormat</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"png"</span><span style="color:#006600; font-weight:bold;">&#41;</span> ;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Output */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header" onclick="urchinTracker('/outgoing/www.php.net/header?referer=');"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Content-Type: image/png"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$im</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Here is image with width 100 and height 0:</p>
<p><a href='http://valokuva.org/wp-content/uploads/2008/01/width_100_height_0.png' title='width_100_height_0.png'><img src='http://valokuva.org/wp-content/uploads/2008/01/width_100_height_0.png' alt='width_100_height_0.png' /></a></p>
<p>Width 100 Height 50:</p>
<p><a href='http://valokuva.org/wp-content/uploads/2008/01/width_100_height_50.png' title='width_100_height_50.png'><img src='http://valokuva.org/wp-content/uploads/2008/01/width_100_height_50.png' alt='width_100_height_50.png' /></a></p>
<p>Width 200 Height 200 (as you can see the font size is now larger):</p>
<p><a href='http://valokuva.org/wp-content/uploads/2008/01/width_200_height_200.png' title='width_200_height_200.png'><img src='http://valokuva.org/wp-content/uploads/2008/01/width_200_height_200.png' alt='width_200_height_200.png' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=93</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Padding thumbnail with color</title>
		<link>http://valokuva.org/?p=92</link>
		<comments>http://valokuva.org/?p=92#comments</comments>
		<pubDate>Fri, 11 Jan 2008 12:30:34 +0000</pubDate>
		<dc:creator>Mikko Koppanen</dc:creator>
				<category><![CDATA[Imagick]]></category>
		<category><![CDATA[PHP stuff]]></category>

		<guid isPermaLink="false">http://valokuva.org/?p=92</guid>
		<description><![CDATA[I know, it's been a while since I last blogged. This is because a lot of things are happening in my personal life. I recently relocated to London from Finland and started a new job. Things are quite busy but I will try to post an example now and then. In the meanwhile I would [...]]]></description>
			<content:encoded><![CDATA[<p>I know, it's been a while since I last blogged. This is because a lot of things are happening in my personal life. I recently relocated to London from Finland and started a new job. Things are quite busy but I will try to post an example now and then. In the meanwhile I would like to hear about sites using Imagick, so if your project is not super secret please post an url and maybe a small explanation what you're doing with Imagick on the site. This is purely for my personal interest.</p>
<p>Anyway, to the point. Today's example originates from a question asked by a user. How do I thumbnail the image inside given dimensions proportionally and fill the "blank" areas with a color? Well, the answer is here <img src='http://valokuva.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The code is for Imagick 2.1.0 but adapting to older versions should not be hard.</p>
<div class="igBar"><span id="lphp-16"><a href="#" onclick="javascript:showCodeTxt('php-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-16">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Define width and height of the thumbnail */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$width</span> = <span style="color:#CC66CC;color:#800000;">100</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$height</span> = <span style="color:#CC66CC;color:#800000;">100</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Instanciate and read the image in */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"test.png"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Fit the image into $width x $height box </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> The third parameter fits the image into a &quot;bounding box&quot; */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">thumbnailImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$width</span>, <span style="color:#0000FF;">$height</span>, <span style="color:#000000; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Create a canvas with the desired color */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span> = <span style="color:#000000; font-weight:bold;">new</span> Imagick<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span>-&gt;<span style="color:#006600;">newImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$width</span>, <span style="color:#0000FF;">$height</span>, <span style="color:#FF0000;">'pink'</span>, <span style="color:#FF0000;">'png'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Get the image geometry */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$geometry</span> = <span style="color:#0000FF;">$im</span>-&gt;<span style="color:#006600;">getImageGeometry</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* The overlay x and y coordinates */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$x</span> = <span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$width</span> - <span style="color:#0000FF;">$geometry</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'width'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#CC66CC;color:#800000;">2</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$y</span> = <span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$height</span> - <span style="color:#0000FF;">$geometry</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'height'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#CC66CC;color:#800000;">2</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Composite on the canvas&nbsp; */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$canvas</span>-&gt;<span style="color:#006600;">compositeImage</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$im</span>, imagick::<span style="color:#006600;">COMPOSITE_OVER</span>, <span style="color:#0000FF;">$x</span>, <span style="color:#0000FF;">$y</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* Output the image*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header" onclick="urchinTracker('/outgoing/www.php.net/header?referer=');"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Content-Type: image/png"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$canvas</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The source image:<br />
<a href='http://valokuva.org/wp-content/uploads/2008/01/test.png' title='test.png'><img src='http://valokuva.org/wp-content/uploads/2008/01/test.png' alt='test.png' /></a></p>
<p>The resulting image:<br />
<a href='http://valokuva.org/wp-content/uploads/2008/01/testphp.png' title='testphp.png'><img src='http://valokuva.org/wp-content/uploads/2008/01/testphp.png' alt='testphp.png' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://valokuva.org/?feed=rss2&amp;p=92</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc (user agent is rejected)
Database Caching 5/10 queries in 0.022 seconds using apc

Served from: valokuva.org @ 2010-09-10 19:23:17 -->