<?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>Short Like A Fox &#187; jpeg</title>
	<atom:link href="http://shortlikeafox.com/tag/jpeg/feed/" rel="self" type="application/rss+xml" />
	<link>http://shortlikeafox.com</link>
	<description>They Say I'm Short...</description>
	<lastBuildDate>Wed, 29 Jul 2009 22:21:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Divide One Image Into Multiple Images Using PHP</title>
		<link>http://shortlikeafox.com/2008/08/26/how-to-divide-one-image-into-multiple-images-using-php/</link>
		<comments>http://shortlikeafox.com/2008/08/26/how-to-divide-one-image-into-multiple-images-using-php/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 06:27:07 +0000</pubDate>
		<dc:creator>ShortLikeAFox</dc:creator>
				<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[jpeg]]></category>

		<guid isPermaLink="false">http://shortlikeafox.com/?p=80</guid>
		<description><![CDATA[ So you want to break one large image into multiple smaller images? No problem. This may seem like an obscure problem, but there are multiple reasons you&#8217;d want to do this. Maybe you want to create a visual sliding puzzle.  Or maybe you are running a unique WordPress theme. Or maybe you want [...]]]></description>
			<content:encoded><![CDATA[<!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	--><div style='float:right'><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://shortlikeafox.com/2008/08/26/how-to-divide-one-image-into-multiple-images-using-php/&amp;t=How+to+Divide+One+Image+Into+Multiple+Images+Using+PHP&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><p>So you want to break one large image into multiple smaller images? No problem. This may seem like an obscure problem, but there are multiple reasons you&#8217;d want to do this. Maybe you want to create a visual <a href="http://en.wikipedia.org/wiki/Sliding_puzzle" target="_blank">sliding puzzle</a>.  Or maybe you are running a <a href="http://wp-themes.com/3col-rdmban-rr/" target="_blank">unique WordPress theme</a>. Or maybe you want to create a collage of some kind. It really doesn&#8217;t matter why you want to split an image into smaller image, PHP makes this task easy. The example below only deals with jpegs. Changing the function to deal with other types of images wouldn&#8217;t be that hard.</p>
<p>&nbsp;</p>
<p><span class="style1">&lt;?php</span><br />
  <span class="style9">//This function will split an image into a number of equally sized columns and rows.<br />
  </span><span class="style3">function</span> split_image($number_of_rows, $number_of_cols, $path_to_image, $file_name){ </p>
<p class="style9"> //$number_of_rows = # of rows you want; <br />
  //$number_of_cols = # of cols you wnat<br />
  //$path_to_image = the path to the folder the image is in, something like: 	/home/content/username/html/list/uploads/ <br />
//$file_name = The filename of the image: archery.jpg, etc.</p>
<p> <span class="style9">// parse path for the extension</span><br />
  $info = <span class="style3">pathinfo</span>($path_to_image <span class="style3">.</span> $file_name);
</p>
<p> <span class="style9">//make sure we are dealing with a jpeg<br />
</span>  <span class="style4">if</span> ( (<span class="style3">strtolower</span>($info[<span class="style1">'extension'</span>]) == <span class="style1">&#8216;jpg&#8217;</span>) || (<span class="style3">strtolower</span>($info[<span class="style1">'extension'</span>]) == <span class="style1">&#8216;jpeg&#8217;</span>) ){</p>
<blockquote>
<p> <span class="style9">// load image and get image size</span><br />
    $source = <span class="style3">imagecreatefromjpeg</span>( <span class="style1">&quot;{$path_to_image}{$file_name}&quot;</span> );<br />
    $width = <span class="style3">imagesx</span>( $source ); <span class="style9">//Find the width</span> <br />
    $height = <span class="style3">imagesy</span>( $source ); <span class="style9">//Find the height</span> <br />
    $segment_width = $width/$number_of_cols; <span class="style9">//Determine the width of the individual segments</span> <br />
    $segment_height = $height/$number_of_rows; <span class="style9">//Determine the height of the individual segments</span> </p>
<p>    <span class="style4">for</span>( $col = 0; $col &lt; $number_of_cols; $col++)<br />
    {
    </p>
<blockquote>
<p><span class="style4">for</span>( $row = 0; $row &lt; $number_of_rows; $row++)<br />{
    </p>
<blockquote>
<p>$fn =<span class="style3"> sprintf</span>( <span class="style1">&quot;img%02d_%02d.jpg&quot;</span>, $col, $row );<br/><span class="style3">echo</span>(<span class="style1"> &quot;$fn&quot;</span> ); <span class="style9">//I print the image name here, so that the process shows itself as it runs<br />
      </span>$im = <span class="style3">@imagecreatetruecolor</span>( $segment_width, $segment_height );<br />
        <span class="style3">imagecopyresized</span>( $im, $source, 0, 0, $col * $segment_width, $row * $segment_height, $segment_width, $segment_height, $segment_width, $segment_height );<br />
$file = <span class="style1">&quot;test.jpg&quot;</span>;<br />
<span class="style9">//Save the images </span><br />
  if(<span class="style3">imagejpeg</span>( $im,<span class="style1">&quot;INSERT DESTINATION HERE &quot;</span>, 100 )) <span class="style9">//The destination will be something like</span><span class="style9">/home/content/c/h/d/images/$fn</span>
      </p>
<blockquote>
<p>echo(<span class="style1">&quot;Has been made!&lt;br/&gt;&quot;</span>);
          </p>
</blockquote>
<p>}
        </p>
</blockquote>
<p>}      </p>
</blockquote>
<p>}</p>
</blockquote>
<p>}</p>
<p><span class="style1">?&gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://shortlikeafox.com/2008/08/26/how-to-divide-one-image-into-multiple-images-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
