Translate!!

Subscribe in a reader

Monday, November 16, 2009

MySql joins

Buzz It
submit to reddit StumbleUpon
MySql joins simply take two tables and joins them together using a common value which they both share. For example if you had a table users and a table posts and you wanted to get all posts by a certain user you could use a query to get all posts where posts.userid = users.user_id.

Setting up their database

So to start we need to create a PHP document connecting to our database.

 $host = "localhost"; 
 $user = "root"; 
 $pass = ""; 
 $name = "joins"; 
  
 $link = mysql_connect( $host, $user, $pass ); 
  
 if( !mysql_select_db( $name, $link ) ) 
 { 
     die("there was an error! ". mysql_error()); 
 } 

 For this example i have created two straight forward tables users and posts the field they both share in common is `user_id`.

 CREATE TABLE `joins`.`users` ( 
 `user_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , 
 `username` VARCHAR( 255 ) NOT NULL 
 ) ENGINE = MYISAM ;  
 CREATE TABLE `joins`.`posts` ( 
 `post_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , 
`user_id` INT( 11 ) NOT NULL , 
 `body` TEXT NOT NULL 
) ENGINE = MYISAM ;  
And out test data.
 INSERT INTO `joins`.`users` ( 
 `user_id` , 
 `username` 
 ) 
 VALUES ( 
 NULL , 'martynj' 
 ), ( 
 NULL , 'bob' 
 ), ( 
 NULL , 'dave' 
 );  
 INSERT INTO `joins`.`posts` (`post_id`, `user_id`, `body`) VALUES (NULL, '1', '
 
  •  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed vulputate nunc quis lacus elementum fringilla. Donec nec nisl sapien. Sed non nisi sed lorem ultricies euismod ac ut velit. Etiam nec lorem et risus volutpat fringilla sit amet sollicitudin ligula. Nullam vel elit at lorem euismod lobortis.
  •  
  •   '), (NULL, '1', '
  •  
  •  Curabitur sed purus felis, vitae rhoncus sem. Curabitur ut massa nulla. Vivamus mollis ante et libero varius sed condimentum dolor malesuada. Aliquam non nibh in sem porttitor bibendum fringilla eu nulla. Etiam porta nibh felis, vitae euismod ligula. Aliquam condimentum nibh vitae purus tincidunt ultrices. Etiam felis est, porta in vulputate in, ultrices quis sem.
  •  
  •  '), (NULL, '2', '
  •  
  •  Nunc sed lorem sem, ut iaculis leo. In mollis felis nec mauris consectetur quis egestas leo dapibus. In hac habitasse platea dictumst. In et malesuada odio. Ut eleifend justo at massa adipiscing gravida. Etiam posuere diam justo, vitae dapibus odio.
  •  
  •  ');  
Now we can start testing different joins on our tables.

Inner joins

An inner join will return all rows regardless of common values in both tables. Generally i don’t use these types of joins much when i’m developing i preffer left join which we will cover next.

 $sql = "SELECT * FROM `users`,`posts` WHERE `users`.`user_id` = `posts`.`user_id`"; 
 $query = mysql_query( $sql ); 
  
 while( $row = mysql_fetch_array( $query ) ) 
 { 
     echo "<p>" . $row["username"] . " - " . $row["body"] . "</p>"; 
 }  
So as you can see for this query it will return three rows because there are three rows in out posts table it will have also joined the data from posts and users because we can use both "username" and "body" even though there both fields from seperate tables.
You can add more to the where clause in this query without it breaking, for example.

 $sql = "SELECT * FROM `users`,`posts` WHERE `users`.`user_id` = `posts`.`user_id` && `users`.`username` = 'martynj'"; 
 $query = mysql_query( $sql ); 
  
 while( $row = mysql_fetch_array( $query ) ) 
 { 
     echo "<p>" . $row["username"] . " - " . $row["body"] . "</p>"; 
 }  
This query will return two rows because there are two rows in the post table which have been posted by martynj.

Left joins

The difference between inner joins and left joins is that while an inner join returned all users which had a post in the posts table, a left join will return all users regardless of rows in the posts table.

  $sql = "SELECT * FROM `users`
        LEFT JOIN `posts`
         ON `users`.`user_id` = `posts`.`user_id`"; 
  
$query = mysql_query( $sql ); 
  
 while( $row = mysql_fetch_array( $query ) ) 
 { 
     echo "<p>" . $row["username"] . " - " . $row["body"] . "</p>"; 
 }  
This query will return 4 rows, one with a username dave but because there were no posts by that user in the posts table, body will be set to NULL.
Once again we can add a where clause if necessary.

 $sql = "SELECT * FROM `users`
        LEFT JOIN `posts`
         ON `users`.`user_id` = `posts`.`user_id`
         WHERE `users`.`username` = 'martynj'"; 
  
 $query = mysql_query( $sql ); 
  
 while( $row = mysql_fetch_array( $query ) ) 
     echo "<p>" . $row["username"] . " - " . $row["body"] . "</p>"; 
 }  

Right joins

The only difference between left joins and right joins is that with a right join it will return all rows from the second table (posts) regardless of common values in the first table, It will then join data from the first table which matches. So it works like a left join in reverse.

 $sql = "SELECT * FROM `users`
          RIGHT JOIN `posts`
        ON `users`.`user_id` = `posts`.`user_id`"; 
  
 $query = mysql_query( $sql ); 
 while( $row = mysql_fetch_array( $query ) ) 
 { 
     echo "<p>" . $row["username"] . " - " . $row["body"] . "</p>"; 
 }  
Hopefully you will now have a fair understanding of how mysql joins work and they be able to write your own joins for your applications. If you have any problems feel free to leave a comment here and they’ll try and help.
[via]









continue reading "MySql joins"

A Twitter List Powered Fan Page

Buzz It
submit to reddit StumbleUpon

A Twitter List Powered Fan Page

via  

Introduction

Recently, Twitter rolled out a great new feature on their site – lists. You can now create and compile a list of twitter users and make it easier for others to follow all at once.
Also, at the same time, they expanded their API to include list management functionality. This allows us to use these new tools to create a widget that flips lists the other way around – a fan page you can put in your sidebar, that allows your visitors to fill in their twitter name and join a specially crafted fan list in your twitter account.
So download the example files and lets start coding!

