Download Youtube Videos using PHP Code

May 29th, 2008 by Sajith M.R

If you want to get the FLV file of any youtube video url using php code, here is the solution.

If you are a PHP Programmer and if you are working with any video website, and if you need to grab videos (FLV files) from youtube and to put it yourown site (not object embedding) , Download the Full Source Code given at the end of this article (ZIP)

I used this php code for the Youtube video download tool http://www.googleneedle.com


Here function getPatternFromUrl is nothing but, get the exact pattern of a particular video from any youtube video url format.

In the above case , it returns pzmP4UvZRa4

The function is below

function getPatternFromUrl($url)

 {

$url = $url.'&';

$pattern = '/v=(.+?)&+/';

preg_match($pattern, $url, $matches);

return ($matches[1]);

}

GetFlvFromYoutube is the main function here, which download the flv file from youtube pattern and saves to your local machine.
The function is below:

function GrabFlvFromYoutube( $pattern )
{

 require_once ("phptube.php");

 $tube = new PHPTube ();

 $flv_http_path = $tube->download($pattern) ;

 echo $flv_http_path;

 set_time_limit(0);

 $data = file_get_contents($flv_http_path);

 $new_flv_path = dirname(_FILE_).'/flvs/'.$pattern.'.flv' ;

 file_put_contents($new_flv_path, $data);

 return $new_flv_path ;

}

Download the fullsource code from this link given:

http://www.sajithmr.com/downloads/youtube-download-php.zip

Online Photoshop in PHP (Series Part 3)

May 26th, 2008 by Sajith M.R
This entry is part 3 of 5 in the series Online Photoshop

Resize a Photo >>

Today we will implement hows to resize photo into a particular width and height (or keeping aspect ratio)

See the live example from: http://www.sajithmr.com/photoshop-tuts/resize/resize.php

You need to install php-gd library to do this. To functions, imagecreatetruecolor and imagecopyresampled will do the resizing.

Those who have not seen the Online Photo Editing tool yet, have a look at: http://www.sajithmr.com/photoshop/index.php 

Here is the function:


function Resize($image,$new_width,$new_height=0)
{

 $old_width = imagesx($image);
 $old_height= imagesy($image);

 if($new_height==0) // if the height is not specified
                           //....calculate the relative height
 $new_height= $new_width * $old_height / $old_width ;

 $new_image= imagecreatetruecolor($new_width, $new_height);
 imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width,
 $new_height, $old_width, $old_height);
 return $new_image;

}

Here the $image is the object of the image which is created from the function imagecreatefromgif($path_to_photo), if the image is in GIF format.

Other functions are imagecreatefromjpeg and imagecreatefrompng for JPEG and PNG respectively .

Download Full source code for this example from: http://www.sajithmr.com/photoshop-tuts/resize.zip

In the previous part we implemented browse photos area. http://www.sajithmr.com/online-photoshop-in-php-series-part-2/

In that for browsing picture files, we used full size image, instead of thumbnails. Here new example , in which browse photos is implemented with image thumbnails using resizing (150 px)

The difference is , instead of calling img tag’s src to the orginal image path, called through resize.php?img=path_to_image , passed the image path as parameter to resize function.

See live example: http://www.sajithmr.com/photoshop-tuts/browse-resize/browse.php

Take the html and see the difference from old browse implementation: http://www.sajithmr.com/photoshop-tuts/browse.php

Which is fast ??

Download the full source code for browsing with image thumbnail from: http://www.sajithmr.com/photoshop-tuts/browse-resize.zip

Keep reading for the coming series,  part 4 , Orkut Like Photo Cropping >>

Subscribe to this website feed now:

Regards

Sajith M.R

Online Photoshop in PHP (Series Part 2)

May 21st, 2008 by Sajith M.R
This entry is part 2 of 5 in the series Online Photoshop

Implementation of the Browse Photos Area >>

Today we will implement the browse photos area of online photoshop

Those who haven’t seen the online photo editing tool, click on the above icon (baloon)

You can see the browse area implementation here: http://www.sajithmr.com/photoshop-tuts/browse.php

What you need for this is 4 php functions: is_dir , opendir, readdir, filetype

Normal file browsing can be implemented using while loop with above four functions.

See its usage:

if (is_dir($dir)){if ($dh = opendir($dir)){

while ( ($file = readdir($dh)) !== false   )

{

if($file != '.' &&  $file != '..')

{

//if it is a directory show folder icon

if(  filetype($dir .$dir_sep. $file) == "dir"   )

{

//display a folder icon here with folder name using img tag

}

else

{

// display image here in img tag

}

}

}

}

}

The whole source code is here: http://www.sajithmr.com/photoshop-tuts/browse.zip

Online Photoshop in PHP (Series Part 1)

May 20th, 2008 by Sajith M.R
This entry is part 1 of 5 in the series Online Photoshop

Introduction >>

Online Photoshop in PHP (Series Part 1)

As i announced in my birthday post: celebrating-1st-year-of-sajithmr.com , i am starting my post series How to make Photoshop Express in PHP

Before we starting the step by step procedure, have a look at : http://www.sajithmr.com/photoshop/index.php

This is a basic version of online photo editing tool.

You can either upload a photo to this tool or you can browse some images already supplied.

The basic features are:

  1. Crop
  2. Resize
  3. Water marking (Both logo and text)
  4. Round corner
  5. Rotate
  6. Download and save

Try yourself

Upload some picture (or browse any picture), Press crop button (top left), you can see orkut photo upload like crop there. You can select the area, or drag anywhere in the image. Press crop button in the workdesk. (Press F11 or fullscreen view for better performance )

Try all other features provided.

The whole site is divided into four parts.

  1. Tools
  2. Work Desk
  3. Browse Photos
  4. Settings

Tools area contains options for crop, resize, watermark, round, undo , save, clear all, download.

Here ‘clear all’ reset all the operations and navigate the website into initial settings.

From the Settings Area, You can fix the angle of the image. You can rotate either clock-wise or anti-clock-wise depending on the angle provided (+ve or -ve)

In Text Water Mark Setting Area, you can enter a text, set font size and font color. It generates a pictures corresponding to your text. Click water mark button in tool area and fix the position , press Apply Watermark

You can also upload your water mark logo.

Finally you can download the edited picture by clicking download button in the Tool area (top right) .

The interesting thing is the whole website / tool is created in a single day.

wanna learn how to implement this ??

Keep reading rest of the series.

In Online Photoshop in PHP (Series Part 2) >> Implementation of the Browse Photos Area

Thanks and Regards
Sajith M.R

Gmail Chat Implementation

May 7th, 2008 by Sajith M.R
This entry is part 3 of 3 in the series Gmail Architecture

Today i implemented gmail chat window , not an ajax chat with a chat server, but its client side implementation.

Here you can see the demo: http://www.sajithmr.com/gtalk/

Take this link in a new tab or window, and take any other website without closing it.

After 3 seconds , (Consider it as a new chat message arrived situation) you can see the google chat notification sound , and title changing. (I didn’t get the actual gtalk notification sound, so i used windows notify.wav file )

You know google (gmail) implemented its sound notification is via swf object. Here me too done the same.

I wrote two function to check whether the browser is in focus or not.


Here is the functions:

function lostFocus()
{
document.title = 'Sajith M.R Says...';
state = 'nonfocus';

played =  0 ;

changeColorRed();

alterTitle();

}

function gotFocus()
{
document.title = 'Gmail Inbox(1)';

state = 'focus';

played = 0 ;
}

The alterTitle() function calls in 3 seconds setTimeOut manner.

function alterTitle()
{

if(state =='nonfocus')

{
if ( document.title == 'Gmail Inbox(1)')
{

if(played == 0)
{
soundManager.play('notify');
played = 1;
}

document.title = 'Sajith M.R Says...';

}
else
document.title = 'Gmail Inbox(1)';

setTimeout("alterTitle()",3000);

}
}

The soundmanager.js file handles the swf flash object and sound triggering.

<script type=”text/javascript” src=”script/soundmanager.js”></script>

These three simple scripts together created this demo: http://www.sajithmr.com/gtalk/

If you want the whole source code , mail me: admin@sajithmr.com

Comment Please …

Regards

Sajith.M.R
http://www.sajith.name

Google Needle - The Exclusive Tool For Google Services

May 7th, 2008 by Sajith M.R

Google Needle Logo

Yesterday i just started a tool for measuring some services of google. This small tool / needle , I started with google page rank checking engine.

It is GoogleNeedle, http://www.googleneedle.com

Later added two more features.

1) Keyword - Url-Pagination

2) Youtube Video Downloads

Here Keyword-URL-Pagination helps to find in which page of google search results , your url / website is found , for a particular keyword. For example the keyword “sexy status message” search on google.com shows my website www.sajithmr.com in 8th page from www.google.com and in the 1st page from www.google.co.in

You can also check your website indexing in google search from different county aspects.

The 2nd tool youtube video downloader is for downloading flv file of youtube video from youtube video url.

Finally my previous and very famous wordpress pagerank plugin’s download option is also included in this ‘GoogleNeedle

Of course this Needle will measure your google, and its services.

Let me know which are the other tools you needed here. Feel free to comment. I will try my best.

Regards

Sajith. M.R
http://www.googleneedle.com

Youtube Images - What an Idea !!!

May 3rd, 2008 by Sajith M.R

Look at the given image carefully …

Youtube Master Image

Did anybody see the above image anywhere ? The Answer might be No. But you might see small parts of this picture. The amazing picture’s name is Youtube Master Image. The Youtube Website contains this single image only, and it uses part by part for different occasions with css ( sytle sheet) property background image and scroll position.

You know the whole youtube website is created with a single image !!!

For example, you see the rating pictures just below the youtube video

Youtube Ratings

Here the fully red star is created by:

<img class=”rating icn_star_full_19×20png alt=” style=”vertical-align: top; src=”http://s.ytimg.com/yt/img/pixel-vfl73.gif/>

Here the src is merely a 1 pixel image. The actual star lies in the style class “rating icn_star_full_19×20png”

See the style sheet:

.icn_star_full_19x20png

{

   transparent url("http://s.ytimg.com/yt/img/master-vfl38353.gif") no-repeat scroll -373px -38px

}

Here scroll -373px and -38px exactly points the red star in the master image.

And for youtube logo, it uses same background image (master image) with another scroll location. Scroll is set to 0px for logo

Like that, all the images, thumbs up , thumbs down, border, scroll back, previous next buttons etc etc are displayed from this single picutre.

Amazing Idea Right ?

(Post your comments please)