Using image generators | laravel-medialibrary | Spatie

 SPATIE

  Laravel Media Library
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-medialibrary](https://spatie.be/docs/laravel-medialibrary/v5)  Converting-other-file-types  Using image generators

 Version   v11   v10   v9   v8   v7   v6   v5   v4   v3

 Other versions for crawler [v11](https://spatie.be/docs/laravel-medialibrary/v11) [v10](https://spatie.be/docs/laravel-medialibrary/v10) [v9](https://spatie.be/docs/laravel-medialibrary/v9) [v8](https://spatie.be/docs/laravel-medialibrary/v8) [v7](https://spatie.be/docs/laravel-medialibrary/v7) [v6](https://spatie.be/docs/laravel-medialibrary/v6) [v5](https://spatie.be/docs/laravel-medialibrary/v5) [v4](https://spatie.be/docs/laravel-medialibrary/v4) [v3](https://spatie.be/docs/laravel-medialibrary/v3)

  Using image generators
- [ Introduction ](https://spatie.be/docs/laravel-medialibrary/v5/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-medialibrary/v5/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-medialibrary/v5/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-medialibrary/v5/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-medialibrary/v5/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-medialibrary/v5/changelog)
- [ About us ](https://spatie.be/docs/laravel-medialibrary/v5/about-us)

Basic usage
-----------

- [ Preparing your model ](https://spatie.be/docs/laravel-medialibrary/v5/basic-usage/preparing-your-model)
- [ Associating files ](https://spatie.be/docs/laravel-medialibrary/v5/basic-usage/associating-files)
- [ Retrieving media ](https://spatie.be/docs/laravel-medialibrary/v5/basic-usage/retrieving-media)
- [ Working with collections ](https://spatie.be/docs/laravel-medialibrary/v5/basic-usage/working-with-collections)

Converting images
-----------------

- [ Defining conversions ](https://spatie.be/docs/laravel-medialibrary/v5/converting-images/defining-conversions)
- [ Retrieving converted images ](https://spatie.be/docs/laravel-medialibrary/v5/converting-images/retrieving-converted-images)
- [ Regenerating images ](https://spatie.be/docs/laravel-medialibrary/v5/converting-images/regenerating-images)

Converting other file types
---------------------------

- [ Using image generators ](https://spatie.be/docs/laravel-medialibrary/v5/converting-other-file-types/using-image-generators)
- [ Creating a custom image generator ](https://spatie.be/docs/laravel-medialibrary/v5/converting-other-file-types/creating-a-custom-image-generator)

Advanced usage
--------------

- [ Working with multiple filesystems ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/working-with-multiple-filesystems)
- [ Adding custom properties ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/adding-custom-properties)
- [ Generating custom urls ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/generating-custom-urls)
- [ Storing media specific manipulations ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/storing-media-specific-manipulations)
- [ Using your own model ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/using-your-own-model)
- [ Using a custom directory structure ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/using-a-custom-directory-structure)
- [ Ordering media ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/ordering-media)
- [ Consuming events ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/consuming-events)
- [ Overriding default filesystem behavior ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/overriding-the-default-filesystem-behaviour)
- [ Soft deleting ](https://spatie.be/docs/laravel-medialibrary/v5/advanced-usage/soft-deletes)

API
---

- [ Adding files ](https://spatie.be/docs/laravel-medialibrary/v5/api/adding-files)
- [ Defining conversions ](https://spatie.be/docs/laravel-medialibrary/v5/api/defining-conversions)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-medialibrary                                                                                                                                                                                                                                    `

Using image generators
======================

###  On this page

1. [ PDF ](#content-pdf)
2. [ SVG ](#content-svg)
3. [ Video ](#content-video)

As explained in the [Defining conversions](/laravel-medialibrary/v5/converting-images/defining-conversions/) section this package use [Glide](http://glide.thephpleague.com/) 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](/laravel-medialibrary/v5/converting-other-file-types/using-image-generators#pdf)
- [SVG](/laravel-medialibrary/v5/converting-other-file-types/using-image-generators#svg)
- [Video](/laravel-medialibrary/v5/converting-other-file-types/using-image-generators#video)

PDF
-----------------------------------------------------------------

The only requirement to perform a conversion of a PDF file is [Imagick](http://php.net/manual/en/imagick.setresolution.php).

SVG
-----------------------------------------------------------------

The only requirement to perform a conversion of a SVG file is [Imagick](http://php.net/manual/en/imagick.setresolution.php).

Video
-----------------------------------------------------------------------

The video image generator uses the [PHP-FFMpeg](https://github.com/PHP-FFMpeg/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](https://ffmpeg.org/download.html).

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:

```

  Your browser does not support the video tag.

```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