Step 1 – XHTML

As usual, we start with the XHTML. As the widget is entirely AJAX based, this is the only code that you will need to include directly into your site. The rest is fetched asynchronously.

demo.html

<div id="fanPage">

<div class="title">

<a class="fanPageLink" href="http://twitter.com" title="Go to fanpage!"><img src="img/twitter-bird.png" id="twitBird" alt="twitter bird" /></a>
<a class="fanPageLink" href="http://twitter.com" title="Go to fanpage!">Fanpage</a>

</div>

<div class="content">
<div class="fans"><img src="img/loader.gif" alt="loading.." /></div>
</div>

<div class="subscribe">
<a href="#" class="joinFP">Join!</a>

<div class="membersCount">
<a class="fanPageLink" id="counter" href="http://twitter.com" title="Total Fans"></a>
</div>

</div>
</div>


Here we have the main fanPage container DIV, which holds our the widget and inside it we have the title, content and subscribe DIVs.
These are later styled with CSS and populated with data via AJAX. Also notice that we have three links which share a FanPageLink class. Currently they point to the twitter’s main site, but later we are going to edit their href attributes dynamically, and point them to the member page of the list.
A jQuery Twitter List Powered Fanpage Widget
A jQuery Twitter List Powered Fanpage Widget

Step 2 – CSS

Once we have the markup in place, we can move to the CSS. Here are only presented the rules that are directly used by the widget. You can view all of the code in demo.css in the source archive.

demo.css

#fanPage{
    /* This is the container that holds the widget */
    background-color:#002233;
    color:white;
    height:300px;
    margin:30px auto;
    padding:10px;
    text-align:left;
    width:170px;
}

#fanPage a, #fanPage a:visited{
    /* This styles the title and total fans links */
    color:white;
   text-decoration:none;
}

#fanPage a:hover{
    text-decoration:underline;
}

.title{
   /* The title on the top */
    background-color:#013853;
   font-family:&amp;quot;Myriad Pro&amp;quot;,Arial,Helvetica,sans-serif;
    font-size:16px;
    letter-spacing:1px;
    margin:3px 0 10px;
    padding:4px 8px;
   position:relative;
    text-align:right;
   text-transform:uppercase;
}

#twitBird{
    /* The twitter icon on the top */
    left:-10px;
    position:absolute;
    top:-28px;
}

.content{
    /* The div that holds the twitter avatars */
    background-color:#eeeeee;
    padding:6px;
    text-align:left;
    height:208px;
    position:relative;
    color:#333333;
}

#mask{
    /* Inserted once you click the green &amp;quot;Join&amp;quot; button */
    font-size:10px;
    left:0;
    padding:10px;
    position:absolute;
    top:0;
}

#mask label{
    display:block;
    font-weight:bold;
    margin:8px 0 4px;
   text-transform:uppercase;
}

#twitterName{
    /* The twitter name input box */
    background-color:#FCFCFC;
    border:1px solid #CCCCCC;
    color:#333333;
    font-family:Arial,Helvetica,sans-serif;
    font-size:12px;
    padding:2px;
}

#mask a.greyButton,#mask a.greyButton:visited{
    /* The default state of the gray join button */
    display:inline-block;
    height:19px;
   margin-top:10px;
    padding:6px 0 0;
    text-align:center;
    width:70px;
    background:url(img/button_gray.png) no-repeat;
    color:#222222;
}

#mask a.greyButton:hover{
    /* The hover effect on the &amp;quot;Join&amp;quot; button */
    background-position:bottom left;
    text-decoration:none;
}

div#mask a, div#mask a:hover, div#mask a:visited{
    color:#0196e3;
}

#response{
    /* The div that holds the response messages in the &amp;quot;Join area&amp;quot; */
    margin-top:10px;
    font-size:10px;
   text-align:center;
}

.subscribe{
    position:relative;
}

.membersCount{
    /* The total number of fans div */
   position:absolute;
    right:0;
    top:5px;
    color:white;
    display:block;
    font-size:22px;
    font-weight:bold;
}

content img{
    /* The twitter avatars */
    margin:2px;
}

#fanPage, .content, .title{
   /* Rounding three elements at once */
    -moz-border-radius:4px;
    -webkit-border-radius:4px;
   border-radius:4px;
}

.a.joinFP, a.joinFP:hover{
    /* The green &amp;quot;Join&amp;quot; button */
    display:block;
   background:url(img/buttons.png) no-repeat;
    width:94px;
    height:38px;
    text-indent:-9999px;
   margin:5px 0 0 -4px;
}

.a.joinFP:hover{
    /* The hover state of the button */
    background-position:bottom left;
}

a img{
    border:none;
}

Step 3 – jQuery

As I mentioned earlier, the entire widget is AJAX based. This is actually a necessity, because communication with the twitter API would stall the website otherwise.
Here is the main idea behind the code below:
  1. The page, in which the widget is included is loaded into a visitor’s browser;
  2. With it, script.js (which holds all of our jQuery code) is executed;
  3. $(document).ready() is run;
  4. An AJAX request is initiated, which loads the data from load.php and displays it on success;
  5. All the links with a fanPageLink class are pointed to the list members page on twitter;
  6. A click function is bonded to the green join button;

First half of script.js

