<?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>WebMuch &#187; PHP</title>
	<atom:link href="http://webmuch.com/category/tutorials/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://webmuch.com</link>
	<description>Everything about the web</description>
	<lastBuildDate>Tue, 16 Feb 2010 10:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Image Flip Using jQuery</title>
		<link>http://webmuch.com/image-flip-using-jquery/</link>
		<comments>http://webmuch.com/image-flip-using-jquery/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 00:11:42 +0000</pubDate>
		<dc:creator>Aayush</dc:creator>
				<category><![CDATA[JavaScript & AJAX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://webmuch.com/?p=175</guid>
		<description><![CDATA[<img src="http://webmuch.com/wp-content/uploads/2009/06/intro.jpg" alt="Image Flip Using jQuery Introduction Image" title="Image Flip Using jQuery Introduction Image" width="150" height="150" class="alignnone size-full wp-image-189" />In this week's post we will be creating an illusion effect of an image flip using jQuery of course. This thing can be used as a cool gallery kind of a thing. So, hopefully you guys will like it, let's get to it.]]></description>
			<content:encoded><![CDATA[<p>Alright, first of all this is not a real image flip but sort of an illusion, the image does not flip itself in 3D since jQuery does not provide us with an image rotation or a distort feature for HTML elements. I know their are some image rotation plug-ins out their but they don&#8217;t work out very well with animate method of jQuery.</p>
<h3>Preview:</h3>
<p><img src="http://webmuch.com/wp-content/uploads/2009/06/preview.jpg" alt="Image Flip Using jQuery Preview Image" title="Image Flip Using jQuery Preview Image" width="585" height="400" class="alignnone size-full wp-image-188" /><br />
<strong>Note: Image flip with reflection is for demo purposes only, it&#8217;s done using the PHP GD Library and it&#8217;s source files are also included in the source code, so meddle with them if you like.</strong></p>
<p><strong><a href="http://webmuch.com/demos/image_flip_demo/flip.html" alt="First Demo">DEMO-1</a> | <a href="http://webmuch.com/demos/image_flip_demo/vertical_flip.html" alt="Second Demo">DEMO-2</a></strong></p>
<h3>HTML Code:</h3>
<pre class="code">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head>
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
&lt;title>Image Flip Illusion Using jQuery&lt;/title>
&lt;link rel="stylesheet" type="text/css" href="default.css" />
&lt;/head>

&lt;body>
&lt;div id="container">
	&lt;h1>Image Flip Illusion Using jQuery&lt;/h1>
    &lt;img id="image1" src="images/image1.jpg" />
    &lt;img id="image2" src="images/image2.jpg" />
&lt;/div>
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">&lt;/script>
&lt;script type="text/javascript" src="hflip.js">&lt;/script>
&lt;/body>
&lt;/html>
</pre>
<h3>CSS Code:</h3>
<pre class="code">
body{
	background-color:#000;
}
h1{
	color:#FFFFFF;
	font-family:Arial;
	font-size:24px;
	font-weight:bold;
}
#container{
	width:400px;
	margin:0px auto;
	height:380px;
	margin-top:50px}
#image1{
	position:absolute;
	cursor:pointer;
	width:300px;
	height:190px;
}
#image2{
	display:none;
	position:absolute;
	cursor:pointer;
}
</pre>
<p>As you can see in the above code, I&#8217;ve placed the two images in a division and given them absolute positioning to assign their positions in the division. </p>
<p>To achieve the Horizontal flip we are basically reducing the width of the first image to 0 pixels, increasing the left side margin from zero to half it&#8217;s width and as soon as we finish that, Increase the width of the second image from zero to it&#8217;s actual width and do the opposite for left side margin what we did for the first image i.e reduce it from half the width of the image to zero.</p>
<p>This process takes place when you click on the first image (#image1) and the same process also takes place when you click on second image (#image2) except for the obvious shuffle in their ids.</p>
<p>Just look at the jQuery code below and you will have a better idea of what&#8217;s happening:</p>
<h3>jQuery:</h3>
<pre class="code">
$(document).ready(function(){
var margin =$("#image1").width()/2;
var width=$("#image1").width();
var height=$("#image1").height();

$("#image2").stop().css({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'});
$("#reflection2").stop().css({width:'0px',height:''+height+'px',marginLeft:''+margin+'px'});

	$("#image1").click(function(){
		$(this).stop().animate({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'},{duration:500});
		window.setTimeout(function() {
		$("#image2").stop().animate({width:''+width+'px',height:''+height+'px',marginLeft:'0px',opacity:'1'},{duration:500});
		},500);
	});

	$("#image2").click(function(){
		$(this).stop().animate({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'},{duration:500});
		window.setTimeout(function() {
		$("#image1").stop().animate({width:''+width+'px',height:''+height+'px',marginLeft:'0px',opacity:'1'},{duration:500});
		},500);
	});

});
</pre>
<p><strong>If you want to perform a Vertical flip the jQuery code for that too is included in the source code.</strong></p>
<p>Feel free to leave comments if you appreciate the tutorial or if you have any queries. You can also criticize the work but don&#8217;t be rude.</p>
<p>You can always find some good tutorials and articles on the <a href="http://webmuch.com/resources/" alt="Resources Page">Resources</a> page. You can always reach it using the menu up-top.</p>
<p>Thanks for Reading!</p>
<p><strong><a href="http://webmuch.com/source_files/image_flip_source.zip">Download the Source Code</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://webmuch.com/image-flip-using-jquery/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
		<item>
		<title>Image Stripe Using PHP GD Library</title>
		<link>http://webmuch.com/image-stripe-using-php-gd-library/</link>
		<comments>http://webmuch.com/image-stripe-using-php-gd-library/#comments</comments>
		<pubDate>Sat, 09 May 2009 17:01:50 +0000</pubDate>
		<dc:creator>Aayush</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[GD Library]]></category>

		<guid isPermaLink="false">http://webmuch.com/?p=73</guid>
		<description><![CDATA[<img src="http://webmuch.com/wp-content/uploads/2009/05/post-intro-image.png" alt="Image Stripe Using PHP GD Library Picture" title="Image Stripe Using PHP GD Library Picture" width="150" height="150" class="alignnone size-full wp-image-74" />In this tutorial we will create an image stripe using PHP's file handling capabilities and GD Library. It will read any number of images from a specified folder and join them all to create a single server side generated image stripe. This will provide the basics of File Handling and GD Graphics Library.]]></description>
			<content:encoded><![CDATA[<h3>Preview:</h3>
<p><img class="alignnone size-full wp-image-78" title="Image Stripe Using PHP GD Library" src="http://webmuch.com/wp-content/uploads/2009/05/preview.jpg" alt="Image Stripe Using PHP GD Library" width="585" height="264" /><br />
What we are going to do today is quite simple. We will read a specific directory for all available images in it and merge them into a single image. Sounds simple, well it is.</p>
<h3>What We Need:</h3>
<ul>
<li>Create a project main folder and create two more folders in it, name them: &#8220;css&#8221; and &#8220;slides&#8221; respectively.</li>
<li>In the project main folder create two files, name them: &#8220;index.php&#8221; and &#8220;createImage.php&#8221; respectively.</li>
<li>In the slides folder put in some jpeg images with same width and height. In my case I used 300px width and 225px height.</li>
</ul>
<h3>index.php:</h3>
<pre class="code">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;

&lt;head&gt;
&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
&lt;title&gt;PHP GD Library Image Stripe&lt;/title&gt;
&lt;!-- stylesheets begin --&gt;

&lt;link rel="stylesheet" type="text/css" href="css/reset.css" /&gt;
&lt;link rel="stylesheet" type="text/css" href="css/master.css" /&gt;

&lt;!-- stylesheets end --&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;div id="wrap"&gt;
	&lt;h2&gt;PHP Image Stripe&lt;/h2&gt;
	&lt;div id="slideshow"&gt;
		&lt;img src="createImage.php" title="Image Stripe" alt="Image Stripe" /&gt;
	&lt;/div&gt;
&lt;/div&gt;&lt;!-- end wrap --&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>In the above code the only new thing to you should be the source(src attribute) of the image tag, which is the link of our &#8220;createImage.php&#8221; file, this is because the file itself when executed outputs an image file. Hope that makes sense, it sure will after you read the excessively documented code of &#8220;createImage.php&#8221; below.</p>
<h3>createImage.php:</h3>
<pre class="code">&lt;?php
$dirPath = 'slides/'; // The path of the directory
$count = 0; // For counting the number of images in the directory

// To check if this is a valid directory
if (is_dir($dirPath)) {
	// Open the directory and make a directory handler called $db
	if ($dh = opendir($dirPath)) {

		// Report all errors except E_WARNING (warnings)
		error_reporting(E_ALL ^ E_WARNING);

		/*
		 *	We have closed the warnings here as there should be no text
		 *	on a page which should be returning as an image otherwise the
		 *	image will not be produced, instead the name of the file will
		 *	be printed.
		 *
		 *	As we are going to use the getimagesize() method to determine
		 *	whether the passed file is an image or not, the method returns
		 *	false when a non image file is passed as a parameter but also
		 *	produces a warning about the same concern, which is why we have
		 *	to disable the warnings in runtime.
		 */

		/*	We start a while loop which runs until the readdir method returns false
		 *	as there are no more files in the directory.
		 *
		 *	each time the loop runs, it enters the next files name in the
		 *	$src variable.
		 */

	while (($filename = readdir($dh)) !== false) {

		/*	getimagesize() method returns false if the file is not an image file.
		 *	Therefore, we check for it to be true as we have passed the file source
		 *	in it, which we created simply by concatinating the $dirPath before
		 *	the $filename.
		 */

		if(getimagesize($dirPath.$filename))
		{

		/*
		 *	We are taking all the "only-image" file names in an array called $imgSrc.
		 *
		 *	$count keeps increasing by 1 if the file is an image and therefore,
		 *	gives us the number of images in the folder. We can get the number
		 *	of images by getting the length of the array as-well and there maybe
		 *	many more methods. But I like it done this way. It is purely a matter
		 *	of choice.
		 */
			$imgSrc[$count] = $dirPath.$filename;
			$count++;
		}
	}

	/*
	 *	As we are creating a horizontal stripe of images we are only
	 *	concerned with the width. First we need to create an Image
	 *	with the dimentions of our final image, therefore we found the
	 *	only the width of our final image because in our case we have
	 *	a static height of our final image.
	 *
	 *	In my case each image in my slides directory has a width of 300px
	 *	and a height of 225px. Therefore, width for a horizontal stripe of
	 *	all images merged will be the number of images multiplied by 300.
	 *
	 *	Which is exactly what I've taken in a variable called $width.
	 *
	 *	Now, for creating an image we have used the imagecreatetruecolor
	 *	method and the resource handler is stored in the variable
	 *	$outputImage.
	 *
	 *	Note: Remember, the height and width of the JPEG's in the slide folder
	 *	must be the same.
	 */

	$width = 300 * $count;
	$outputImage = imagecreatetruecolor($width, 225);

	/*
	 *	We run a loop with the number of images as the limit,
	 *	in which we  create a resource handler for each image
	 *	in the slides folder and then merge it into the Main
	 *	Image i.e. $outputImage.
	 *
	 *	If the loop runs for the first time the "x-coordinate of destination point"
	 *	is static and hard coded as 300 and then for each increament we multiply 300
	 *	by the loop count, this merges the images one after another horizontally
	 *
	 */

		for($i=0; $i&lt;$count; $i++)
		{
			$temp = imagecreatefromjpeg($imgSrc[$i]);
			if($i==0)
				imagecopymerge($outputImage, $temp, 0, 0, 0, 0, 300, 225, 100);
			else
				imagecopymerge($outputImage, $temp, $i*300, 0, 0, 0, 300, 225, 100);

			/*
			 *	Syntax Explaination
			 *
				imagecopymerge(
						Destination image link resource,
						Source image link resource,
						x-coordinate of destination point,
						y-coordinate of destination point,
						x-coordinate of source point,
						y-coordinate of source point,
						Source width,
						Source height,
						alpha transparency
				)
			*/

		}
	}
}

// For displaying the image as the output.

header('Content-type: image/jpeg');
imagejpeg($outputImage);

// Destroying the resourse handler.
imagedestroy($outputImage);

/*
 *	Reporting all errors. Switching it back on,
 *	as the image has already been produced and displayed.
 */
error_reporting(E_ALL);
?&gt;</pre>
<p><strong>Note: Remember, the height and width of the JPEG&#8217;s in the slides folder must be the same.</strong><br />
<strong>Note: imagecreatetruecolor() method does not support GIF images.</strong></p>
<h3>Links:</h3>
<ul>
<li><a href="http://in.php.net/imagecopymerge">imagecopymerge()</a></li>
<li><a href="http://in.php.net/manual/en/function.error-reporting.php">error_reporting()</a></li>
<li><a href="http://in.php.net/imagecreatefromjpeg">imagecreatefromjpeg()</a></li>
<li><a href="http://in.php.net/imagecreatetruecolor">imagecreatetruecolor()</a></li>
</ul>
<p>Thanks for reading!</p>
<p><strong><a href="http://www.webmuch.com/source_files/php_gdImageStripe.zip">Download the Source Code</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://webmuch.com/image-stripe-using-php-gd-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
