How to get thumbnail snapshot of video and pdf file in php - php

Can anyone help me out that how i can display video and pdf file as thumbnail??
Thanks..............

For the PDF you can use Imagick.
How it's done is here in great detail
For the video snapshot, you can use FFMPEG. Here's an example code.
// this will create many images
$thumb = exec("ffmpeg -i video.mpg image%d.jpg");

Use ImageMagick's PHP class. Supports both video and PDF.

Related

I want to convert a video link to an m3u8 file

I want to convert a video link to an m3u8 file That means I can give a video for the input of the link and I can watch the same video with the extension m3u8 for the output.
Please help me with this.
You should use ffpmeg and ffprobe for video converting / procesing.
try this library PHP-FFmpeg-video-streaming

PHP QR Code scan from PDF file

I have a PDF file with a QR Code. Iuploaded the file on the server folder named "tmp" and now I need to scan and convert this QR via PHP.
I found this library:
include_once('lib/QrReader.php');
$qrcode = new QrReader('/var/tmp/qrsample.png');
$text = $qrcode->text(); //return decoded text from QR Code
print $text;
But this works only for png/jpeg files.
Is there any way to scan PDF ? Is there any way to convert PDF to png only the time that I need ?
Thank you!
First, transform your PDF into an image with Imagick, then use your library to decode the QRcode from it:
include_once('lib/QrReader.php');
//the PDF file
$pdf = 'mypdf.pdf';
//retrieve the first page of the PDF as image
$image = new imagick($pdf.'[0]');
//pass it to the QRreader library
$qrcode = new QrReader($image, QrReader::SOURCE_TYPE_RESOURCE);
$text = $qrcode->text(); //return decoded text from QR Code
print $text;
//clear the resources used by Imagick
$image->clear();
You would want to convert the PDF to a supported image type, OR find a QR code reading library that supports PDFs. IMO the first option is easier. A quick search leads me to http://www.phpgang.com/how-to-convert-pdf-to-jpeg-in-php_498.html for a PDF -> img converter.
Presumably the QR code is embedded in the PDF as an image. You could use a command-line tool such as pdfimages to extract the image first, then run your QRReader library on the extracted image. You might need a bit of trial and error to establish which image is the QR code if there is more than one image in the PDF.
See extract images from PDF with PHP for more detail.

PDF Image thumbnail preview in laravel 5.1?

I have file module, where I want to list all files,with thumbnail preview.
as like follows,
I am storing files in storage folder,which is not accessible via http.
So How can I provide thumbnail preview for docs especially image and PDF.
Is there any package availabe in laravel 5.1?
The preview image of a PDF file is usually the first page of the PDF file.
You can use ImageMagick to obtain that first page of the PDF file.
<?php
$imagick = new imagick('sample.pdf[0]'); // 0 specifies the first page of the pdf
$imagick->setImageFormat('jpg'); // set the format of the output image
header('Content-Type: image/jpeg'); // set the header for the browser to understand
echo $imagick; // display the image
?>
You can also output (save the contents of the image in a file) and store it under a thumbnail folder with the PDF name as the file name. like ( sample.jpg )
As for a solution based on laravel, I don't think laravel has any package that can do the same
Though the question was posted quite a long ago but I'm answering because it might helps others. There is a package for generating image from pdf. Pdf to Image. You should have Imagick and Ghostscript installed

PDF to Image Conversion - PHP

Note: PDF files would be uploaded by user.
I am making a document sharing website(pdf). I don't want users to be able to copy/select the pdf file text. I am looking for a nice PDF/Image Document viewer. Currently using the following method:
I am using imagemagick to convert PDF file to Jpeg. But the process is too slow even after disabling OpenMP. I was looking forward to convert full PDF to different image files but decided to just convert the first image to a thumbnail because the process is so slow.
I am using it on my local machine and it takes more than 30 seconds to convert 40-50 pages in good quality. So if there are pdf files more than 100 pages, this process would ruin the user experience.
Is there any way to convert PDF to Image files?
Also is there a way to let this process (pdf to image) happen asynchronously? Like the user filling out file details while the pdf is being uploaded and converted, something like YT videos?
Enter the command in exec() function, this will help you out
<?php
$pdf_url = 'testfile.pdf'; // Url of the PDF
$image_name = 'output.jpg'; // Set the image name
exec('convert "'.$pdf_url.'" -colorspace RGB -resize 800 "'.$image_name.'"', $output, $return_var);
?>
Hope this helps you
¿You use a linux sever?
Just use convert command and put [0] sufix to pdf file for save a cover:
exec("convert '/home/sample.pdf[0]' '/home/test.png'");

PHP: how to create an image from another PNG image

I have a small Minecraft server where people can upload their skins. Minecraft skins are small png images. Is it possible to convert this png image to another png image via PHP (e.g. GD library)?
I have made this image to help me explain what I am trying to do:
Yes, it's possible. You'd need multiple imagecopy commands to pull out sections of the skin image and paste it into the proper spots in the "output" image.
Basic order of operations would be:
$input = imagecreatefrompng('skin.png');
$output = imagecreatetruecolor(800, 600); // whatever the dimensions should be.
imagecopy($output, $input, 0,0, 10,20, 50,60);
imagecopy(...);
...
...
The first copy command is saying "take a 50x60 section of the input image, starting at coordinates 10x20, and paste it into the destination image in the top left corner".
The actual sequence/coordinates/sizes will be up to you to figure out.
If you're not doing a 1:1 copy of the image and are doing resizing, then you'll want imagecopyresampled() instead.
Here is the PHP manual for creating images from png :
http://php.net/manual/en/function.imagecreatefrompng.php
Here is a simple tutorial :
http://www.phptutorial.info/?imagecreatefrompng
You can do this with CSS
Here is a tutorial: http://www.w3schools.com/css/css_image_sprites.asp

Categories