$(document).ready(function(){
   /* Executed on DOM load */

    $.getJSON(&quot;load.php&quot;,function(data){

        /* Loading the widget data */
        if(data.error)
       {
            /* If there is an error, output and exit */
            $(&quot;.content&quot;).html(data.error);
           return false;
       }

        $(&quot;.content .fans&quot;).html(&#039;&#039;);
        /* Remove the rotating GIF */

       $.each(data.members,function(i,val){

           /* Loop through all the shown members and add them to the .content DIV */
            $(&quot;.content .fans&quot;).append(&#039;&lt;a href=&quot;http://twitter.com/&#039;+i+&#039;&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;&#039;+val+&#039;&quot; width=&quot;48&quot; height=&quot;48&quot; title=&quot;&#039;+i+&#039;&quot; alt=&quot;&#039;+i+&#039;&quot; /&gt;&lt;/a&gt;&#039;);
        });

        $(&#039;#counter&#039;).html(data.membersCount);
        /* Set the member counter */

        $(&#039;.fanPageLink&#039;).attr(&#039;href&#039;,data.fanPage+&#039;/members&#039;).attr(&#039;target&#039;,&#039;_blank&#039;);
        /* Set the .fanPageLink-s to point to the profile page */
   });

   $(&#039;.joinFP&#039;).click(function(e){

        /* IF the green button has been clicked.. */

       if($(&#039;.content&#039;).html().indexOf(&#039;id=&quot;mask&quot;&#039;)!=-1)
      {
           /* ..and the form is already shown exit */
            e.preventDefault();
           return false;
       }

       /* ..in the other case, start a fade out effect */
        $(&quot;.content .fans&quot;).fadeOut(&quot;slow&quot;,function(){

            $(&#039;.content&#039;).append(&#039;&lt;div id=&quot;mask&quot;&gt;\
            To join our fan page, you just have to fill in your name\
            &lt;label&gt;Twitter username:&lt;/label&gt;\
            &lt;input id=&quot;twitterName&quot; name=&quot;twitter&quot; type=&quot;text&quot; size=&quot;20&quot; /&gt;\
            &lt;a href=&quot;&quot; class=&quot;greyButton&quot; onclick=&quot;sendData();return false;&quot;&gt;Join!&lt;/a&gt; or &lt;a href=&quot;#&quot; onclick=&quot;cancel();return false;&quot;&gt;cancel&lt;/a&gt;\
            &lt;div id=&quot;response&quot;&gt;&lt;/div&gt;\
            &lt;/div&gt;&#039;);
        });

        /* Prevent the link from redirecting the page */
        e.preventDefault();
    });
});

Later if a click occurs on the green  “Join” button, the avatars are faded out and a form appears on their place.
The second half of the code handles the sending of the data to add.php:

Second half of script.js

function sendData()
{
    /* This function sends the form via AJAX */
    $('#response').html('<img src="img/loader.gif" />');
    var twitter = $('#twitterName').val();
    if(!twitter.length)
    {
        $('#response').html('<span style="color:red">Please fill in your twitter username.</span>');
        return false;
    }

    $.ajax({
        type: "POST",
        url: "add.php",
        data: "twitter="+encodeURIComponent(twitter),
        /* Sending the filled in twitter name */
        success: function(msg){

           /* PHP returns 1 on success, and 0 on error */
            var status = parseInt(msg);

            if(status)
            {
                $('#response').html('Thank you for being a fan! You will be added in a few minutes. <a href="#" onclick="cancel();return false">Hide this form</a>.');
                $('#twitterName').val('');
           }
            else
                $('#response').html('<span style="color:red">There is no such twitter user.</span>');
        }
    });
}

function cancel()
{
    /* Hides the "Join" form */
    $('#mask').remove();
    $('.content .fans').fadeIn('slow');
}


The sendData function is called if the user clicks on the newly created gray “Join” button below the input field. It also checks the return status of the AJAX request to choose the proper status message.
Also remember that for above code the work, we need to include the jQuery library and script.js into the head section of the document:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>

Step 4 – PHP

Now that we followed all the code on the front-end, it is now time for the last part of this tutorial – the PHP back-end.
PHP has the important task of communicating with the twitter API. This is done via a special extension – CURL. For convenience, I made a special function – curlMe that wraps the CURL code and makes it easier to send requests from other places in the script.

functions.php

function error($msg)
{
    // Format the error as a JSON object and exit the script:
    die('{error:"'.$msg.'"}');
}

function fetchElement($element,$src)
{
    // Takes in an XML document as string $src, and returns the required nod value

    $match = array();
    preg_match_all('/<'.$element.'>(.*)<\/'.$element.'>/u',$src,$match);
    // Matching the required property in the xml

    return $match[1];

    // ..and returning it
}

function curlMe($url,$gp='')
{
    // Using CURL to communicate with the Twitter API

    global $username,$password;

    $cc = curl_init();

    curl_setopt($cc, CURLOPT_URL, $url);

    if($gp)
    {
        // If the $gp parameter is set, send it by a POST request:
        curl_setopt($cc, CURLOPT_POST, 1);
        curl_setopt($cc, CURLOPT_POSTFIELDS, $gp);
    }
    else
        curl_setopt($cc, CURLOPT_GET, 1);

    curl_setopt($cc, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($cc, CURLOPT_USERPWD, $username.':'.$password);
    curl_setopt($cc, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($cc, CURLOPT_RETURNTRANSFER, 1);

    $xml = curl_exec($cc);
    curl_close($cc);

    return $xml;
}

Now that we’ve defined those functions, we can use them in any PHP file by just including or requiring functions.php in the script.
Adding new fans on the list is done in add.php

add.php

require "functions.php";
require "config.php";

if(!$_POST['twitter'])
die('0');

$userXML = curlMe("http://twitter.com/users/show.xml?screen_name=".urlencode($_POST['twitter']));
// Initiating an API request

if(strpos($userXML,'<error>Not found</error>') !== false)
{
    // If there is no such user, return an error:
    die('0');
}

// fetchElement returns an array, and the list function assigns its first element to $id:
list($id) = fetchElement('id',$userXML);

curlMe('http://api.twitter.com/1/'.$username.'/'.$list.'/members.xml','id='.$id);

echo 1;

As with any API, there are limits of usage. This is done to prevent abuse of the service and ruining everybody’s day. Twitter enforces a 150 requests per hour rule, which limits how many times we can GET data for the twitter list.
This is why I build a simple caching mechanism, that stores the fetched data for 15 minutes after a request is made to the API.
Here is how it works:
  1. The widget makes an AJAX request to load.php;
  2. The php script checks to see if a cache file exists;
  3. If it does, it gets its contents and returns it;
  4. If it does not, or if the cache is older than 15 minutes, it fetches the data from the API, stores it in the cache file for later use and returns it;
This simple mechanism ensures that the widget will always have API calls to spare. You can see the code below:

load.php'

require "functions.php";
require "config.php";

$cache_file = 'twitter.cache';
// The cache file

$cache_expire_time = 15*60;
// The cache expires after 15 minutes

$twitterers_shown = 12;

// If you are making changes and want to destroy the cache while testing,
// uncomment the line below:

//$cache_expire_time = 1;

if(!file_exists($cache_file) || time() - filemtime($cache_file) > $cache_expire_time)
{
    // If there isn't a cache file, or if it is older than allowed

    $xml = curlMe("http://api.twitter.com/1/".$username."/".$list."/members.xml");
    //$xml = curlMe("http://api.twitter.com/1/chouka/design/members.xml");

    if(strpos($xml,'<error>Not found</error>') !== false)
    {
        // If there is not such a list, create it automatically:
        curlMe('http://api.twitter.com/1/'.$username.'/lists.xml','name='.$list);
    }

    $usernames = fetchElement('screen_name',$xml);
    $avatars = fetchElement('profile_image_url',$xml);

    $json = '';
    foreach($usernames as $k=>$u)
    {
        if($k!=0) $json.=', ';
       $json.='"'.$u.'":"'.$avatars[$k].'"';
        // Generating the json object with a structure: username:avatar_image

        if($k>=$twitterers_shown-1) break;
    }

    // Getting the total number of fans requires an additional API call:

    $membersXML = curlMe("http://api.twitter.com/1/".$username."/lists/".$list.".xml");
    $membersCount = fetchElement('member_count',$membersXML);

    $json = '{members:{'.$json.'}, membersCount:'.$membersCount[0].',fanPage:"http://twitter.com/'.$username.'/'.$list.'"}';

    // Save the generated json variable in the cache for later use:
    $fp = fopen($cache_file,'w');

    if($fp == false)
    {
        error("Your cache file could not be created! You have to chmod the script directory to 777!");
    }

    fwrite($fp,$json);
    fclose($fp);
}
else
{
    $json = file_get_contents($cache_file);
    // Fetch the data from the cache file
}

echo $json;

Also you might notice that the API requires you to provide you username and password in order to use it. So if you are planning to run the demo on your own server, be sure to fill in your log-in information in config.php.
The two states
With this our Twitter List Powered Fan Page is complete!














 

 


continue reading "A Twitter List Powered Fan Page"

Film Strip Photo Collage in Photoshop

Buzz It
submit to reddit StumbleUpon

Film Strip Photo Collage in Photoshop

from photoshopessentials.com

Let's get started!

Step 1: Create A New Photoshop Document

Let's begin as we did in part one by creating a new Photoshop document. This will become our main photo collage document. Go up to the File menu at the top of the screen and choose New, or for a faster way, press Ctrl+N (Win) / Command+N (Mac) on your keyboard:
Creating a new document in Photoshop. Image © 2009 Photoshop Essentials.com.
Choose File > New from the Menu Bar at the top of the screen.
This brings up Photoshop's New Document dialog box. I'm going to go with a standard frame size of 8 x 10 for my photo collage, and I want it to appear in landscape orientation, so I'll enter a value of 10 inches for the Width and 8 inches for the Height (make sure you select inches for the measurement type and not pixels), and since I want to be able to print my final result later and have it appear nice and sharp, I'll enter 300 pixels/inch for the Resolution value. Finally, I'll set the Background Contents option at the bottom to White so my document appears with a solid white background:
The New Document dialog box in Photoshop. Image © 2009 Photoshop Essentials.com.
Create a new 8 x 10 inch document at a resolution of 300 pixels/inch.
Click OK when you're done to exit out of the dialog box. The new document appears on your screen.

Step 2: Open Your Main Photo

Next, open the photo you want to use as the main image in the collage. Here's the photo I'll be using:
A wedding photo with a bride and groom. Image licensed from iStockphoto by Photoshop Essentials.com
Open your main photo.
You should now have two separate document windows open on your screen. The main photo collage document appears in one, and the photo you just opened appears in the other.

Step 3: Copy And Paste The Image Into The Photo Collage Document

We need to add this photo to our photo collage document that we created in step 1, and we can do that simply by copying and pasting it. First, press Ctrl+A (Win) / Command+A (Mac) on your keyboard to select the entire image. You'll see a selection outline appear around the edges of the image in the document window. With the image selected, press Ctrl+C (Win) / Command+C (Mac) to copy the image temporarily to your computer's memory.
Switch over to your photo collage document by clicking anywhere inside its document window, then press Ctrl+V (Win) / Command+V (Mac) to paste the photo into the document. In my case, my photo is larger than the 8 x 10 document I created, so only part of the photo appears visible inside the document window. We'll fix that in a moment:
Copying and pasting the photo into the main document. Image © 2009 Photoshop Essentials.com
If your photo is larger than the main document, not all of it will be visible.
If we look in the Layers panel now, we can see that the photo has been added on its own layer (which Photoshop has automatically named "Layer 1") above the white-filled Background layer:
The Layers panel in Photoshop CS4. Image © 2009 Photoshop Essentials.com
Photoshop places the photo on its own layer in the photo collage document.
You can close out of the photo's original document window at this point. All we need open is the main photo collage document.

Step 4: Use Free Transform To Resize And Reposition The Photo

Since my photo is currently too big to fit inside my photo collage document, I'll need to resize it. I also need to reposition the image so that the wedding couple appears more on the left side of the document, leaving room for my film strips on the right. I can resize and reposition the image at the same time using Photoshop's Free Transform command. Go up to the Edit menu at the top of the screen and choose Free Transform, or press Ctrl+T (Win) / Command+T (Mac) to select it with the keyboard shortcut:
The Free Transform command in Photoshop. Image © 2009 Photoshop Essentials.com
Go to Edit > Free Transform.
This brings up the Free Transform box and handles around the image. Unfortunately, since the edges of my photo extend out beyond the visible area of the document, I can't see the Free Transform handles, which makes it a bit difficult to do anything. If you're having the same problem, go up to the View menu at the top of the screen and choose the Fit on Screen command, or press Ctrl+0 (Win) / Command+0 (Mac) for the keyboard shortcut:
The Fit on Screen command in Photoshop. Image © 2009 Photoshop Essentials.com
If you can't see the Free Transform handles, go to View > Fit on Screen.
This tells Photoshop to expand the size of the document window so that everything fits inside of it. Even though the actual viewable area of the document doesn't change and much of the photo remains hidden from view, we can now easily access the Free Transform handles in the corners of the photo. To resize the image, hold down your Shift key, which will constrain the aspect ratio of the photo as you resize it, then click on a handle (the little square) in one of the corners of the photo and, while still holding down your mouse button, drag it in towards the center of the photo. I'm going to drag the handle in the bottom right corner inward to make my photo smaller:
Resizing an image with the Free Transform command in Photoshop. Image © 2009 Photoshop Essentials.com
To resize the image, hold down Shift, then click and drag any of the corner handles.
To move the image if needed, click anywhere inside the photo, keep your mouse button held down, and drag the image around inside the document. I'm going to drag the wedding couple over towards the left side of the document so I'll have room on the right to add my film strips. Leave somewhere between one quarter and one third of the document on the right for the film strips:
Repositioning the image with the Free Transform command in Photoshop. Image © 2009 Photoshop Essentials.com
To move the image, click anywhere inside of it and drag it around as needed.
Press Enter (Win) / Return (Mac) when you're done to accept the changes and exit out of the Free Transform command. Here's my document after resizing and moving the photo towards the left. Notice how some of the white background is now visible along the right side of the document after moving the image:
The image after resizing and repositioning it with the Free Transform command. Image © 2009 Photoshop Essentials.com
Some of the white background is now visible along the right side of the document.
We're going to blend the right edge of the photo in with the white background using a layer mask and the Gradient Tool next!

Step 5: Add A Layer Mask

Let's blend the right edge of the photo in with the white background, creating a smooth transition between the two. Having an area of white on the right side of the document will make it easier to see the film strips that we'll be adding in a moment. Make sure "Layer 1" is selected in the Layers panel (it should be highlighted in blue), then click on the Layer Mask icon at the bottom of the Layers panel to add a layer mask to the layer:
Adding a layer mask in Photoshop. Image © 2009 Photoshop Essentials.com.
Click on the Layer Mask icon at the bottom of the Layers panel.
Nothing will happen yet in the document window itself, but a layer mask thumbnail appears on "Layer 1" in the Layers panel:
The Layers panel showing the new layer mask thumbnail in Photoshop. Image © 2009 Photoshop Essentials.com.
A layer mask has been added to the photo layer.

Step 6: Select The Gradient Tool

Select the Gradient Tool from the Tools panel, or press the letter G on your keyboard to select it with the shortcut:
The Gradient Tool in Photoshop. Image © 2009 Photoshop Essentials.com.
Select Photoshop's Gradient Tool.

Step 7: Choose The Black to White Gradient

With the Gradient Tool selected, right-click (Win) / Control-click (Mac) anywhere inside the document to quickly bring up the Gradient Picker, then click on the Black to White gradient, third icon from the left, top row, to select it:
Choosing the Black, White gradient from the Gradient Picker. Image © 2009 Photoshop Essentials.com.
Click on the Black to White gradient in the Gradient Picker to select it.
Click anywhere outside of the Gradient Picker when you're done to close it.

Step 8: Draw A Black to White Gradient To Create A Transition Area

With the Black to White gradient selected, click just inside the right edge of the photo to set a starting point for the gradient, then keep your mouse button held down and drag horizontally towards the left, stopping just short of the center of the document. The area between the points where you started and ended the gradient is where the photo will blend into the white background:
Drawing a black to white gradient on the layer mask in Photoshop. Image © 2009 Photoshop Essentials.com.
Click and drag out a black to white gradient to create a transition between the photo and the background.
Release your mouse button, at which point Photoshop draws the gradient. Since we drew the gradient on the layer mask, not on the layer itself, we don't actually see the gradient in the document window. Instead, we see the effects of the gradient on the layer mask, which now blends the right side of the photo smoothly into the white area on the far right:
The photo and background are now blended nicely. Image © 2009 Photoshop Essentials.com.
The right edge of photo now blends nicely into the solid white background.
Our main photo is in place and ready for the film strips to be added. We'll do that next!

Step 9: Open The Film Strip Document

Open the film strip document that we created back in part one of the tutorial:
The film strip photo frame that was created in part one of the tutorial. Image © 2009 Photoshop Essentials.com.
The film strip photo frame was created in the first part of the tutorial.

Step 10: Rename The Middle Layer "Photo Area"

In a moment, we're going to be adding a few copies of our film strip to the photo collage document, but before we do, let's make a couple of quick changes to the film strip. First, let's rename the middle layer to something that will be easier to understand later. Double-click directly on the name "Shape 2" and change the layer's name to "photo area", since the rectangular shape on this layer represents the area where the photos will be visible inside the film strip. Press Enter (Win) / Return (Mac) when you're done to accept the change:
Renaming a layer in the Layers panel in Photoshop. Image © 2009 Photoshop Essentials.com.
Double-click on the middle layer's name and rename it "photo area".

Step 11: Group The Two Shape Layers Together

Next, let's take the two shape layers that make up our film strip and group them together, creating what's called, not surprisingly, a layer group. Click on the top layer ("Shape 1") in the Layers panel to select it, then hold down your Shift key and click on the "photo area" layer that we just renamed. This will select both layers at once, and you'll see them both highlighted in blue.
Selecting two layers at once in the Layers panel. Image © 2009 Photoshop Essentials.com.
Click on the top layer to select it, then hold Shift and click on the middle layer to select them both at once.
With both layers selected, go up to the Layer menu at the top of the screen, choose New, and then choose Group from Layers:
Selecting the New Group from Layers option in Photoshop CS4. Image © 2009 Photoshop Essentials.com.
Go to Layer > New > Group from Layers.
Photoshop will pop open a small dialog box where we can enter a name for our new layer group. Name the group "film strip":
Naming the new layer group in Photoshop. Image © 2009 Photoshop Essentials.com.
Name the new layer group "film strip".
Click OK when you're done to close out of the dialog box, and if we look again in the Layers panel, we can see that we now have a new layer group named "film strip". Both of the shape layers that make up the film strip are inside the group:
The new layer group appears in the Layers panel. Image © 2009 Photoshop Essentials.com.
Layer groups are a great way to organize layers and keep the Layers panel from getting cluttered.

Step 12: Save The Changes

Before we continue, let's save the changes we've made to the film strip so we won't have to make them again the next time we use it. Go up to the File menu at the top of the screen and choose the Save command. Since we've already saved the document once, Photoshop won't bother to ask us what we want to name it or where we want to save it to. It will simply overwrite the previous version of the document:
Saving the changes to the document in Photoshop. Image © 2009 Photoshop Essentials.com.
Go to File > Save.

Step 13: Select The Move Tool

We're ready to add the film strip to the photo collage document. Select the Move Tool from the Tools panel, or press the letter V on your keyboard to select it with the shortcut:
The Move Tool in Photoshop. Image © 2009 Photoshop Essentials.com.
The Move Tool can be found at the top of the Tools panel.

Step 14: Drag The Film Strip Into The Photo Collage Document

Then, with the film strip and the photo collage documents open in separate windows, click with the Move Tool inside the film strip's document window, keep your mouse button held down, and drag the film strip over to the photo collage document window:
Dragging the layer group between document windows in Photoshop. Image © 2009 Photoshop Essentials.com.
Drag the film strip layer group into the photo collage document.
Release your mouse button, and the film strip appears inside the photo collage document:
The first film strip has been added to the collage. Image © 2009 Photoshop Essentials.com.
The first film strip has been added.
You can close out of the film strip document at this point since we no longer need it. If we look in the Layers panel for the photo collage document, we can see that the film strip layer group has been copied over and now appears above the main photo:
The layer group has been copied over to the photo collage document. Image © 2009 Photoshop Essentials.com.
The film strip layer group now appears in the photo collage document's Layers panel.

Step 15: Move, Reposition And Rotate The Film Strip With Free Transform

Now that we have our first film strip, let's move it into position. I'm going to move mine into the top right corner of the document. I'm also going to make it a bit smaller and, to add a little more visual interest, I'll rotate it slightly. I can do all three of these things with Photoshop's Free Transform command, so with the layer group selected in the Layers panel, I'll press Ctrl+T (Win) / Command+T (Mac) to quickly bring up the Free Transform box and handles around the film strip, just as we saw earlier when we moved and resized the main photo.
To move the film strip, I'll click inside of it and, with my mouse button held down, I'll drag it up into the top right corner of the document, releasing my mouse button once it's in place:
Moving the film strip with the Free Transform command in Photoshop. Image © 2009 Photoshop Essentials.com.
Click inside the film strip and drag it to its new position.
To resize it and make it a bit smaller, I'll hold down my Shift key, which will constrain the aspect ratio of the film strip as I resize it so I don't accidentally distort its shape, then I'll click on the handle in the bottom left corner (it doesn't matter which corner you choose), keep my mouse button held down, and drag it in towards the center of the film strip, releasing my mouse button when I'm done:
Resizing the film strip by dragging a corner handle. Image © 2009 Photoshop Essentials.com.
Hold down Shift as you drag corner handles to resize the film strip.
Finally, to rotate the film strip, I'll move my mouse button outside of the Free Transform bounding box, at which point my mouse cursor changes to a small rotate icon, then I'll click, hold my mouse button down, and drag to rotate the film strip. I'm going to rotate my film strip counter-clockwise, releasing my mouse button when I'm done:
Rotating the film strip with the Free Transform command in Photoshop. Image © 2009 Photoshop Essentials.com.
Move your mouse cursor outside of the Free Transform box, then click and drag to rotate it.
When you're finished moving, resizing and rotating your film strip, press Enter (Win) / Return (Mac) to accept the changes and exit out of the Free Transform command.

Step 16: Rename The Layer Group

Back when we created a layer group out of the two shape layers that make up our film strip, we changed the name of the group from the generic name "Group 1" that Photoshop gave it to "film strip". Since we're going to be adding several copies of the film strip to our document, let's be even more descriptive with our group names to make it easy to distinguish between them in the Layers panel. I'm going to double-click directly on the group's name in the Layers panel and add the word "top" to the end of the group's name. Press Enter (Win) / Return (Mac) when you're done to accept the change:
Renaming the layer group to 'film strip top'. Image © 2009 Photoshop Essentials.com.
Adding the location of each film strip to the group's name will make it easy to work with them later.

Step 17: Drag Out A Copy Of The Film Strip

Let's add our second film strip. I'm going to place my second one in the bottom right corner of the document, directly below the first one. With the Move Tool selected, I'll hold down Shift+Alt (Win) / Shift+Option (Mac), click on the film strip in the document window and drag it straight down to the bottom right corner. The Alt / Option key tells Photoshop to make a copy of the film strip as I drag, rather than moving the original film strip, and holding the Shift key limits the direction that I can drag in, making it easy to drag straight down:
Dragging out a copy of the film strip in Photoshop. Image © 2009 Photoshop Essentials.com.
Hold down Shift+Alt (Win) / Shift+Option (Mac) and drag out a copy of the film strip.

Step 18: Rename The New Film Strip's Layer Group

If we look in the Layers panel, we can see that we now have two layer groups, each one containing a different film strip. Photoshop automatically named our second group "film strip top copy", so let's double-click on the group's name and change it to "film strip bottom". Press Enter (Win) / Return (Mac) when you're done to accept the name change:
Renaming the second film strip layer group. Image © 2009 Photoshop Essentials.com.
Change the name of the second film strip to "film strip bottom".

Step 19: Drag Out A Third Film Strip

With the "film strip bottom" layer group selected in the Layers panel and the Move Tool still selected, hold down Shift+Alt (Win) / Shift+Option (Mac), just as we did a moment ago, and drag out a third film strip. This creates a copy of the film strip we just added in the bottom right corner. I'm going to drag straight up to place my third film strip directly between the other two:
Dragging out a third film strip in Photoshop. Image © 2009 Photoshop Essentials.com.
Hold down Shift+Alt (Win) / Shift+Option (Mac) and drag out another copy of the film strip.

Step 20: Rotate The Third Film Strip

Since having all three film strips rotated exactly the same way looks a bit dull, I'll press Ctrl+T (Win) / Command+T (Mac) to bring up the Free Transform box and handles around my third film strip. I'll move my mouse cursor outside of the Free Transform box, which changes the cursor to the rotate icon, then I'll click, hold my mouse button down, and drag to rotate the film strip:
Rotating the third film strip in the photo collage. Image © 2009 Photoshop Essentials.com.
Rotate the third film strip with the Free Transform command.
Press Enter (Win) / Return (Mac) when you're done to accept the change and exit out of the Free Transform command.

Step 21: Rename The Third Film Strip's Layer Group

We have our three film strips in place, but before we starting adding photos to them, let's rename the third film strip's layer group in the Layers panel, which is currently named "film strip bottom copy". Double-click on its name and change it to "film strip middle", then press Enter (Win) / Return (Mac) to accept the change:
Renaming the third film strip layer group. Image © 2009 Photoshop Essentials.com.
Change the name of the second film strip to "film strip middle".
We're ready to add photos to the film strips. We'll do that next!

Step 22: Open The Photo You Want To Add To The First Film Strip

We're ready to add our photos to the film strips. Since the steps are the same for each film strip, we'll look at how to add a photo to the first one ("film strip top"). Then, to add photos to the remaining film strips, simply repeat the same steps.
First, open the photo you want to place inside the film strip. Here's the photo I'll be using:
The first image to be added to the film strip. Image licensed from iStockphoto by Photoshop Essentials.com
Open the photo that will be placed inside the first film strip.

Step 23: Select And Copy The Photo

We're going to copy and paste the photo into the film strip, just as we copied and pasted the main photo into the photo collage document at the beginning of the tutorial. Press Ctrl+A (Win) / Command+A (Mac) to quickly select the entire image. You'll see a selection outline appear around the edges of the photo in the document window. Then press Ctrl+C (Win) / Command+C (Mac) to copy the photo to your computer's memory.

Step 24: Twirl Open The Layer Group For The Top Film Strip

With the image copied to memory, switch over to the main photo collage document by clicking anywhere inside its document window. We need to access the shape layers that make up the film strip in the top right corner of the document, which means we need to twirl open the film strip's layer group. Click on the small triangle icon on the far left of the "film strip top" group in the Layers panel. This will twirl open the layer group, allowing us to see the two shape layers inside of it:
Opening the layer group for the first film strip. Image © 2009 Photoshop Essentials.com.
Click on the triangle icon to open and close layer groups.

Step 25: Select The Photo Area Layer

With the layer group open, click on the photo area layer to select it. The shape on this layer represents the area where the photo will appear inside the film strip:
Selecting the film strip's photo area layer. Image © 2009 Photoshop Essentials.com.
Click on the "photo area" layer.

Step 26: Paste The Image Into The Film Strip

With the "photo layer" selected, press Ctrl+V (Win) / Command+V (Mac) to paste the photo into the film strip. If we look in the document window, we can see that the photo now appears in front of the main image, but it doesn't look like it's inside the film strip just yet. We'll fix that in a moment (your photo may appear much larger in the document window than mine, since I'm using smaller images for my film strips):
Pasting the first image into the first film strip. Image © 2009 Photoshop Essentials.com.
The photo appears inside the document.
Even though the photo doesn't yet appear to be inside the film strip, if we look in the Layers panel, we see that sure enough, Photoshop has placed the image inside the "film strip top" layer group, directly above the "photo area" layer, which is exactly where we want it. Photoshop always adds new layers directly above the layer that was selected, which is why we selected the "photo area" layer before pasting in the image:
The image appears above the 'photo area' layer in the layer group. Image © 2009 Photoshop Essentials.com.
The photo was added between the two shape layers that make up the film strip.

Step 27: Position The Photo Inside The Film Strip

With the Move Tool still selected, click on the image in the document window and drag it over to the film strip in the top right corner so that it fills the entire gray photo area in the center of the film strip. Don't worry about positioning it exactly right for now:
Dragging the photo inside the photo area of the film strip. Image © 2009 Photoshop Essentials.com.
Use the Move Tool to drag the image into the gray photo area of the film strip.

Step 28: Create A Clipping Mask

Once you have the photo moved into position, go up to the Layer menu at the top of the screen and choose Create Clipping Mask, or press Ctrl+Alt+G (Win) / Command+Option+G (Mac) to select the Create Clipping Mask command with the keyboard shortcut:
Creating a clipping mask in Photoshop. Image © 2009 Photoshop Essentials.com.
Go to Layer > Create Clipping Mask.
This tells Photoshop to "clip" the photo to the shape on the "photo area" layer below it, and now, only the area of the photo that falls within the boundaries of the shape remains visible in the document. The rest of the photo is hidden from view, creating the illusion that the image is inside the film strip:
The image is now clipped to the photo area inside the film strip. Image © 2009 Photoshop Essentials.com.
The image now appears inside the film strip thanks to the clipping mask.

Step 29: Fine-Tune The Image Inside The Film Strip With Free Transform

Press Ctrl+T (Win) / Command+T (Mac) to once again bring up the Free Transform command and use it to move, resize and/or rotate the image as needed inside the film strip. I'm going to make my photo a bit smaller so more of it fits within the viewable area of the film strip, and I'm also going to rotate it a little. Notice that, even though we can only see the part of the photo that's within the film strip itself, the Free Transform box and handles appear around the actual edges of the image, which is much larger than what's visible in the film strip:
Resizing and rotating the image inside the film strip. Image licensed from iStockphoto by Photoshop Essentials.com
The Free Transform box and handles appear around the actual edges of the image in the film strip, even though only part of the image is visible.
If you can't see the Free Transform handles because your image is too big to fit inside the document window, press Ctrl+0 (Win) / Command+0 (Mac) to select the Fit on Screen command and have Photoshop resize the document window.
When you're happy with how the image looks inside the film strip, press Enter (Win) / Return (Mac) to accept the changes and exit out of the Free Transform command.

Step 30: Add Photos To The Other Film Strips

To add photos to the other film strips in the collage, simply repeat the same steps. First, open the image you want to place inside the film strip. Press Ctrl+A (Win) / Command+A (Mac) to select the entire image, then press Ctrl+C (Win) / Command+C (Mac) to copy it. Switch over to the photo collage document and twirl open the film strip's layer group. Select the photo area layer inside the layer group, then press Ctrl+V (Win) / Command+V (Mac) to paste the photo into the document directly above the "photo area" layer. Use the Move Tool to drag the photo into the gray area in the center of the film strip, then go up to the Layer menu and choose Create Clipping Mask to clip the photo to the shape on the "photo area" layer below it. Finally, press Ctrl+T (Win) / Command+T (Mac) to bring up the Free Transform command and resize, reposition and/or rotate the image inside the film strip as needed. Press Enter (Win) / Return (Mac) when you're done to accept the changes.
Here's my final photo collage after adding photos to the middle and bottom film strips:
Photoshop film strip photo collage effect. Image licensed from iStockphoto by Photoshop Essentials.com
The final photo collage after adding photos to the other film strips.
And there we have it!
 

 


 


continue reading "Film Strip Photo Collage in Photoshop"

Create Clean and Fresh Call-to-Action Button + Embossing Text Effect in Photoshop

Buzz It
submit to reddit StumbleUpon
For those who haven’t yet came across the idea of “Call-to-Action” button – basically they’re buttons that you would want all your users to click on when they land on your page. Usually they’ll be a link to a download, signup or sale. By making those buttons easy to easy and click on, you increase the likelyhood that user will notice the button, then follow up with relevant actions.
As for embossing text, they’re everywhere now on the web, and I personally quite like this particular effect :)
Here is a preview of the final effect for this tutorial: (click to enlarge)

OK let’s get started!

Step 1

Create a new document size 750px * 400px (size doesn’t really matter here) and fill this background layer with White. Create a new layer on top of the background layer called “gradient”, grab the Gradient Tool from the toolbox and fill it as shown below:
1 fill
I decide to use this light gradient because it’s easier to demonstrate several important points in the next few steps. You can of course try out darker ones.

Step 2

Let’s type some text on the canvas. I used this font because I personally feel it’s a very clean and bold font, which you can use for a wide range of headings, or descriptive text.
So type some sample text on the canvas as shown below: (use a slightly darker colour for font colour)
2 type
Appy the following layer blending option to the text layer:
Inner Shadow
2 inner sha
Stroke
2 stroke
And you will have the following effect to the text layer:
2 effect
See, that’s our embossing text effect done. Very simple, yet effective.

Step 3

Ok let’s get on with creating the call-to-action button. Use the Rounded Rectangular Tool with a 7px radius, draw a button on the canvas as shown below: (Make shape you select “shape layers” on top option bar)
3 shape layers
3 draw
Apply the following layer blending effect to this button:
Bevel and Emboss
3 bevel
Gradient Overlay
3 grad over
With the Gradient Colour, apply the following settings:
Location 0% – Color: #0083be
Location 99% – Color: #31c8fa
Location 100% – Color: #FFFFFF
3 grad setting
Stroke
3 stroke
And you will have the following effect:
3 effect

Step 4

Now we have a button background, let’s add some symbol onto it so it provides some kinds of graphical meaning. In this case, I decided to make this button a download button. So naturally I thought of a down arrow would mean something to the user.
So grab the Custom shape tool from the toolbox:
4 cust sha
and choose the bold arrow from the library as shown below:
4 arrow
Draw an arrow on the position as shown below, rotate it clockwise 90 degree when you done the drawing:
4 draw arrow
Apply the following layer blending options to the arrow layer:
Drop Shadow
4 drop sha
Gradient Overlay
4 grad over
Location 0% – Color: #09c228
Location 100% – Color: #b4ff97
4 grad over setting
Stroke
4 stroke
You will have the following effect so far:
4 effect

Step 5

Now we can type some text onto the button:
5 type
Apply the following layer blending options to the text layer:
Inner Glow
5 inner glow
Gradient Overlay
5 grad over
Stroke
5 stroke
and you will have the following effect:
5 effect

Step 6

Ok we’re almost done. To spice up the final effect, we can add some light and shadow to the button and text to increase their depth. To do this, create a new layer underneath the button background layer, grab a big soft brush with a dark colour, do a single click on the centre of the canvas:
6 shadow
Use free transform tool to resize it and position it as shown below:
6 resize
To create a light divider between the text and the button, simply create a new layer on top of the shadow layer, use a big soft brush with white colour, do a single click to the position as shown below:
6 light
Again we resize it and fit it to the postion under the text:
6 resize 2
and here is the final effect for this tutorial:



Final Thoughts

There are several things I think we need to pay attention to when it comes to making call-to-action buttons:
  1. Always try to use fresh, vibrant colour as button background, and make sure the color differs significantly from the rest.
  2. Apply gradient to the background creating more depth and make the button stand out
  3. Use graphic element and symbol on the button to make it more meaningful to visitors
  4. Use Light and shadows to draw user attentions.
continue reading "Create Clean and Fresh Call-to-Action Button + Embossing Text Effect in Photoshop"
Next Next home

RECENT COMMENTS

Grab This Widget

Random posts

 

Powered by FeedBurner

Subscribe to updates
Blog-Watch - The Blog Directory
Computers blogs
googlef97e20b47bd40d74.html
The Link Exchange - Your ultimate resource for link exchange!
Technology Blogs - Blog Rankings
Computers Blogs
GoLedy.com
Blog Directory
Technology Blogs - Blog Rankings
Blog Directory
Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine

I'm in

I'm in
Reddit [Mithun Mohan]

Follow me in twitter

Follow me in twitter
[Brilliant Computing]

See me in Delicious

See me in Delicious
Mithun Mohan

Find me in stumble upon

Find me in stumble upon
[Mithun Mohan]

Lets become friends in digg

Lets become friends in digg
[Brilliant Computing]

The Brilliant Computing community in Orkut

VISITORS

   
MyFreeCopyright.com Registered & Protected

TERMS AND CONDITIONS

Dear Visitors...
This blog does not contain uploaded files on the server but only provides direct links to download files.Navigate the links provided at your own risk.If any problem occurs like broken link or something or virus then you can contact me via 'Contact Me' found on top of this blog so that I can change the link.Dont hesitate to comment.If Any request or suggestions plz contact me.
DO THE HACKS POSTED HERE AT YOUR OWN RISK.
Thankyou for visiting my blog............enjoy

Protected by Copyscape Plagiarism Detector
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; } if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } } document.onmousedown = rtclickcheck;

Brilliant Computing Copyright © 2009 Brilliant Computing is Designed by Ipietoon Sponsored by Online Business Journal

Creative Commons License
Brilliant computing by Mithun is licensed under a Creative Commons Attribution-Noncommercial 2.5 India License.