rosell-dk / webp-convert

Convert jpeg/png to webp with PHP (if at all possible)
MIT License
576 stars 101 forks source link

Converting time takes too long #336

Closed inajaf closed 2 years ago

inajaf commented 2 years ago

Guys, when trying to upload 5 mb jpeg, then it takes too long for converting. What kind of issue it could be? Here is my class for converting.

class ImageConverter
{

    /**
     * @throws ConversionFailedException
     */
    public function convertImage($file, string $generatedName, string $folderName): void
    {
        $uploadPath = Yii::getAlias('@common/web/uploads/') . $folderName . '/';

        WebPConvert::convert($file->tempName, $uploadPath . $generatedName, $this->getConvertOptions());

    }

    public static function getConvertOptions(): array
    {
        return [
            'png' => [
                'encoding' => 'auto',
                'near-lossless' => 60,
                'quality' => 80,
                'sharp-yuv' => true,
            ],
            'jpeg' => [
                'encoding' => 'auto',
                'quality' => 80,
                'sharp-yuv' => true,
            ],
            'jfif' => [
                'encoding' => 'auto',
                'quality' => 80,
                'sharp-yuv' => true,
            ]
        ];
    }
}
inajaf commented 2 years ago

Fixed by using Gd::convert instead of WebConverter::convert