<?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; imagemagick</title> <atom:link href="http://sniptools.com/tag/imagemagick/feed/" rel="self" type="application/rss+xml" /><link>http://sniptools.com</link> <description>Design &#38; Technology Observations</description> <lastBuildDate>Tue, 15 May 2012 09:23:41 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</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>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 4/7 queries in 0.002 seconds using disk: basic
Object Caching 523/526 objects using disk: basic

Served from: sniptools.com @ 2012-05-17 20:22:43 -->
