<?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; codeigniter</title>
	<atom:link href="http://sandbox.ronggur.com/tag/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://sandbox.ronggur.com</link>
	<description>Ronggur Hutasuhut Playground</description>
	<lastBuildDate>Thu, 15 Apr 2010 08:53:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 view
1. Controller
Create controller and named it &#8220;preview&#8221;, we also need function in it to call [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/' onclick="pageTracker._trackPageview('/outgoing/mitcho.com/code/yarpp/?referer=');">Yet Another Related Posts Plugin</a>.]]></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;">

&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;">

&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 105 times" >Image on the fly with codeigniter (105)</a></li>
</ul>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="pageTracker._trackPageview('/outgoing/blinklist.com/index.php?Action=Blink/addblink.php_amp_Name=How+to+generate+image+on+the+fly+with+codeIgniter_amp_Description=How+to+generate+image+on+the+fly+with+codeIgniter_amp_Url=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://blinklist.com/index.php?Action=Blink/addblink.php&amp;Name=How+to+generate+image+on+the+fly+with+codeIgniter&amp;Description=How+to+generate+image+on+the+fly+with+codeIgniter&amp;Url=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F" rel="nofollow" title="Add to&nbsp;BlinkList"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/blinklist.png" title="Add to&nbsp;BlinkList" alt="Add to&nbsp;BlinkList" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/www.bloglines.com/sub/http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F?referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F" rel="nofollow" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/del.icio.us/post?url=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F_amp_title=How+to+generate+image+on+the+fly+with+codeIgniter&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F&amp;title=How+to+generate+image+on+the+fly+with+codeIgniter" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/digg.com/submit?phase=2_amp_url=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F_amp_title=How+to+generate+image+on+the+fly+with+codeIgniter&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F&amp;title=How+to+generate+image+on+the+fly+with+codeIgniter" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/www.facebook.com/sharer.php?u=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/www.google.com/bookmarks/mark?op=edit_amp_output=popup_amp_bkmk=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F_amp_title=How+to+generate+image+on+the+fly+with+codeIgniter&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F&amp;title=How+to+generate+image+on+the+fly+with+codeIgniter" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/www.stumbleupon.com/submit?url=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F_amp_title=How+to+generate+image+on+the+fly+with+codeIgniter&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F&amp;title=How+to+generate+image+on+the+fly+with+codeIgniter" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/www.technorati.com/faves?add=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="pageTracker._trackPageview('/outgoing/myweb2.search.yahoo.com/myresults/bookmarklet?u=http_3A_2F_2Fsandbox.ronggur.com_2F2009_2F11_2F20_2Fhow-to-generate-image-on-the-fly-with-codegniter_2F_amp_t=How+to+generate+image+on+the+fly+with+codeIgniter&amp;referer=');window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsandbox.ronggur.com%2F2009%2F11%2F20%2Fhow-to-generate-image-on-the-fly-with-codegniter%2F&amp;t=How+to+generate+image+on+the+fly+with+codeIgniter" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sandbox.ronggur.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/' onclick="pageTracker._trackPageview('/outgoing/mitcho.com/code/yarpp/?referer=');">Yet Another Related Posts Plugin</a>.</p>]]></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>
