<?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>Sniptools &#187; PEAR</title>
	<atom:link href="http://sniptools.com/tag/pear/feed" rel="self" type="application/rss+xml" />
	<link>http://sniptools.com</link>
	<description>Design &#38; Technology Observations</description>
	<lastBuildDate>Mon, 10 Oct 2011 02:12:36 +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>Dynamic Thumbnailing with Imagemagick in PHP</title>
		<link>http://sniptools.com/vault/dynamic-thumbnailing-with-imagemagick-in-php</link>
		<comments>http://sniptools.com/vault/dynamic-thumbnailing-with-imagemagick-in-php#comments</comments>
		<pubDate>Tue, 27 May 2003 18:21:21 +0000</pubDate>
		<dc:creator>Shanx</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[imaging]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://sniptools.com/cms/?p=22</guid>
		<description><![CDATA[Dynamic Thumbnailing with Imagemagick in PHP
]]></description>
			<content:encoded><![CDATA[<p>Here is some sample code that allows you to create a thumbnail automatically (assuming ImageMagick is already installed and functional) (based on the <a href="http://pear.sourceforge.net/en/packages.imagick.php">imagick</a> PEAR module).</p>
<h2></h2>
<h2>Code for dynamic thumbnails using PHP</h2>
<blockquote>
<pre>&lt;?php
<span style="color: #ff9900;">
<span style="color: #008000;">// Specify your file details</span></span>
$current_file = 'image.jpg';
$max_width = '150';
<span style="color: #ff9900;">
<span style="color: #008000;">// Get the current info on the file</span></span>
$current_size = getimagesize($current_file);
$current_img_width = $current_size[0];
$current_img_height = $current_size[1];
$image_base = explode('.', $current_file);
<span style="color: #ff9900;"><span style="color: #008000;">
</span><span style="color: #008000;">// This part gets the new thumbnail name</span></span>
$image_basename = $image_base[0];
$image_ext = $image_base[1];
$thumb_name = $image_basename.'-th.'.$image_ext;
<span style="color: #ff9900;"><span style="color: #008000;">
// Determine if the image actually needs to be resized
// and if it does, get the new height for it</span>
</span>if ($current_img_width &gt; $max_width)
{
  $too_big_diff_ratio = $current_img_width/$max_width;
  $new_img_width = $max_width;
  $new_img_height = round($current_img_height/$too_big_diff_ratio);
  <span style="color: #008000;">// Convert the file</span>
  $make_magick = system("convert -geometry $new_img_width x $new_img_height $current_file $thumb_name", $retval);
  <span style="color: #008000;">// Did it work?</span>
  if (!($retval)) {
    echo 'Thumbnail created: &lt;img src="' .$thumb_name .'"&gt;';
  }
  else {
    echo 'Error: Please try again.';
  }
}
else
{
  echo 'No need to resize.';
}</pre>
<p>?&gt;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://sniptools.com/vault/dynamic-thumbnailing-with-imagemagick-in-php/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

