<?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>MySandbox &#187; php</title>
	<atom:link href="http://sandbox.ronggur.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://sandbox.ronggur.com</link>
	<description>Ronggur Hutasuhut Playground</description>
	<lastBuildDate>Mon, 31 Oct 2011 10:39: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>
		<item>
		<title>How to generate image on the fly with codeIgniter</title>
		<link>http://sandbox.ronggur.com/2009/11/20/how-to-generate-image-on-the-fly-with-codegniter/</link>
		<comments>http://sandbox.ronggur.com/2009/11/20/how-to-generate-image-on-the-fly-with-codegniter/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 16:45:27 +0000</pubDate>
		<dc:creator>ronggur</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[feat]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://sandbox.ronggur.com/?p=165</guid>
		<description><![CDATA[This post is talking about how to generate image on the fly with codeigniter. This is the basic code and sure you can improve it as you far as you need, All we need is only 1 controller and 1 (&#8230;)</p><p><a href="http://sandbox.ronggur.com/2009/11/20/how-to-generate-image-on-the-fly-with-codegniter/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This post is talking about how to generate image on the fly with codeigniter. This is the basic code and sure you can improve it as you far as you need, All we need is only 1 controller and 1 view</p>
<h3>1. Controller</h3>
<p>Create controller and named it &#8220;preview&#8221;, we also need function in it to call the image class. See the script below</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php

class preview extends Controller {

function preview()
{
parent::Controller();
$this-&gt;load-&gt;helper('url');
}

function index($height='50',$width='50')
{

// we will need to pass the height and with of the image
$arr_data['height']    =    $height;
$arr_data['width']    =    $width;
$this-&gt;load-&gt;view('preview', $arr_data);
}

function get_photo($height,$width){
$path = [ absolute path to your image ex : /public-html/dock/image.jpg ];
$this-&gt;load-&gt;library('image_lib');
$imageinit['image_library']     = 'gd2';
$imageinit['quality']            = '90%'; // set quality
$imageinit['dynamic_output']    = true;     // set to true to generate it dynamically
$imageinit['source_image']         = $path;
$imageinit['maintain_ratio']     = false;
$imageinit['width']             = $width;
$imageinit['height']             = $height;
$this-&gt;image_lib-&gt;initialize($imageinit);
if(!$this-&gt;image_lib-&gt;resize()){
echo $this-&gt;image_lib-&gt;display_errors(); // print error if it fails
}
}
}

?&gt;
</pre>
<p>&#8220;get_photo&#8221; function is where we will generate the image dynamically. We call this function in &lt;img&gt; html tag in &#8220;view&#8221; file.</p>
<p><span id="more-165"></span></p>
<h3>2. View</h3>
<p>Here is the view code where we will call &#8220;get_photo&#8221; function</p>
<pre class="brush: php; title: ; notranslate">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Code Igniter : Image on the fly&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;img src=&quot;&lt;?php echo base_url().'index.php/preview/get_photo/'.$height.'/'.$width.'' ?&gt;&quot; title=&quot;image on the fly&quot; alt=&quot;image on the fly&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>That&#8217;s it</p>
<ul>
<li><a title="image on the fly with code igniter" href="http://demo.ronggur.com/citutorial/index.php/preview/get_photo/600/800" onclick="pageTracker._trackPageview('/outgoing/demo.ronggur.com/citutorial/index.php/preview/get_photo/600/800?referer=');">View demo</a></li>
<li>Download source (only controller and view) :  <a class="downloadlink" href="http://sandbox.ronggur.com/wp-content/plugins/download-monitor/download.php?id=7" title=" downloaded 240 times" >Image on the fly with codeigniter (240)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sandbox.ronggur.com/2009/11/20/how-to-generate-image-on-the-fly-with-codegniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: sandbox.ronggur.com @ 2012-02-04 23:11:08 -->
