<?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>The html blog &#187; ajax</title>
	<atom:link href="http://htmlblog.net/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://htmlblog.net</link>
	<description>The web sandbox of Asvin Balloo</description>
	<lastBuildDate>Tue, 09 Nov 2010 11:39:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Pixidou &#8211; an Open Source AJAX Image Editor (PHP and YUI based)</title>
		<link>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/</link>
		<comments>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 17:42:09 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[brightness]]></category>
		<category><![CDATA[contrast]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[flip]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[image editor]]></category>
		<category><![CDATA[negative]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[rotate]]></category>
		<category><![CDATA[tint]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=37</guid>
		<description><![CDATA[Pixidou is a new open source AJAX image editor which will allow you to : adjust brightness adjust contrast cropping flipping negative resizing rotating tint images. What you need to get running PHP5.2+ installed on your webserver GD2 a web browser Demo Installation Unzip/untar the software in your web directory and that&#8217;s all ;-) Also [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Pixidou </strong>is a new open source AJAX image editor which will allow you to :</p>
<ul>
<li>adjust brightness</li>
<li>adjust contrast</li>
<li>cropping</li>
<li>flipping</li>
<li>negative</li>
<li>resizing</li>
<li>rotating</li>
<li>tint</li>
</ul>
<p>images.<br />
<span id="more-37"></span><br />
<strong>What you need to get running</strong></p>
<ul>
<li>PHP5.2+ installed on your webserver</li>
<li>GD2</li>
<li>a web browser</li>
</ul>
<p><strong><a href="http://htmlblog.net/demo/pixidou">Demo</a></strong></p>
<p><strong>Installation</strong><br />
Unzip/untar the software in your web directory and that&#8217;s all ;-)<br />
Also ensure the images folder is writable by your webserver.<br />
Have fun !!!</p>
<p><strong>Download</strong><br />
<a href="http://github.com/asvinb/pixidou/tree/master" target="_blank">Get it and follow it at github</a></p>
<p>All the image manipulation is <a href="http://php.net">PHP-based</a> with the help of the great <a href="http://www.verot.net/php_class_upload.htm" target="_blank">class.upload.php</a> class by Colin Verot which I highly recommend.</p>
<p>The frontend is the most interesting part, where I&#8217;ve use the one and only <a href="http://developer.yahoo.com/yui">YUI library</a>. Here are the component I used (served from Yahoo CDN) :</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/reset/" target="_blank">reset-fonts.css</a> &#8211;  for all resetting, style information</li>
<li>utilities &#8211; for all AJAX, animation, drag drop, event handling stuff</li>
<li><a href="http://developer.yahoo.com/yui/container/" target="_blank">container</a> &#8211; for all panels, dialogs, alerts</li>
<li><a href="http://developer.yahoo.com/yui/menu/" target="_blank">menu</a> &#8211; for the top navigation menu together with the submenus</li>
<li><a href="http://developer.yahoo.com/yui/button/" target="_blank">button</a> &#8211; provides nice buttons</li>
<li><a href="http://developer.yahoo.com/yui/slider/" target="_blank">slider</a> &#8211; for adjusting contrast and brightness</li>
<li><a href="http://developer.yahoo.com/yui/colorpicker/" target="_blank">color picker</a> &#8211; to choose the color to tint the image</li>
<li><a href="http://developer.yahoo.com/yui/resize/" target="_blank">resize</a> &#8211; to resize the image</li>
<li><a href="http://developer.yahoo.com/yui/imagecropper/" target="_blank">image cropper</a> &#8211; image cropping utility</li>
<li><a href="http://developer.yahoo.com/yui/json/" target="_blank">json</a> &#8211; to parse all JSON data returned from PHP scripts</li>
<li><a href="http://developer.yahoo.com/yui/layout/" target="_blank">layout</a> &#8211; the general layout
<li>
<li><a href="http://developer.yahoo.com/yui/tabview/" target="_blank">tabview</a> &#8211; for the about information</li>
</ul>
<p>I&#8217;ve not used the <a href="http://developer.yahoo.com/yui/grids/">grids.css</a> since it caused some problems while using the color picker.</p>
<p>It&#8217;s only the beginning of <strong>Pixidou </strong>and I&#8217;am currently looking for some collaborators. So, if you think you can give a helping hand in any way to <strong>Pixidou</strong>, don&#8217;t hesitate to contact me (asvin.balloo [@] gmail.com), I&#8217;ll happily add you as a contributor to the repository on github.</p>
<p>Since it&#8217;s an early version, there must be some bugs lying everywhere, don&#8217;t hesitate to drop me an email.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>AJAX image cropper with YUI and PHP</title>
		<link>http://htmlblog.net/ajax-image-cropper-with-yui-and-php/</link>
		<comments>http://htmlblog.net/ajax-image-cropper-with-yui-and-php/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 11:01:55 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[image cropper]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=35</guid>
		<description><![CDATA[This post will show you how to build an AJAX crop image tool using the image cropper control from YUI library and PHP. The ImageCropper Control from the YUI library gives you an interactive interface for getting the dimensions to crop an image and using these dimensions in PHP, we can do some cropping. The [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to build an AJAX crop image tool using the image cropper control from YUI library and PHP.</p>
<p><span id="more-35"></span><br />
The <a href="http://developer.yahoo.com/yui/imagecropper/">ImageCropper Control</a> from the <a href="http://developer.yahoo.com/yui/">YUI library</a> gives you an interactive interface for getting the dimensions to crop an image and using these dimensions in <a href="http://php.net">PHP</a>, we can do some cropping.</p>
<p>The script we are going to build will </p>
<ul>
<li>allow users to upload an image via AJAX</li>
<li>then allow them to select an area for cropping</li>
<li>lastly, provide a download link for the cropped image.</li>
</ul>
<p>There are 3 files we are going to use </p>
<ul>
<li>index.php &#8211; will contain the form for image upload as well as the cropping interface</li>
<li>upload.php &#8211; provides uploading functionality</li>
<li>crop.php &#8211; provides cropping functionality</li>
</ul>
<p>From a technical point of view, the flow will be like this :</p>
<ol>
<li>user uploads jpg image (index.php)</li>
<li>index.php then posts the image asynchronously to upload.php which will do the upload on the server, returning JSON data containing the image file name, its width and its height.</li>
<li>with the JSON data and innerHTML we put the image in our page</li>
<li>initialize the javascript cropping tool</li>
<li>generate a download link (crop.php)</li>
</ol>
<p><strong><br />
Let&#8217;s have a look at index.php</strong><br />
The index.php is our main file where users will be able upload images and then download the cropped ones. </p>
<p>We&#8217;ll need the following components from the YUI library :</p>
<ul>
<li>yahoo-dom-event.js &#8211; for DOM manipulation and Event handling</li>
<li>dragdrop &#8211; dependency for the image cropper control</li>
<li>element &#8211; dependency for the image cropper control</li>
<li>resize &#8211; dependency for the image cropper control</li>
<li>connection &#8211; for AJAX requests, in our case for image uploads via AJAX</li>
<li>json &#8211; for parsing JSON data</li>
<li>imagecropper &#8211; our most important control</li>
</ul>
<p>Of course we&#8217;ll use <a href="http://developer.yahoo.com/yui/articles/hosting/">Yahoo combo handling</a> and add the js to our page along with the CSS needed for the above controls :</p>
<pre class="brush: xhtml">
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://yui.yahooapis.com/2.5.2/build/resize/assets/skins/sam/resize.css&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://yui.yahooapis.com/2.5.2/build/imagecropper/assets/skins/sam/imagecropper.css&quot; /&gt;
&lt;!-- js --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/dragdrop/dragdrop-min.js&amp;2.5.2/build/element/element-beta-min.js&amp;2.5.2/build/resize/resize-beta-min.js&amp;2.5.2/build/imagecropper/imagecropper-beta-min.js&amp;2.
5.2/build/connection/connection-min.js&amp;2.5.2/build/json/json-min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Next users must be able to upload images via AJAX, so we add a form to our page:</p>
<pre class="brush: xhtml">
&lt;form action=&quot;upload.php&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot; name=&quot;uploadForm&quot; id=&quot;uploadForm&quot;&gt;
	Image : &lt;input type=&quot;file&quot; name=&quot;uploadImage&quot; id=&quot;uploadImage&quot; /&gt;
	&lt;input type=&quot;button&quot; id=&quot;uploadButton&quot; value=&quot;Upload&quot;/&gt;
&lt;/form&gt;
</pre>
<p>We have an onclick event to the upload button to fire the uploading process.</p>
<pre class="brush: javascript">
// add listeners
YAHOO.util.Event.on(&#039;uploadButton&#039;, &#039;click&#039;, uploader.carry);
</pre>
<p>We&#8217;ll also need 2 containers :</p>
<ul>
<li>imageContainer &#8211; will contain our uploaded image</li>
<li>downloadLink &#8211; will contain the download link</li>
</ul>
<pre class="brush: xhtml">
&lt;div id=&quot;imageContainer&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;downloadLink&quot;&gt;&lt;/div&gt;
</pre>
<p>Both containers will be updated via innerHTML afterwards.</p>
<h3>AJAX upload</h3>
<p>For the AJAX upload, <a href="http://thecodecentral.com/2007/09/04/asynchronous-file-upload-yuis-approach">Code Central</a> </p>
<p>has an excellent tutorial which I highly recommend. I took the code sample and modified it a bit to fit my needs. Finally I came up with a nice <a href="http://json.org/">JSON object</a> called uploader which has one method, carry. The latter just posts form data to a specified URL.</p>
<pre class="brush: javascript">
uploader = {
	carry: function(){
		// set form
		YAHOO.util.Connect.setForm(&#039;uploadForm&#039;, true);
		// upload image
		YAHOO.util.Connect.asyncRequest(&#039;POST&#039;, &#039;upload.php&#039;, {
			upload: function(o){
				// parse our json data
				var jsonData = YAHOO.lang.JSON.parse(o.responseText);

				// put image in our image container
				YAHOO.util.Dom.get(&#039;imageContainer&#039;).innerHTML = &#039;&lt;img id=&quot;yuiImg&quot; src=&quot;&#039; + jsonData.image + &#039;&quot; width=&quot;&#039; + jsonData.width + &#039;&quot; height=&quot;&#039; + jsonData.height + &#039;&quot; alt=&quot;&quot; /&gt;&#039;;

				// init our photoshop
				photoshop.init(jsonData.image); 

				// get first cropped image
				photoshop.getCroppedImage();
			}
		});
	}
};
</pre>
<p>When upload is complete, we get the JSON data we mentioned earlier on. For e.g :</p>
<pre class="brush: javascript">
{&quot;image&quot; : &quot;images/myimage.jpg&quot;, &quot;width&quot; : &quot;500&quot;, &quot;height&quot; : 400}
</pre>
<p>With this data and using innerHTML we update our imageContainer div to put our image which will have yuiImg as id :</p>
<pre class="brush: javascript">
YAHOO.util.Dom.get(&#039;imageContainer&#039;).innerHTML = &#039;&lt;img id=&quot;yuiImg&quot; src=&quot;&#039; + jsonData.image + &#039;&quot; width=&quot;&#039; + jsonData.width + &#039;&quot; height=&quot;&#039; + jsonData.height + &#039;&quot; alt=&quot;&quot; /&gt;&#039;;
</pre>
<p>It&#8217;s very important to specify the image width and height else the image cropper won&#8217;t work.<br />
Next we initialize another JSON object, photoshop which we&#8217;ll have a look now.</p>
<p>Our photoshop object</p>
<pre class="brush: javascript">
photoshop = {
	image: null,
	crop: null,

	init: function(image){
		// set our image
		photoshop.image = image;

		// our image cropper from the uploaded image
		photoshop.crop = new YAHOO.widget.ImageCropper(&#039;yuiImg&#039;);
		photoshop.crop.on(&#039;moveEvent&#039;, function() {
			// get updated coordinates
			photoshop.getCroppedImage();
		});
	},

	getCroppedImage: function(){
		var coordinates = photoshop.getCoordinates();
		var url = &#039;crop.php?image=&#039; + photoshop.image + &#039;&amp;cropStartX=&#039; + coordinates.left +&#039;&amp;cropStartY=&#039; + coordinates.top +&#039;&amp;cropWidth=&#039; + coordinates.width +&#039;&amp;cropHeight=&#039; + coordinates.height;
		YAHOO.util.Dom.get(&#039;downloadLink&#039;).innerHTML = &#039;&lt;a href=&quot;&#039; + url + &#039;&quot;&gt;download cropped image&lt;/a&gt;&#039;;		

	},

	getCoordinates: function(){
		return photoshop.crop.getCropCoords();
	}
};
</pre>
<p>The init function iniatializes the YUI image cropper from the uploaded image which has yuiImg as id.</p>
<pre class="brush: javascript">
photoshop.crop = new YAHOO.widget.ImageCropper(&#039;yuiImg&#039;);
</pre>
<p>We also subscribe to the moveEvent for the cropper since we&#8217;ll need to update the download link for the cropped image. So whenever the image cropper is moved/resized, we call the getCroppedImage function.</p>
<pre class="brush: javascript">
photoshop.crop.on(&#039;moveEvent&#039;, function() {
	// get updated coordinates
	photoshop.getCroppedImage();
});
</pre>
<p>The getCroppedImage function will generate the download link for the cropped image. To do image cropping in <a href="http://php.net">PHP</a> we&#8217;ll need</p>
<ul>
<li>the image we want to crop</li>
<li>the X,Y coordinates</li>
<li>height and width of the to be cropped area</li>
</ul>
<p>Fortunately the YUI cropper utility has a function which will give us what we want, it&#8217;s the getCropCoords() method. So, whenever the getCroppedImage function is called, we get the coordinates of the cropped area, build a URL and finally put the download link in our downloadLink container.</p>
<pre class="brush: javascript">
// get coordinates
var coordinates = photoshop.getCoordinates();

// build our url
var url = &#039;crop.php?image=&#039; + photoshop.image + &#039;&amp;cropStartX=&#039; + coordinates.left +&#039;&amp;cropStartY=&#039; + coordinates.top +&#039;&amp;cropWidth=&#039; + coordinates.width +&#039;&amp;cropHeight=&#039; + coordinates.height;

// put download link in our page
YAHOO.util.Dom.get(&#039;downloadLink&#039;).innerHTML = &#039;&lt;a href=&quot;&#039; + url + &#039;&quot;&gt;download cropped image&lt;/a&gt;&#039;;
</pre>
<p>This is all we need for the index page.</p>
<p><strong>upload.php</strong></p>
<pre class="brush: php">
if(!empty($_FILES[&quot;uploadImage&quot;])) {
  	// get file name
	$filename = basename($_FILES[&#039;uploadImage&#039;][&#039;name&#039;]);

	// get extension
  	$ext = substr($filename, strrpos($filename, &#039;.&#039;) + 1);

  	// check for jpg only
  	if ($ext == &quot;jpg&quot;) {
      		// generate unique file name
  		$newName = &#039;images/&#039;.time().&#039;.&#039;.$ext;

  		// upload files
        	if ((move_uploaded_file($_FILES[&#039;uploadImage&#039;][&#039;tmp_name&#039;], $newName))) {

        		// get height and width for image uploaded
        		list($width, $height) = getimagesize($newName);

        		// return json data
           		echo &#039;{&quot;image&quot; : &quot;&#039;.$newName.&#039;&quot;, &quot;height&quot; : &quot;&#039;.$height.&#039;&quot;, &quot;width&quot; : &quot;&#039;.$width.&#039;&quot; }&#039;;
        	}
        	else {
           		echo &#039;{&quot;error&quot; : &quot;An error occurred while moving the files&quot;}&#039;;
        	}
  	}
  	else {
     		echo &#039;{&quot;error&quot; : &quot;Invalid image format&quot;}&#039;;
  	}
}
</pre>
<p>The upload.php file too is self explanatory, we check for a jpg image only, then generate an unique filename, put it in the images folder and finally build json data which we&#8217;ll use for DOM manipulation. Of course the images folder must be writable by the web server.</p>
<p><strong>crop.php</strong></p>
<pre class="brush: php">
// get variables
$imgfile = $_GET[&#039;image&#039;];
$cropStartX = $_GET[&#039;cropStartX&#039;];
$cropStartY = $_GET[&#039;cropStartY&#039;];
$cropW = $_GET[&#039;cropWidth&#039;];
$cropH = $_GET[&#039;cropHeight&#039;];

// Create two images
$origimg = imagecreatefromjpeg($imgfile);
$cropimg = imagecreatetruecolor($cropW,$cropH);

// Get the original size
list($width, $height) = getimagesize($imgfile);

// Crop
imagecopyresized($cropimg, $origimg, 0, 0, $cropStartX, $cropStartY, $width, $height, $width, $height);

// force download nes image
header(&quot;Content-type: image/jpeg&quot;);
header(&#039;Content-Disposition: attachment; filename=&quot;&#039;.$imgfile.&#039;&quot;&#039;);
imagejpeg($cropimg);

// destroy the images
imagedestroy($cropimg);
imagedestroy($origimg);
</pre>
<p>Crop.php allows us to crop our uploaded image. First we get all the variables passed to us via the AJAX request,</p>
<pre class="brush: php">
// get variables
$imgfile = $_GET[&#039;image&#039;];
$cropStartX = $_GET[&#039;cropStartX&#039;];
$cropStartY = $_GET[&#039;cropStartY&#039;];
$cropW = $_GET[&#039;cropWidth&#039;];
$cropH = $_GET[&#039;cropHeight&#039;];
</pre>
<p>Then we create 2 images, the original one and the cropped one, and use the imagecopyresized function to generate the cropped image. We add some header information to tell the world it&#8217;s an image and prompt for a save dialog.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/ajax-image-cropper-with-yui-and-php/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>f-lv.com &#8211; download YouTube videos in FLV/MP4/3GP format</title>
		<link>http://htmlblog.net/f-lvcom-download-youtube-videos-in-flv-mp4-3gp-format/</link>
		<comments>http://htmlblog.net/f-lvcom-download-youtube-videos-in-flv-mp4-3gp-format/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:02:15 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[download youtube]]></category>
		<category><![CDATA[flv]]></category>
		<category><![CDATA[mp4]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[vlc]]></category>
		<category><![CDATA[youtube]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=29</guid>
		<description><![CDATA[After playing with the YouTube API and Python over the past week, I&#8217;am pleased to announce the launch of f-lv.com You will be able to : download your favorite YouTube videos in FLV/MP4 format email the video download link to your friend have a look at a nice carousel (thanks Bill for that) with the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://f-lv.com"><img src="http://f-lv.com/images/logo.png" alt="f-lv.com" /></a></p>
<div style="clear:both"></div>
<p>After playing with the YouTube API and Python over the past week, I&#8217;am pleased to announce the launch of <a href="http://f-lv.com">f-lv.com</a></p>
<p>You will be able to :</p>
<ul>
<li>download your favorite <a href="http://youtube.com">YouTube</a> videos in FLV/MP4 format</li>
<li>email the video download link to your friend</li>
<li>have a look at a <a href="http://billwscott.com/carousel/">nice carousel </a>(thanks Bill for that) with the latest downloaded videos</li>
</ul>
<p><span id="more-29"></span><br />
Site is built in <a href="http://php.net">PHP5</a> with a tiny bit of <a href="http://python.org/">Python</a> for generating the link part, powered by the one and only <a href="http://developer.yahoo.com/yui/">YUI library</a> for all AJAX stuff, dialogs, panels.</p>
<p><strong>Latest update (22 August 2008):</strong><br />
Support for 3GP files has been added. Users can now download 3GP files which are perfect for their mobile phones.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/f-lvcom-download-youtube-videos-in-flv-mp4-3gp-format/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

