<?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>All About Web &#38; Mobile Application Development &#187; prototype</title>
	<atom:link href="http://www.londatiga.net/tag/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.londatiga.net</link>
	<description>All About Web &#38; Mobile Application Development</description>
	<lastBuildDate>Sat, 14 Jan 2012 16:56:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to Crop Image Using JavaScript and PHP</title>
		<link>http://www.londatiga.net/it/how-to-crop-image-using-javascript-and-php/</link>
		<comments>http://www.londatiga.net/it/how-to-crop-image-using-javascript-and-php/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 00:46:01 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[image crop]]></category>
		<category><![CDATA[image crop guide]]></category>
		<category><![CDATA[image crop howto]]></category>
		<category><![CDATA[image crop javascript]]></category>
		<category><![CDATA[image crop php]]></category>
		<category><![CDATA[image crop tutorial]]></category>
		<category><![CDATA[image cropping]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php GD]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=250</guid>
		<description><![CDATA[Image cropping is a usefull feature in web application that allows user to crop an image on a web page and save it for later use. This feature is commonly used in user&#8217;s preferences tool for creating a profile image. User uploads an image from his local hardrive and then directly crop his desired part [...]]]></description>
			<content:encoded><![CDATA[<p>Image cropping is a usefull feature in web application that allows user to crop an image on a web page and save it for later use. This feature is commonly used in user&#8217;s preferences tool for creating a profile image. User uploads an image from his local hardrive and then directly crop his desired part  for used as his profile image without using an image editing software.</p>
<div class="wp-caption alignnone" style="width: 510px"><img title="Image Cropping" src="http://londatiga.net/images/imagecropping/imagecropping.jpg" alt="Image Cropping" width="500" height="375" /><p class="wp-caption-text">Image Cropping</p></div>
<p>Image cropping process can be separated into two separated process. The first process is  for acquaring  coordinates and dimensions of selected area of an image, which will be done in client side using JavaScript. The next is  process for creating a new image based on coordinates and dimensions from previously cropping process using PHP on server side. In this tutorial, i&#8217;ll use JavaScript <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/comment-page-27/" target="_blank">Image Cropper</a> library by David Spurr and PHP GD image processing functions.</p>
<p><strong>Client Side</strong></p>
<p>Image Cropper is an excellent JavaScript library written by David Spurr that makes image cropping easier. It allows us to crop an image using an interface with the same features and styling as found in commercial image editing software. It is based on <a href="http://www.prototypejs.org/" target="_blank">Prototype</a> JavaScript Framework and <a href="http://script.aculo.us/" target="_blank">Scriptaculous</a>.</p>
<p><span style="text-decoration: underline;">How to Setup</span></p>
<ol>
<li>Download the required library files</li>
<p>- <a href="http://www.prototypejs.org/download">Prototype Javascript Framework</a></p>
<p>- <a href="http://script.aculo.us/downloads">Scriptaculous (scriptaculous-js-1.8.3.zip)</a></p>
<p>- <a href="http://www.defusion.org.uk/code/javascript-image-cropper-ui-using-prototype-scriptaculous/download-zip/" target="_blank">Image Cropper (jsCropperUI-1.2.1.zip)</a></p>
<li>Extract <span style="color: #800000;">scriptaculous-js-1.8.3.zip <span style="color: #000000;"> </span></span> and copy <span style="color: #800000;">scriptaculous.js</span>, <span style="color: #800000;">builder.js</span>, <span style="color: #800000;">effect.js</span> and <span style="color: #800000;">dragdrop.js</span> from the extracted files into your web application directory.</li>
<li>Extract <span style="color: #800000;">jsCropperUI-1.2.1.zip</span> and copy <span style="color: #800000;">cropper.js, marqueeHoriz.gif, marqueeVert.gif, cropper.css</span> from the extracted files into your web application directory (  must reside in the same directory).</li>
<li>Include <span style="color: #800000;">Prototype.js</span>, <span style="color: #800000;">scriptaculous.js <span style="color: #000000;">and</span> </span><span style="color: #800000;">cropper.j</span><span style="color: #800000;">s</span> in the HEAD section of your HTML file.
<pre class="brush: xml; title: ;">
&lt;script src=&quot;scripts/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;scripts/scriptaculous.js?load=effects,builder,dragdrop&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;scripts/cropper.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
</li>
</ol>
<p><span style="text-decoration: underline;">Using Image Cropper Library</span></p>
<p><span style="text-decoration: underline;">With  Dynamic Crop Preview</span></p>
<pre class="brush: jscript; title: ;">
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
Event.observe (
	window,
	'load',
	function() {
		new Cropper.ImgWithPreview(
			't3soeta',
			{
				minWidth: 200,
				minHeight: 100,
                ratioDim: { x: 200, y: 100 },
				displayOnInit: true,
				onEndCrop: saveCoords,
                onloadCoords: { x1: 0, y1: 0, x2: 200, y2: 100 },
                previewWrap: 'preview'
			}
		)
	}
);

function saveCoords (coords, dimensions)
{
	$( 'x1' ).value = coords.x1;
	$( 'y1' ).value = coords.y1;
	$( 'width' ).value = dimensions.width;
	$( 'height' ).value = dimensions.height;
}
&lt;/script&gt;

&lt;form action=&quot;saveCrop.php&quot; method=&quot;post&quot;&gt;
&lt;div style=&quot;width:750px&quot;&gt;
    &lt;div style=&quot;float:left&quot;&gt;
        &lt;img src=&quot;images/t3soeta.jpg&quot; id=&quot;t3soeta&quot; width=&quot;500&quot; height=&quot;375&quot; /&gt;
    &lt;/div&gt;
    &lt;div id=&quot;preview&quot; style=&quot;float:right;&quot;&gt;&lt;/div&gt;
    &lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;x1&quot; id=&quot;x1&quot; value=&quot;&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;y1&quot; id=&quot;y1&quot; value=&quot;&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;width&quot; id=&quot;width&quot; value=&quot;&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;height&quot; id=&quot;height&quot; value=&quot;&quot;&gt;
&lt;/div&gt;
&lt;input type=&quot;submit&quot; name=&quot;Done&quot; value=&quot; Done &quot;&gt;
&lt;/form&gt;
</pre>
<p><strong>Line 06:</strong> Instantiate Image Cropper class.</p>
<p><strong>Line 07:</strong> Image Id.</p>
<p><strong>Line 09:</strong> <span style="color: #800000;">minWidth</span>, is the minimum width for  selected area in pixels.</p>
<p><strong>Line 10</strong>: <span style="color: #800000;">minHeight</span>, is the minimum height for selected area in pixels.</p>
<p><strong>Line 11:</strong> <span style="color: #800000;">ratioDim</span>, is the pixel dimensions to apply as a restrictive ratio, with properties x &amp; y.</p>
<p><strong>Line 12: </strong><span style="color: #800000;">displayOnInit</span>, whether display the selected area on initialisation. If set to <span style="color: #800000;">true</span>, <span style="color: #800000;">minWidth</span> and <span style="color: #800000;">minHeight</span> or <span style="color: #800000;">ratioDim</span> must be provided.</p>
<p><strong>Line 13:</strong> o<span style="color: #800000;">nEndCrop</span>, a callback function which will be called when user finished a crop movement. The function takes two arguments:</p>
<ul>
<li>coords, is the coordinates of selected area with properties <span style="color: #800000;">x1</span>, <span style="color: #800000;">y1</span>, <span style="color: #800000;">x2</span>,  <span style="color: #800000;">y2</span>.</li>
<li>dimensions , is the dimensions of selected area with properties <span style="color: #800000;">w</span><span style="color: #800000;">idth</span> and<span style="color: #800000;"> height</span>.</li>
</ul>
<p>On example above (Line 21), coordinates and dimensions are stored in hidden elements and will be sent to server side script (<span style="color: #800000;">s</span><span style="color: #800000;">aveCrop.php</span>) using HTTP POST method for later processing .</p>
<p><strong>Line 14: </strong><span style="color: #800000;">onloadCoords<span style="color: #000000;">, is the coordinates of the selected area to display onload</span></span></p>
<p><strong>Line 15: </strong><span style="color: #800000;">previewWra</span><span style="color: #800000;">p</span>, is the id of container for image crop preview.</p>
<p><strong>Line 21: </strong>callback function, as set on <span style="color: #800000;">onEndCrop</span> option (Line 13).</p>
<p><strong>Line 33:</strong> image to be cropped, it&#8217;s id must match the id set on Line 07.</p>
<p><strong>Line 35: </strong>div container for image crop preview.</p>
<p><strong>Line 37-40</strong>: Hidden elements to store coordinates and dimensions of selected area.</p>
<p>View live demo <a title="Image Cropping" href="http://londatiga.net/tutorials/imagecrop/example.html" target="_blank">here</a></p>
<p><span style="text-decoration: underline;">Without Dynamic Crop Preview</span></p>
<p>For using Image Cropper without dynamic preview, change the class from <span style="color: #800000;">Cropper.ImgWithPrevie</span><span style="color: #800000;">w</span> to <span style="color: #800000;">Cropper.Img<span style="color: #000000;"> and remove the <span style="color: #800000;">previewWrap</span> option.</span></span></p>
<pre class="brush: jscript; title: ;">
Event.observe (
	window,
	'load',
	function() {
		new Cropper.Img (
			't3soeta',
			{
				minWidth: 200,
				minHeight: 100,
                ratioDim: { x: 200, y: 100 },
				displayOnInit: true,
				onEndCrop: saveCoords,
                onloadCoords: { x1: 0, y1: 0, x2: 200, y2: 100 },
			}
		)
	}
);
</pre>
<p><span style="color: #800000;"><span style="color: #000000;">View live demo <a title="Image Cropping" href="http://londatiga.net/tutorials/imagecrop/example2.html" target="_blank">here</a></span></span></p>
<p><span style="color: #800000;"><span style="color: #000000;"><strong>Server Side</strong></span></span></p>
<p>On server side, image is processed using PHP GD image functions, which required GD library installed.</p>
<pre class="brush: php; title: ;">
&lt;?php
$x1      = $_POST['x1'];
$y1      = $_POST['y1'];
$width   = $_POST['width'];
$height  = $_POST['height'];

$srcImg  = imagecreatefromjpeg('images/t3soeta.jpg');
$newImg  = imagecreatetruecolor($width, $height);

imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height);

imagejpeg($newImg, 'images/cropped_t3soeta.jpg');
?&gt;
</pre>
<p><strong>Line 02-05: </strong>get coordinates and dimensions sent from client.</p>
<p><strong>Line 07:</strong> create source image</p>
<p><strong>Line 08:</strong> create a new true color image for cropped image</p>
<p><strong>Line 10:</strong> copy selected area from source image into new image using coordinates and dimensions sent from client.</p>
<p><strong>Line 12</strong>: Output the new cropped image into a file.</p>
<div style="padding:10px;background:#2dd354;"><a title="Download image crop demo source code" href="http://londatiga.net/downloads/tutorial/imagecrop.zip" target="_self">Download Example Source Code</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/how-to-crop-image-using-javascript-and-php/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Prototype: Using Ajax.Updater to Update Browser&#8217;s DOM Element</title>
		<link>http://www.londatiga.net/it/prototype-using-ajax-updater-to-update-browsers-dom-element/</link>
		<comments>http://www.londatiga.net/it/prototype-using-ajax-updater-to-update-browsers-dom-element/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 18:12:59 +0000</pubDate>
		<dc:creator>lorenz</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax.updater]]></category>
		<category><![CDATA[browser dom update]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[dom update after ajax request]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[update dom]]></category>

		<guid isPermaLink="false">http://www.londatiga.net/?p=139</guid>
		<description><![CDATA[Ajax has become popular since it allows web application to behave interactively like a desktop application. It allows asynchronous communication between client (browser) and server so web applications can retrieve data from server  in the background without interfering with the display and behavior of the existing page.
There are some javascript frameworks available over internet that help [...]]]></description>
			<content:encoded><![CDATA[<p>Ajax has become popular since it allows web application to behave interactively like a desktop application. It allows asynchronous communication between client (browser) and server so web applications can retrieve data from server  in the background without interfering with the display and behavior of the existing page.</p>
<p>There are some javascript frameworks available over internet that help us to build web application easier using ajax like Prototype,  Jquery,  Dojo, etc.  For me, i prefer to use prototype because of  it&#8217;s functionality and easy to use. I&#8217;ve been using Prototype for over one year and feel comfort with it.</p>
<p>In ajax programming, we often use ajax to update parts within HTML page with the data retrived from server where in prototype i use <strong>Ajax.Request</strong> function to handle it.  But in some cases,  if  our ajax response data  contains other java script code,  and we want the script to work after the response, it won&#8217;t work.  It happens because the browser&#8217;s DOM is not updated with the newly retrieved script from ajax response. To overcome this problem, we can use <strong>Ajax.Updater</strong> function that&#8217;s a spesialization of Ajax.Request function.</p>
<p>The function:</p>
<blockquote><p><strong>new Ajax.Updater(container, url[, options])</strong></p></blockquote>
<p>where <em>container</em> is the HTML part to be updated and <em>url </em>is url to server side script.</p>
<p>Options:</p>
<table border="0">
<tbody>
<tr>
<td width="100"><strong>Options</strong></td>
<td width="100"><strong>Default</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td style="width: 100px;">evalScripts</td>
<td>false</td>
<td>This determines whether <code>&lt;script&gt;</code> elements in the response  text are evaluated or not.By default, <a><code>Element.update</code></a> is  used, which replaces the whole contents of the container with the response text</td>
</tr>
<tr>
<td>insertion</td>
<td>None</td>
<td>As of Prototype 1.6.0, this notation is deprecated. Simply pass either  <code>'top'</code>, <code>'bottom'</code>, <code>'before'</code> or  <code>'after'</code> as a string instead</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<pre class="brush: jscript; title: ;">
var url = 'ajax.php';

var myAjax = new Ajax.Updater('datadiv', url, {
      method: 'get',
      evalScripts: true,

      onSuccess: function(transport) {},

      onFailure: function(transport) {
           alert('Transport error!');
       }
 });
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.londatiga.net/it/prototype-using-ajax-updater-to-update-browsers-dom-element/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

