1. Go to this page and download the library: Download lakshmaji/thumbnail library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace Trending\Http\Controllers\File;
use Carbon;
use Thumbnail;
use Illuminate\Http\Request;
use Trending\Http\Controllers\Controller;
/**
* -----------------------------------------------------------------------------
* ThumbnailTest - a class illustarting the usage og Thumbnail package
* -----------------------------------------------------------------------------
* This class having the functionality to upload a video file
* and generate corresponding thumbnail
*
* @since 1.0.0
* @version 1.0.0
* @author lakshmaji
*/
class ThumbnailTest extends AnotherClass
{
public function testThumbnail()
{
// get file from input data
$file = $this->request->file('file');
// get file type
$extension_type = $file->getClientMimeType();
// set storage path to store the file (actual video)
$destination_path = storage_path().'/uploads';
// get file extension
$extension = $file->getClientOriginalExtension();
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$file_name = $timestamp;
$upload_status = $file->move($destination_path, $file_name);
if($upload_status)
{
// file type is video
// set storage path to store the file (image generated for a given video)
$thumbnail_path = storage_path().'/images';
$video_path = $destination_path.'/'.$file_name;
// set thumbnail image name
$thumbnail_image = $fb_user_id.".".$timestamp.".jpg";
// set the thumbnail image "palyback" video button
$water_mark = storage_path().'/watermark/p.png';
// get video length and process it
// assign the value to time_to_image (which will get screenshot of video at that specified seconds)
$time_to_image = floor(($data['video_length'])/2);
$thumbnail_status = Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,$time_to_image);
if($thumbnail_status)
{
echo "Thumbnail generated";
}
else
{
echo "thumbnail generation has failed";
}
}
}
}
// end of class ThumbnailTest
// end of file ThumbnailTest.php