<?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>Snipe.Net &#187; image manipulation</title>
	<atom:link href="http://www.snipe.net/tags/image-manipulation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snipe.net</link>
	<description>Bitterness never tasted so sweet</description>
	<lastBuildDate>Thu, 29 Jul 2010 05:03:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Tilt-Shift Photos (and How to Fake Them)</title>
		<link>http://www.snipe.net/2009/01/tilt-shift-photography/</link>
		<comments>http://www.snipe.net/2009/01/tilt-shift-photography/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 17:03:52 +0000</pubDate>
		<dc:creator>snipe</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[photography]]></category>

		<guid isPermaLink="false">http://www.snipe.net/?p=886</guid>
		<description><![CDATA[Tilt-shift photography (also known in the industry as &#8220;swing and tilt&#8221;) is a method by which photographers can take an aerial shot of a real-life place that makes it look as though it&#8217;s a miniature model. It&#8217;s a fascinating effect, and I have always found it interesting how the lens can fool the eye into [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.snipe.net%2F2009%2F01%2Ftilt-shift-photography%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.snipe.net%2F2009%2F01%2Ftilt-shift-photography%2F&amp;source=snipeyhead&amp;style=normal&amp;service=bit.ly&amp;service_api=R_92bd97f4f8b9fa8a40675b36ea291223" height="61" width="50" /><br />
			</a>
		</div>
<p>Tilt-shift photography (also known in the industry as &#8220;swing and tilt&#8221;) is a method by which photographers can take an aerial shot of a real-life place that makes it look as though it&#8217;s a miniature model. It&#8217;s a fascinating effect, and I have always found it interesting how the lens can fool the eye into believing something that isn&#8217;t real simply by adjusting light and focus. The end-result is very cool, and always reminds me a bit of the intro to Mr. Roger&#8217;s Neighborhood.<span id="more-886"></span></p>
<h2>Some Amazing Examples of Tilt-Shift Photography</h2>
<p>While tilt-shift photography has been gaining momentum, photographers Olivo Barbieri andÂ  <a href="http://www.vincentlaforet.com/" target="_blank">Vincent LaForet</a> were some of the first to bring this technique mainstream, with LaForet&#8217;s work featured in the New York Times and all over the country. I&#8217;ve included a few of his pieces here, but if you like this style, be sure to check out the <strong><a href="http://www.nytimes.com/packages/html/magazine/20070531_VINCENT_FEATURE/blocker.html" target="_blank">New York Times photo slideshow</a></strong> (with fascinating audio) of his work, a great collection of <strong><a href="http://www.smashingmagazine.com/2008/11/16/beautiful-examples-of-tilt-shift-photography/" target="_blank">50 Beautiful Examples of Tilt-Shift Photography</a></strong> by Smashing Magazine, and a <strong><a href="http://www.funtasticus.com/20081128/effective-tilt-shift-photography/" target="_blank">substantial collection on Funtasticus</a></strong> (although I suspect a few of these may be faked &#8211; but more on that later.)</p>
<div id="attachment_891" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.snipe.net/wp-content/uploads/2009/01/lf2.jpg"><img class="size-full wp-image-891" title="lf2" src="http://www.snipe.net/wp-content/uploads/2009/01/lf2.jpg" alt="Photo by Vincent LaForet" width="500" height="349" /></a><p class="wp-caption-text">Photo by Vincent LaForet</p></div>
<div id="attachment_892" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.snipe.net/wp-content/uploads/2009/01/tennis.jpg"><img class="size-full wp-image-892" title="tennis" src="http://www.snipe.net/wp-content/uploads/2009/01/tennis.jpg" alt="Photo by Vincent LaForet" width="500" height="332" /></a><p class="wp-caption-text">Photo by Vincent LaForet</p></div>
<div id="attachment_893" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.snipe.net/wp-content/uploads/2009/01/train.jpg"><img class="size-full wp-image-893" title="train" src="http://www.snipe.net/wp-content/uploads/2009/01/train.jpg" alt="Photo by Vincent LaForet" width="500" height="335" /></a><p class="wp-caption-text">Photo by Vincent LaForet</p></div>
<h2>So How Does it Work?</h2>
<p>According to <a href="http://en.wikipedia.org/wiki/Tilt-shift_photography" target="_blank">Wikipedia</a>:</p>
<blockquote><p>Tilt-shift photography refers to the use of camera movements on small- and medium format cameras. In many cases, it refers to tilting the lens relative to the image plane and using a large aperture to achieve a very shallow depth of field. The technique relies on <a href="http://en.wikipedia.org/wiki/Scheimpflug_principle" target="_blank">the Scheimpflug principle</a> [a geometric rule that describes the orientation of the plane of focus of an optical system (such as a camera) when the lens plane is not parallel to the image plane] and usually requires the use of special lenses.</p>
<p>&#8220;Tilt-shift&#8221; actually encompasses two different types of movements: rotation of the lens, called tilt, and movement of the lens parallel to the image plane, called shift. Tilt is used to control the orientation of the plane of focus (PoF), and hence the part of an image that appears sharp. Shift is used to control perspective, usually involving the convergence of parallel lines.</p></blockquote>
<p>Applying tilt on a small- or medium-format camera usually requires a tilt-shift lens or perspective control lens; shift can be applied with the same type of lens or with a lens that offers only the shift movement.</p>
<p>An article on <a href="http://www.cheapshooter.com/2007/08/24/tilt-shift-photography-its-a-small-world-after-all/" target="_blank">Cheapshooter</a> describes it like this:</p>
<blockquote><p>A tilt-shift lens allows the photographer very exacting control over the depth-of-field in an image, much more than any regular lens could provide. Focus can be restricted to a single, narrow band, with everything else rapidly blurring away. This distorts the appearance and makes the eye think that distances are a lot smaller than they typically are. When applied to a large scene like a city or a museum, everything appears miniature.</p></blockquote>
<p>Tilt-shift and perspective-correction lenses are available for many SLR cameras, but most are far more expensive than comparable lenses without movements. The <strong><a href="http://en.wikipedia.org/wiki/Lensbaby" target="_blank">Lensbaby SLR lens</a></strong> is a low-cost alternative for providing tilt and swing for many SLR cameras, although the effect is somewhat different from that of the lenses just described. Because of the simple optical design, aberrations are significant, and sharp focus is limited to a region near the lens axis. Consequently, the Lensbaby&#8217;s primary application is selective focus. If that&#8217;s what you&#8217;re looking for, however, the Lensbaby may be a great (and affordable) choice.</p>
<h2>Tilt-Shift for the Rest of Us: Miniature Faking</h2>
<p>Unlike my amazingly talented husband, who is a <a href="http://flickr.com/photos/lundegaard/sets/72157607004256283/" target="_blank">professional photographer</a> (among other things), I am less-than-awesome behind a camera. I&#8217;ve managed to pull off a few decent shots in my life, but only thanks to digital cameras, and taking thousands of shots, hoping one might come out the way I want. Seriously, if I were kidnapped by that bad guy from the Saw franchise, and all I had to do to get out was take a decent photo using a camera that doesn&#8217;t auto-focus, I&#8217;d be dead.</p>
<p>My skills are more in the post-production area, using Photoshop to create the effect I am not capable of achieving through my camera alone. I can fake it, even though I can&#8217;t make it.</p>
<p>And just like everything else genuine and cool in this world, you have to figure that eventually someone would figure out how to fake it.</p>
<p>In principle, itâ€™s not hard to make a fake: essentially, pick an area in a photo that you want to sharpen, then blur the rest. (Unnatural color saturation, one helpful fake-tilt-shift tutorial offers, â€œmakes it look more as if itâ€™s built from polystyrene and lichen.â€) In practice, itâ€™s a little harder and takes some time, but the end results are really fun.</p>
<p>Two excellent tutorials on using Photoshop to turn a regular photo into a faked tilt-shift photo can be found on <strong><a href="http://www.tiltshiftphotography.net/photoshop-tutorial.php" target="_blank">TiltShiftPhotography.Net</a></strong> and <strong><a href="http://recedinghairline.co.uk/tutorials/fakemodel/" target="_blank">Receding Hairline</a></strong>, although like any other tutorial for photo editing, it&#8217;s not an exact formula since every photo is different. Once you get a feel for the process, you&#8217;ll want to play around with the settings until you get the end result you&#8217;re looking for.</p>
<p>If you don&#8217;t have any aerial photos laying around to practice on, consider using Google Earth.Â  To get an idea of exactly how amazing this effect can be using Google Earth images, check out <a href="http://www.gearthblog.com/blog/archives/2008/12/tilt_shift_photography_using_google.html" target="_blank">this video</a> on the Google Earth Blog, that does a <strong><a href="http://www.gearthblog.com/blog/archives/2008/12/tilt_shift_photography_using_google.html" target="_blank">video flyover of San Francisco using faked tilt-shift photos</a> </strong>based on images from Google Earth. Simply incredible.</p>
<h2>And, For the Truly Lazy&#8230;</h2>
<p>The website <strong><a href="http://tiltshiftmaker.com/" target="_blank">TiltShiftMaker.Com</a></strong> lets you upload your own real-life photos, and use a simple interface to select the area you want to focus on. Click a button, and boom, you&#8217;re done. If you&#8217;re skeptical that it can be that easy, check out <a href="http://flickr.com/groups/tiltshiftmaker/" target="_blank">their gallery on Flickr</a> and see for yourself.</p>


<p>Possibly related posts:<ol><li><a href='http://www.snipe.net/2008/11/photo-retouching-how-to-salvage-a-dark-digital-photo/' rel='bookmark' title='Permanent Link: Photo Retouching &#8211; How to Salvage a Dark Digital Photo'>Photo Retouching &#8211; How to Salvage a Dark Digital Photo</a> <small>I prefer not to shoot with flash when I can...</small></li>
<li><a href='http://www.snipe.net/2008/12/techy-spin-on-office-cards/' rel='bookmark' title='Permanent Link: Put a Fun, Techy Spin on the Boring Office Card'>Put a Fun, Techy Spin on the Boring Office Card</a> <small>You know the drill &#8211; someone in the office is...</small></li>
<li><a href='http://www.snipe.net/2008/11/facebook-and-myspace-users-beware-virus/' rel='bookmark' title='Permanent Link: Facebook and MySpace Users, Beware!'>Facebook and MySpace Users, Beware!</a> <small>I have received two virus emails from two unrelated friends,...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.snipe.net/2009/01/tilt-shift-photography/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cropped Thumbnails using PHP and the GD Library</title>
		<link>http://www.snipe.net/2004/06/cropped-thumbnails-using-php-and-the-gd-library/</link>
		<comments>http://www.snipe.net/2004/06/cropped-thumbnails-using-php-and-the-gd-library/#comments</comments>
		<pubDate>Mon, 28 Jun 2004 15:29:31 +0000</pubDate>
		<dc:creator>snipe</dc:creator>
				<category><![CDATA[PHP/mySQL]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.snipe.net/?p=140</guid>
		<description><![CDATA[This code will allow you to create a thumbnail from a segment of the image. In some situations, you want to thumbnail an entire image &#8211; but other times, you may want only a piece &#8211; for example if you wish to generate square thumbnail images regardless of whether or not the original image is [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fcropped-thumbnails-using-php-and-the-gd-library%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fcropped-thumbnails-using-php-and-the-gd-library%2F&amp;source=snipeyhead&amp;style=normal&amp;service=bit.ly&amp;service_api=R_92bd97f4f8b9fa8a40675b36ea291223" height="61" width="50" /><br />
			</a>
		</div>
<p>This code will allow you to create a thumbnail from a segment of the image. In some situations, you want to thumbnail an entire image &#8211; but other times, you may want only a piece &#8211; for example if you wish to generate <span style="font-weight: bold;">square thumbnail images</span> regardless of whether or not the original image is landscape or portrait style.</p>
<p><span id="more-140"></span></p>
<p>The basics are as follows:</p>
<ol>
<li>Resize the image, using the $newthumb size value as the SMALLEST measurement (height in the case of landscape images, width in the case or portrait images). So if you had an original image that is 400 pixels wide and 200 pixels tall, it would set the height to 60 (since 60 is the $newthumb height we&#8217;ve used in the example below) and then resize the width down according to whatever ratio is that will contrain the proportions.</li>
<li>Trim off the extra so that the end thumb is 60&#215;60.</li>
</ol>
<pre class="brush: php">
$orig_path = â€˜/path/to/original/file/â€™;
$micro_path = â€˜/path/to/cropped/file/â€™;
$imagefilename = â€˜myimage.jpgâ€™;

$size = getimagesize($orig_path.$imagefilename);

/**
* new cropped thumbnail sizes
*/
$newthumb_width = 60;
$newthumb_height = 60;

/**
* assign friendlier values to getimagesize data
*/
$orig_width = $size[0];
$orig_height= $size[1];

$width_ratio = ($newthumb_width / $orig_width );
$height_ratio = ($newthumb_height / $orig_height);

if ($orig_width &gt; $orig_height ) {
// this is a landscape image
$crop_width = round($orig_width * $height_ratio);
$crop_height = $newthumb_height;

} elseif ($orig_width &lt; $orig_height ) {
// this is a portrait image
$crop_height = round($orig_height * $width_ratio);
$crop_width = $newthumb_width;

} else {
// this is a square image
$crop_width = $newthumb_width;
$crop_height = $newthumb_height;
}

$source_img = imagecreatefromjpeg($orig_path.$imagefilename);
$dest_img = imagecreatetruecolor($newthumb_width,$newthumb_height);

/**
* if you want to crop from a specific area, for example, if you
* want to crop the image from the middle instead of the top left,
* youâ€™ll need to do some more math to replace the 0,0,0,0 bits here.
*/
imagecopyresampled($dest_img, $source_img, 0 , 0 , 0, 0, $crop_width, $crop_height, $orig_width, $orig_height);
imagejpeg($dest_img, $micro_path.$imagefilename);
imagedestroy($dest_img);</pre>


<p>Possibly related posts:<ol><li><a href='http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-the-gd-library/' rel='bookmark' title='Permanent Link: Dynamic thumbnailing with PHP and the GD library'>Dynamic thumbnailing with PHP and the GD library</a> <small>Although there are loads of ways you can do this,...</small></li>
<li><a href='http://www.snipe.net/2009/02/painting-in-photoshop/' rel='bookmark' title='Permanent Link: Photo-Realistic Painting in Photoshop'>Photo-Realistic Painting in Photoshop</a> <small>While Photoshop is an incredibly powerful photo manipulator, you can...</small></li>
<li><a href='http://www.snipe.net/2004/06/dynamic-watermarkstext-overlay-on-images-in-php/' rel='bookmark' title='Permanent Link: Dynamic Watermarks/Text Overlay on Images in PHP'>Dynamic Watermarks/Text Overlay on Images in PHP</a> <small>This code can be useful for a number of things,...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.snipe.net/2004/06/cropped-thumbnails-using-php-and-the-gd-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic Watermarks/Text Overlay on Images in PHP</title>
		<link>http://www.snipe.net/2004/06/dynamic-watermarkstext-overlay-on-images-in-php/</link>
		<comments>http://www.snipe.net/2004/06/dynamic-watermarkstext-overlay-on-images-in-php/#comments</comments>
		<pubDate>Sun, 27 Jun 2004 15:22:15 +0000</pubDate>
		<dc:creator>snipe</dc:creator>
				<category><![CDATA[PHP/mySQL]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.snipe.net/?p=138</guid>
		<description><![CDATA[This code can be useful for a number of things, such as making dynamic banners or for adding a copyright type of watermark to photographs or artwork (as we do in snipe gallery). As usual, this will not work for gifs unless you have a version of gd that lets you do that (cuz the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fdynamic-watermarkstext-overlay-on-images-in-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fdynamic-watermarkstext-overlay-on-images-in-php%2F&amp;source=snipeyhead&amp;style=normal&amp;service=bit.ly&amp;service_api=R_92bd97f4f8b9fa8a40675b36ea291223" height="61" width="50" /><br />
			</a>
		</div>
<p>This code can be useful for a number of things, such as making dynamic banners or for adding a copyright type of watermark to photographs or artwork (as we do in <a href="http://www.snipegallery.com" target="_blank">snipe gallery</a>). As usual, this will not work for gifs unless you have a version of gd that lets you do that (cuz the folks at Unisys are a bunch of mo-mos).</p>
<p><span id="more-138"></span></p>
<p>The example here is taken from the Godsmack sig generator, so it&#8217;s designed to create white text with a black drop shadow on a preformatted blank banner.</p>
<p>Note: Remember that <strong>PHP must be compiled with jpeg/png/gd support</strong>, AND that the font file must be uploaded to the server for this to work. For our purposes, we&#8217;ll assume you&#8217;re going to take this snippet and make it into its own file, which we&#8217;ll call &#8220;mkwatermark.php&#8221;.</p>
<pre class="brush: php">
// specify the file name - you can use a full path, or &quot;../../&quot; type stuff here
// if the image is not in the same directory as this code file
$image = imagecreatefrompng(&quot;gs-banner-sm.png&quot;);

// specify the font size
$font_size = 14;

// in this case, the color is white, but you can replace the numbers with the RGB values
// of any color you want
$color = imagecolorallocate($image, 255,255,255);

// make our drop shadow color
$black = imagecolorallocate($image, 0,0,0);

// and now we do the overlay - the layers of text start top to bottom, so
// the drop shadow comes first

// $image - the base image file we specified above
// $font_size - Well duh. Its the size of the font
// 0 - the angle of the text - we don&#039;t want an angle, so we leave it at 0
// 55 - pixels to the right from the leftmost part of the image
// 35 - pixels down from the top of the image
// $black - the color we defined above
// &quot;../fonts/ARIALBD.TTF&quot; - the location on the server that the font can be found
// &quot;Test Text&quot; - the text we&#039;re overlaying - you can also use a variable here
ImageTTFText ($image, $font_size, 0, 56, 36, $black, &quot;../fonts/ARIALBD.TTF&quot;,&quot;Test Text&quot;);

// Now add the actual white text &quot;on top&quot;
ImageTTFText ($image, $font_size, 0, 55, 35, $color, &quot;../fonts/ARIALBD.TTF&quot;,&quot;Test Text&quot;);
header(&quot;Content-type: image/png&quot;);
imagepng($image);
imagedestroy($image);
}
</pre>
<p>To print out the image, we would just have to wite the html as:</p>
<pre>&lt;img src="mkwatermark.php"&gt;</pre>
<p>Note about Variables &#8211; If you are using any variables outside the file to determine what the code does (for example, making the text a variable as we do with the Godsmack sig generator), be sure to secure your code and check to be sure the user can&#8217;t do any damage to your system by entering harmful values.</p>


<p>Possibly related posts:<ol><li><a href='http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-imagemagick/' rel='bookmark' title='Permanent Link: Dynamic thumbnailing with PHP and Imagemagick'>Dynamic thumbnailing with PHP and Imagemagick</a> <small>This code formatting is a little off, since the WYSIWG...</small></li>
<li><a href='http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-the-gd-library/' rel='bookmark' title='Permanent Link: Dynamic thumbnailing with PHP and the GD library'>Dynamic thumbnailing with PHP and the GD library</a> <small>Although there are loads of ways you can do this,...</small></li>
<li><a href='http://www.snipe.net/2002/06/sending-htmlplain-text-mail-simultaneously-using-php/' rel='bookmark' title='Permanent Link: Sending HTML/Plain Text Mail Simultaneously using PHP'>Sending HTML/Plain Text Mail Simultaneously using PHP</a> <small>Although I expect this article to cause a few ruffled...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.snipe.net/2004/06/dynamic-watermarkstext-overlay-on-images-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamic thumbnailing with PHP and the GD library</title>
		<link>http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-the-gd-library/</link>
		<comments>http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-the-gd-library/#comments</comments>
		<pubDate>Sun, 27 Jun 2004 15:15:57 +0000</pubDate>
		<dc:creator>snipe</dc:creator>
				<category><![CDATA[PHP/mySQL]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.snipe.net/?p=136</guid>
		<description><![CDATA[Although there are loads of ways you can do this, for this example, we&#8217;re assuming that the fullsize image is located in a directory called &#8220;images&#8221;, and the thumbnails will have the same name as the fullsize, but will be copied into a directory called &#8220;thumbs&#8221;. &#60;?php // find out the current size info $photo_filename [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fdynamic-thumbnailing-with-php-and-the-gd-library%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fdynamic-thumbnailing-with-php-and-the-gd-library%2F&amp;source=snipeyhead&amp;style=normal&amp;service=bit.ly&amp;service_api=R_92bd97f4f8b9fa8a40675b36ea291223" height="61" width="50" /><br />
			</a>
		</div>
<p>Although there are loads of ways you can do this, for this example, we&#8217;re assuming that the fullsize image is located in a directory called &#8220;images&#8221;, and the thumbnails will have the same name as the fullsize, but will be copied into a directory called &#8220;thumbs&#8221;.</p>
<p><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
</span><span style="color: #ff8000;">// find out the current size info<br />
</span><span style="color: #0000bb;">$photo_filename </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"myimage.jpg"<br />
</span><span style="color: #0000bb;">$path </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"/home/snipe/www/images/"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$image_stats </span><span style="color: #007700;">= </span><span style="color: #0000bb;">GetImageSize</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$imagewidth </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$image_stats</span><span style="color: #007700;">[</span><span style="color: #0000bb;">0</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$imageheight </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$image_stats</span><span style="color: #007700;">[</span><span style="color: #0000bb;">1</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$img_type </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$image_stats</span><span style="color: #007700;">[</span><span style="color: #0000bb;">2</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$new_w </span><span style="color: #007700;">= </span><span style="color: #0000bb;">100</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$ratio </span><span style="color: #007700;">= (</span><span style="color: #0000bb;">$imagewidth </span><span style="color: #007700;">/ </span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$new_h </span><span style="color: #007700;">= </span><span style="color: #0000bb;">round</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$imageheight </span><span style="color: #007700;">/ </span><span style="color: #0000bb;">$ratio</span><span style="color: #007700;">);</span></span></code></p>
<p><span style="color: #ff8000;">// Find out if we need to resize it by checking to<br />
// see if the original image is larger than the<br />
// defined new width, and making sure the<br />
// resized version does not exist yet</span></p>
<p><span style="color: #007700;">if ((</span><span style="color: #0000bb;">$imagewidth </span><span style="color: #007700;">&gt; </span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">)&amp;&amp; (!</span><span style="color: #0000bb;">file_exists</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">))) {</span></p>
<p><span style="color: #ff8000;">// if this is a jpeg, resize as a jpeg<br />
</span><span style="color: #007700;">if (</span><span style="color: #0000bb;">$img_type</span><span style="color: #007700;">==</span><span style="color: #0000bb;">2</span><span style="color: #007700;">) {</span></p>
<p><span style="color: #0000bb;">$src_img </span><span style="color: #007700;">= </span><span style="color: #0000bb;">imagecreatefromjpeg</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$dst_img </span><span style="color: #007700;">= </span><span style="color: #0000bb;">imagecreate</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_h</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">imagecopyresized</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_h</span><span style="color: #007700;">,</span><span style="color: #0000bb;">imagesx</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">),</span><span style="color: #0000bb;">imagesy</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">));<br />
</span><span style="color: #0000bb;">imagejpeg</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);</span></p>
<p>} elseif (<span style="color: #0000bb;">$img_type</span><span style="color: #007700;">==</span><span style="color: #0000bb;">3</span><span style="color: #007700;">) {<br />
</span><span style="color: #ff8000;">// if image is a png, copy it</span></p>
<p><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">=</span><span style="color: #0000bb;">ImageCreate</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_h</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">=</span><span style="color: #0000bb;">ImageCreateFrompng</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">ImageCopyResized</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_h</span><span style="color: #007700;">,</span><span style="color: #0000bb;">ImageSX</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">),</span><span style="color: #0000bb;">ImageSY</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">));<br />
</span><span style="color: #0000bb;">Imagepng</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);</span></p>
<p><span style="color: #ff8000;">// Normally if image is neither png nor jpeg<br />
// (ie, invalid image or a gif file), I use<br />
// the fullsize as the thumbnail and just<br />
// resize it through the html size tags. For this<br />
// example tho, weâ€™ll pretend we have a version of<br />
// Gdlib that can handle gif resizing</span></p>
<p><span style="color: #007700;">} elseif (</span><span style="color: #0000bb;">$img_type</span><span style="color: #007700;">==</span><span style="color: #0000bb;">1</span><span style="color: #007700;">) {</span></p>
<p><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">=</span><span style="color: #0000bb;">ImageCreate</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_h</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">=</span><span style="color: #0000bb;">ImageCreateFromGif</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">ImageCopyResized</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">0</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_w</span><span style="color: #007700;">,</span><span style="color: #0000bb;">$new_h</span><span style="color: #007700;">,</span><span style="color: #0000bb;">ImageSX</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">),</span><span style="color: #0000bb;">ImageSY</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$src_img</span><span style="color: #007700;">));<br />
</span><span style="color: #0000bb;">ImageGif</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$dst_img</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$path</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$photo_filename</span><span style="color: #007700;">);</span></p>
<p>} else {<br />
<span style="color: #ff8000;">// if it doesnâ€™t show up as any of the valid formats, give an error<br />
</span><span style="color: #007700;">echo </span><span style="color: #dd0000;">&#8216;error&#8217;</span><span style="color: #007700;">;</span></p>
<p>} <span style="color: #ff8000;">// endif img_type sequence</span></p>
<p><span style="color: #007700;">}</span></p>
<p><span style="color: #0000bb;">?&gt; </span></p>


<p>Possibly related posts:<ol><li><a href='http://www.snipe.net/2004/06/cropped-thumbnails-using-php-and-the-gd-library/' rel='bookmark' title='Permanent Link: Cropped Thumbnails using PHP and the GD Library'>Cropped Thumbnails using PHP and the GD Library</a> <small>This code will allow you to create a thumbnail from...</small></li>
<li><a href='http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-imagemagick/' rel='bookmark' title='Permanent Link: Dynamic thumbnailing with PHP and Imagemagick'>Dynamic thumbnailing with PHP and Imagemagick</a> <small>This code formatting is a little off, since the WYSIWG...</small></li>
<li><a href='http://www.snipe.net/2004/06/dynamic-watermarkstext-overlay-on-images-in-php/' rel='bookmark' title='Permanent Link: Dynamic Watermarks/Text Overlay on Images in PHP'>Dynamic Watermarks/Text Overlay on Images in PHP</a> <small>This code can be useful for a number of things,...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-the-gd-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic thumbnailing with PHP and Imagemagick</title>
		<link>http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-imagemagick/</link>
		<comments>http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-imagemagick/#comments</comments>
		<pubDate>Sun, 27 Jun 2004 15:11:50 +0000</pubDate>
		<dc:creator>snipe</dc:creator>
				<category><![CDATA[PHP/mySQL]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.snipe.net/?p=134</guid>
		<description><![CDATA[This code formatting is a little off, since the WYSIWG editor seems to have eaten part of it. Sorry. &#60;?php /* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- */ /* &#8212;&#8212;&#8212;&#8212; BEGIN PHP SNIPPET &#8212;&#8212;&#8212;&#8212;&#8212;-*/ /* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- */ // specify your file details $current_file = &#8220;image.jpg&#8221;; $max_width = &#8220;150&#8243;; // get the current info on the file $current_size = getimagesize($current_file); $current_img_width [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fdynamic-thumbnailing-with-php-and-imagemagick%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.snipe.net%2F2004%2F06%2Fdynamic-thumbnailing-with-php-and-imagemagick%2F&amp;source=snipeyhead&amp;style=normal&amp;service=bit.ly&amp;service_api=R_92bd97f4f8b9fa8a40675b36ea291223" height="61" width="50" /><br />
			</a>
		</div>
<p>This code formatting is a little off, since the WYSIWG editor seems to have eaten part of it. Sorry.</p>
<p><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php</span></span></code></p>
<p><span style="color: #ff8000;">/* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- */<br />
/* &#8212;&#8212;&#8212;&#8212; BEGIN PHP SNIPPET &#8212;&#8212;&#8212;&#8212;&#8212;-*/<br />
/* &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- */<br />
// specify your file details<br />
</span><span style="color: #0000bb;">$current_file </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;image.jpg&#8221;</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$max_width </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;150&#8243;</span><span style="color: #007700;">;</span></p>
<p><span style="color: #ff8000;">// get the current info on the file<br />
</span><span style="color: #0000bb;">$current_size </span><span style="color: #007700;">= </span><span style="color: #0000bb;">getimagesize</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$current_file</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$current_img_width </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$current_size</span><span style="color: #007700;">[</span><span style="color: #0000bb;">0</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$current_img_height </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$current_size</span><span style="color: #007700;">[</span><span style="color: #0000bb;">1</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$image_base </span><span style="color: #007700;">= </span><span style="color: #0000bb;">explode</span><span style="color: #007700;">(</span><span style="color: #dd0000;">&#8220;.&#8221;</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$current_file</span><span style="color: #007700;">);</span></p>
<p><span style="color: #ff8000;">// this part gets the new thumbnail name<br />
</span><span style="color: #0000bb;">$image_basename </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$image_base</span><span style="color: #007700;">[</span><span style="color: #0000bb;">0</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$image_ext </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$image_base</span><span style="color: #007700;">[</span><span style="color: #0000bb;">1</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$thumb_name </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$image_basename</span><span style="color: #007700;">.</span><span style="color: #dd0000;">&#8220;-th.&#8221;</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$image_ext</span><span style="color: #007700;">;</span></p>
<p><span style="color: #ff8000;">// determine if the image actually needs to be resized<br />
// and if it does, get the new height for it<br />
</span><span style="color: #007700;">if (</span><span style="color: #0000bb;">$current_img_width </span><span style="color: #007700;">&gt; </span><span style="color: #0000bb;">$max_width</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">$too_big_diff_ratio </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$current_img_width</span><span style="color: #007700;">/</span><span style="color: #0000bb;">$max_width</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$new_img_width </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$max_width</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$new_img_height </span><span style="color: #007700;">= </span><span style="color: #0000bb;">round</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$current_img_height</span><span style="color: #007700;">/</span><span style="color: #0000bb;">$too_big_diff_ratio</span><span style="color: #007700;">);</span></p>
<p><span style="color: #ff8000;">// presto chango alacazam<br />
</span><span style="color: #0000bb;">$make_magick </span><span style="color: #007700;">= </span><span style="color: #0000bb;">system</span><span style="color: #007700;">(</span><span style="color: #dd0000;">&#8220;convert -geometry $new_img_width x $new_img_height $current_file $thumb_name&#8221;</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$retval</span><span style="color: #007700;">);</span></p>
<p><span style="color: #ff8000;">// let us know if it worked or not<br />
</span><span style="color: #007700;">if (!(</span><span style="color: #0000bb;">$retval</span><span style="color: #007700;">)) {<br />
echo </span><span style="color: #dd0000;">&#8220;Thumbnail createdÂ Â -&#8221;</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$thumb_name</span><span style="color: #007700;">;<br />
} else {<br />
echo </span><span style="color: #dd0000;">&#8220;Oops &#8211; no dice! Script failed cuz your momma doesn&#8217;t love you.&#8221;</span><span style="color: #007700;">;<br />
}<br />
} else {<br />
echo </span><span style="color: #dd0000;">&#8220;No need to resize! You&#8217;re perfect just the way you are.&#8221;</span><span style="color: #007700;">;<br />
}</span></p>
<p><span style="color: #0000bb;">?&gt;</span></p>


<p>Possibly related posts:<ol><li><a href='http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-the-gd-library/' rel='bookmark' title='Permanent Link: Dynamic thumbnailing with PHP and the GD library'>Dynamic thumbnailing with PHP and the GD library</a> <small>Although there are loads of ways you can do this,...</small></li>
<li><a href='http://www.snipe.net/2004/06/dynamic-watermarkstext-overlay-on-images-in-php/' rel='bookmark' title='Permanent Link: Dynamic Watermarks/Text Overlay on Images in PHP'>Dynamic Watermarks/Text Overlay on Images in PHP</a> <small>This code can be useful for a number of things,...</small></li>
<li><a href='http://www.snipe.net/2009/10/mini-site-facebook-static-fbml/' rel='bookmark' title='Permanent Link: Extending Facebook Static FBML Tabs with Dynamic Content'>Extending Facebook Static FBML Tabs with Dynamic Content</a> <small>This tutorial walks you through how to use DynamicFBML to...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.snipe.net/2004/06/dynamic-thumbnailing-with-php-and-imagemagick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
