Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 2.16 KB

using-image-generators.md

File metadata and controls

59 lines (43 loc) · 2.16 KB
title weight
Using image generators
1

As explained in the Defining conversions section this package use Glide under the hood which only perform conversions on images files.

To generate conversions of other media types – most notably PDFs and videos – the medialibrary uses a image generators to create a derived image file of the media.

Conversion of specific file type are defined in the exact same way as images:

$this->addMediaConversion('thumb')
     ->width(368)
     ->height(232)
     ->performOnCollections('videos');

The medialibrary includes image generators for the following file types:

PDF

The only requirement to perform a conversion of a PDF file is Imagick.

SVG

The only requirement to perform a conversion of a SVG file is Imagick.

Video

The video image generator uses the PHP-FFMpeg package that you can install via composer:

$ composer require php-ffmpeg/php-ffmpeg

You'll also need to follow FFmpeg installation instructions on their official website.

The video image generator allows you to choose at which time of the video the derived file should be created using the setExtractVideoFrameAtSecond on the conversion.

$this->addMediaConversion('thumb')
     ->width(368)
     ->height(232)
     ->extractVideoFrameAtSecond(20)
     ->performOnCollections('videos');

Once the conversion is created you can easily use the thumbnail in a html video tag for example:

<video controls poster="{{ $video->getUrl('thumb') }}">
  <source src="{{ $video->getUrl() }}" type="video/mp4">
  Your browser does not support the video tag.
</video>