HOME


Mini Shell 1.0
DIR: /home/cardxfeb/www/vendor/spatie/laravel-medialibrary/src/Conversions/ImageGenerators/
Upload File :
Current File : //home/cardxfeb/www/vendor/spatie/laravel-medialibrary/src/Conversions/ImageGenerators/Webp.php
<?php

namespace Spatie\MediaLibrary\Conversions\ImageGenerators;

use Illuminate\Support\Collection;
use Spatie\MediaLibrary\Conversions\Conversion;

class Webp extends ImageGenerator
{
    public function convert(string $file, Conversion $conversion = null): string
    {
        $pathToImageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.png';

        $image = imagecreatefromwebp($file);

        imagepng($image, $pathToImageFile, 9);

        imagedestroy($image);

        return $pathToImageFile;
    }

    public function requirementsAreInstalled(): bool
    {
        if (! function_exists('imagecreatefromwebp')) {
            return false;
        }

        if (! function_exists('imagepng')) {
            return false;
        }

        if (! function_exists('imagedestroy')) {
            return false;
        }

        return true;
    }

    public function supportedExtensions(): Collection
    {
        return collect(['webp']);
    }

    public function supportedMimeTypes(): Collection
    {
        return collect(['image/webp']);
    }
}