Download Thumbnail From Youtube Video Using PHP code 2020

Hello Guys, In this tutorial of php code i will show you how to download thumbnail images from youtube video using PHP code 2020.After watching this tutorial You will be able to download any video thumbnail by searching youtube video url in textbox and choose also quality of image like HD quality, medium quality, low quality etc. So let start

To Download Thumbnail From Youtube Video Here are some steps below:-

Step 1: Create a HTML file and copy paste below code

We create a HTML file and save that file with a name thumbnail.html

So here we create a form with edittext to enter youtube video url and send it to php code for operation which is get_thumbnail.php page ande here we extract thumbnail from youtube url.

<html>
<head>
<link href="thumbnail_style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="wrapper">

<div class="thumbnail_div">
<form method="post" action="get_thumbnail.php">
<input type="text" name="url" placeholder="Enter URL">
<input type="submit" name="get_thumbnail" value="GET THUMBNAIL">
</form>
</div>

</div>
</body>
</html>

Step 2: Create a PHP file to download thumbnail from youtube video and copy paste below php code

We create a PHP file with get_thumbnail.php and save it.

In this step we get the youtube video url and get value video id by using explode() function which is after the 'v' variable in url. We use youtube image storing subdomain 'img.youtube.com' and write full path where youtube store its video thumbnail and write '0' which is the default video thumbnail.You can use 0, 1, 2 and 3 for different thumbnails of a particular video.You may also like upload image from url.

<?php
if(isset($_POST['get_thumbnail']))
{
 $url=$_POST['url'];
 $fetch=explode("v=", $url);
 $videoid=$fetch[1];

?>

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<table>
		<tr>
			<td>Default</td>
			<td><?PHP echo '<img src="http://img.youtube.com/vi/'.$videoid.'/default.jpg" width="auto"/>'; ?></td>
		</tr>
		<tr>
			<td>HQ</td>
			<td><?PHP echo '<img src="http://img.youtube.com/vi/'.$videoid.'/hqdefault.jpg" width="auto"/>'; ?></td>
		</tr>
		<tr>
			<td>mq</td>
			<td><?PHP echo '<img src="http://img.youtube.com/vi/'.$videoid.'/mqdefault.jpg" width="auto"/>'; ?></td>
		</tr>
		<tr>
			<td>SD</td>
			<td><?PHP echo '<img src="http://img.youtube.com/vi/'.$videoid.'/sddefault.jpg" width="auto"/>'; ?></td>
		</tr>
		<tr>
			<td>Full HD</td>
			<td><?PHP echo '<img src="http://img.youtube.com/vi/'.$videoid.'/maxresdefault.jpg" width="auto"/>'; ?></td>
		</tr>
	</table>
</body>
</html>

<?php } ?>

Step 3: Create a CSS file and copy paste below css code

We make a CSS file and save it with a name thumbnail_style.css

body

{

 margin:0 auto;

 padding:0px;

 text-align:center;

 width:100%;

 font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;

 background-color:#2C3E50;

}

#wrapper

{

 margin:0 auto;

 padding:0px;

 text-align:center;

 width:995px;

}

#wrapper h1

{

 margin-top:50px;

 font-size:45px;

 color:white;

}

#wrapper h1 p

{

font-size:18px;

}

.form_div input[type="text"]

{

 width:380px;

 height:50px;

 border-radius:2px;

 font-size:17px;

 padding-left:5px;

 border:1px solid silver;

}

.form_div input[type="submit"]

{

 width:150px;

 height:50px;

 border:none;

 border-radius:2px;

 font-size:15px;

 background-color:#7F8C8D;

 border-bottom:3px solid #616A6B;

 color:white;

 font-weight:bold;

}

If you like this tutorial comment your reviews

 

Enjoyed this article? Stay informed by joining our newsletter!

Comments
aayan - Nov 22, 2020, 1:48 PM - Add Reply

Great content

You must be logged in to post a comment.

You must be logged in to post a comment.

About Author