Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
peripherad
/
vendor
/
spatie
/
laravel-medialibrary
/
src
/
Conversions
/
ImageGenerators
:
Svg.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php namespace Spatie\MediaLibrary\Conversions\ImageGenerators; use Illuminate\Support\Collection; use Imagick; use ImagickPixel; use Spatie\MediaLibrary\Conversions\Conversion; class Svg extends ImageGenerator { public function convert(string $file, Conversion $conversion = null): string { $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg'; $image = new Imagick(); $image->readImage($file); $image->setBackgroundColor(new ImagickPixel('none')); $image->setImageFormat('jpg'); file_put_contents($imageFile, $image); return $imageFile; } public function requirementsAreInstalled(): bool { return class_exists(\Imagick::class); } public function supportedExtensions(): Collection { return collect(['svg']); } public function supportedMimeTypes(): Collection { return collect(['image/svg+xml']); } }