Download YouTube Video Thumbnail [Source Codes]
To create this program [Download YouTube Video Thumbnail]. First, you need to create two Files one PHP File and another one is CSS File. After creating these files just paste the following codes into your file. First, create a PHP file with the name of index.php and paste the given codes into your PHP file. Remember, you’ve to create a file with .php extension.
if(isset($_POST['button'])){
$imgUrl = $_POST['imgurl'];
$ch = curl_init($imgUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$downloadImg = curl_exec($ch);
header('Content-type: image/jpg');
header('Content-Disposition: attachment;filename="thumbnail.jpg"');
<!-- Coding By CodingNepal - youtube.com/codingnepal -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Download YouTube Video Thumbnail | CodingNepal</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<header>Download Thumbnail</header>
<span class="title">Paste video url:</span>
<input type="text" placeholder="https://www.youtube.com/watch?v=lqwdD2ivIbM" required>
<input class="hidden-input" type="hidden" name="imgurl">
<span class="bottom-line"></span>
<div class="preview-area">
<img class="thumbnail" src="" alt="">
<i class="icon fas fa-cloud-download-alt"></i>
<span>Paste video url to see preview</span>
<button class="download-btn" type="submit" name="button">Download Thumbnail</button>
const urlField = document.querySelector(".field input"),
previewArea = document.querySelector(".preview-area"),
imgTag = previewArea.querySelector(".thumbnail"),
hiddenInput = document.querySelector(".hidden-input"),
button = document.querySelector(".download-btn");
let imgUrl = urlField.value;
previewArea.classList.add("active");
button.style.pointerEvents = "auto";
if(imgUrl.indexOf("https://www.youtube.com/watch?v=") != -1){
let vidId = imgUrl.split('v=')[1].substring(0, 11);
let ytImgUrl = `https://img.youtube.com/vi/${vidId}/maxresdefault.jpg`;
}else if(imgUrl.indexOf("https://youtu.be/") != -1){
let vidId = imgUrl.split('be/')[1].substring(0, 11);
let ytImgUrl = `https://img.youtube.com/vi/${vidId}/maxresdefault.jpg`;
}else if(imgUrl.match(/\.(jpe?g|png|gif|bmp|webp)$/i)){
button.style.pointerEvents = "none";
previewArea.classList.remove("active");
hiddenInput.value = imgTag.src;
Second, create a CSS file with the name of style.css and paste the given codes in your CSS file. Remember, you’ve to create a file with .css extension.
/* Import Google font - Poppins & Noto */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;600;700&family=Poppins:wght@400;500;600&display=swap');
font-family: "Poppins", sans-serif;
box-shadow: 10px 10px 13px rgba(0,0,0,0.1);
border-bottom: 2px solid #ccc;
font-family: 'Noto Sans', sans-serif;
.url-input .field input::placeholder{
.url-input .field .bottom-line{
transition: transform 0.3s ease;
.url-input .field input:focus ~ .bottom-line,
.url-input .field input:valid ~ .bottom-line{
border: 2px dashed #8e46ec;
.preview-area .thumbnail{
.preview-area.active .thumbnail{
.preview-area.active .icon,
.preview-area.active span{
transition: background 0.3s ease;
@media screen and (max-width: 460px){
That’s all, now you’ve successfully created a project on Download YouTube Video Thumbnail using HTML CSS JavaScript & PHP. If your code does not work or you’ve faced any error/problem then please download the source code files from the given download button. It’s free and a .zip file will be downloaded then you’ve to extract it.
After extracting, move this folder inside htdocs of your XAMPP installation directory and start the apache server from xampp control panel and then open this url – localhost/thumbnail or localhost/thumbnail/index.php in your browser.
Download Disini
Post a Comment