<?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>su.percilio.us &#187; imagick</title>
	<atom:link href="http://su.percilio.us/tag/imagick/feed/" rel="self" type="application/rss+xml" />
	<link>http://su.percilio.us</link>
	<description>Haughtily disdainful or contemptuous</description>
	<lastBuildDate>Tue, 06 Apr 2010 15:58:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Setting Locale and Using PECL&#8217;s Imagick Library in PHP</title>
		<link>http://su.percilio.us/2010/04/setting-locale-and-using-pecls-imagick-library-in-php/</link>
		<comments>http://su.percilio.us/2010/04/setting-locale-and-using-pecls-imagick-library-in-php/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 19:13:45 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Nerdities]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[pecl]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://su.percilio.us/?p=179</guid>
		<description><![CDATA[I ran across an interesting issue today. An issue, that when I Googled it, appeared to have been resolved 2 years ago. However, I was using up-to-date versions of PHP, ImageMagick and the Imagick PECL library. So, on to my issue. I have an abstract piece of code that when given the proper variables will [...]]]></description>
			<content:encoded><![CDATA[<p>I ran across an interesting issue today. An issue, that when I Googled it, appeared to have been resolved 2 years ago. However, I was using up-to-date versions of PHP, ImageMagick and the Imagick PECL library. </p>
<p>So, on to my issue. I have an abstract piece of code that when given the proper variables will set set the locale for my application. It sets the locale thusly:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">setlocale</span><span style="color: #009900;">&#40;</span>LC_ALL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'fr_CA.utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Later in the application, I was trying to draw a rectangle for a gauge that would graph a number against another number. When I tried to call the Imagick rectangle method, all hell broke loose.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$gauge</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ImagickDraw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$x1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">position</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$y1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">position</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">y1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$x2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">position</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x2</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$y2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">position</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">y2</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gauge</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x1</span><span style="color: #339933;">,</span><span style="color: #000088;">$y1</span><span style="color: #339933;">,</span><span style="color: #000088;">$x2</span><span style="color: #339933;">,</span><span style="color: #000088;">$y2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I then got this lovely message:</p>

<div class="wp_syntax"><div class="code"><pre class="log" style="font-family:monospace;">Fatal error: Uncaught exception 'ImagickException' with message 'Non-conforming drawing primitive definition `,' @ draw.c/DrawImage/3123'</pre></div></div>

<p>Googled a bit and everything said this was fixed in the PECL library as of 2007. But it&#8217;s 2010 and I&#8217;m still having the issue!</p>
<p>Turns out if you set &#8220;LC_NUMERIC&#8221; to any French language locale, it can make interpreting floats difficult, because the French use commas (,) instead of periods (.) to delimit their fractions numerically. This caused the &#8220;rectangle&#8221; function of the &#8220;Imagick&#8221; PECL library to go crazy.</p>
<p>My Solution?</p>
<p>I altered my brash locale setting code to be a little more granular:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">setlocale</span><span style="color: #009900;">&#40;</span>LC_TIME<span style="color: #339933;">,</span> <span style="color: #0000ff;">'fr_CA.utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">setlocale</span><span style="color: #009900;">&#40;</span>LC_MONETARY<span style="color: #339933;">,</span> <span style="color: #0000ff;">'fr_CA.utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Setting locales for &#8220;LC_TIME&#8221; and &#8220;LC_MONETARY&#8221; was enough for me to get the programmatic localization I needed. And it made sure that &#8220;LC_NUMERIC&#8221; did not get set and cause localization on floats to interfere with external libraries.</p>
<p>This is &#8220;bang your head against the wall&#8221; stuff people. I hope this helps someone.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fsu.percilio.us%2F2010%2F04%2Fsetting-locale-and-using-pecls-imagick-library-in-php%2F';
  addthis_title  = 'Setting+Locale+and+Using+PECL%26%238217%3Bs+Imagick+Library+in+PHP';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://su.percilio.us/2010/04/setting-locale-and-using-pecls-imagick-library-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

