The first step for creating a custom generator is to create a class that extends Spatie\MediaLibrary\ImageGenerators:
useIlluminate\Support\Collection;
useSpatie\MediaLibrary\Conversion\Conversion;
useSpatie\MediaLibrary\ImageGenerators\BaseGenerator;
classPowerPointextendsBaseGenerator
{
/**
* This function should return a path to an image representation of the given file.
*/publicfunctionconvert(string $file, Conversion $conversion = null) : string
{
$pathToImageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg';
// Here you should convert the file to an image and return generated conversion path.\PowerPoint::convertFileToImage($file)->store($imageFile);
return$imageFile;
}
publicfunctionrequirementsAreInstalled() : bool
{
returntrue;
}
publicfunctionsupportedExtensions() : Collection
{
returncollect(['ppt', 'pptx']);
}
publicfunctionsupportedMimeTypes() : Collection
{
returncollect([
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
]);
}
}
If you want the generator to be applied to all your models, you can override the Media class as explained in the
using your own model page and modify the
getImageGenerators method in your own Media class.
If the generator only needs to be applied to one of your models you can override the getImageGenerators in that model like this: