<?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>Daniel Eneström &#187; ImageMagick</title>
	<atom:link href="http://enestrom.com/tag/imagemagick/feed/" rel="self" type="application/rss+xml" />
	<link>http://enestrom.com</link>
	<description>Keep It Simply Stupid</description>
	<lastBuildDate>Fri, 23 Dec 2011 00:50:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>phpThumb and imagerotate()</title>
		<link>http://enestrom.com/20090509/phpthumb-and-imagerotate/</link>
		<comments>http://enestrom.com/20090509/phpthumb-and-imagerotate/#comments</comments>
		<pubDate>Sat, 09 May 2009 09:41:12 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Image processing]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[imagerotate()]]></category>
		<category><![CDATA[phpThumb]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=90</guid>
		<description><![CDATA[One of the PHP libraries I use the most is phpThumb, because of its ease to use and portability. Simply putting the folder in the web root is usually sufficient to get started. One thing has annoyed me for a &#8230; <a href="http://enestrom.com/20090509/phpthumb-and-imagerotate/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20090509/phpthumb-and-imagerotate/' addthis:title='phpThumb and imagerotate() ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>One of the PHP libraries I use the most is phpThumb, because of its ease to use and portability. Simply putting the folder in the web root is usually sufficient to get started. One thing has annoyed me for a while though, and it is that I couldn&#8217;t get the rotating commands to work.</p>
<p>After some research I discovered that the <a href="http://se2.php.net/imagerotate()" target="_blank">imagerotate()</a> function in GD library (a library that handles many of the graphics processing in phpThumb) is only available in the bundled version of GD library (that is: the version that sometimes comes bundled with PHP). That is not the case for me and I have my own server with lots of sites on, and didn&#8217;t feel like recompiling PHP just to get the imagerotate function to work.</p>
<p>So, in this new light, I looked for a function replacement using <a href="http://www.imagemagick.org/script/index.php" target="_blank">ImageMagick</a> instead (a much better image processing library, but rarely installed by default) and found this one somewhere. Simply put it at the bottom of your <em>phpthumb.functions.php </em>file and *poof* rotating images in phpThumb will start working.</p>
<pre lang="php">if ( !function_exists( 'imagerotate' ) ) {
    function imagerotate( $source_image, $angle, $bgd_color=null ) {
        $angle = 360-$angle; // GD rotates CCW, imagick rotates CW
        $temp_src = '/tmp/temp_src.png';
        $temp_dst = '/tmp/temp_dst.png';
        if (!imagepng($source_image,$temp_src)){
            return false;
        }
        $imagick = new Imagick();
        $imagick->readImage($temp_src);
        $imagick->rotateImage(new ImagickPixel(), $angle);
        $imagick->writeImage($temp_dst);
        //trigger_error( 'imagerotate(): could not write to ' . $file1 . ', original image returned', E_USER_WARNING );
        $result = imagecreatefrompng($temp_dst);
        unlink($temp_dst);
        unlink($temp_src);
        return $result;
    }
}</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20090509/phpthumb-and-imagerotate/' addthis:title='phpThumb and imagerotate() ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20090509/phpthumb-and-imagerotate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

