Вход Регистрация
Файл: vendor/intervention/image/src/Drivers/Gd/Encoders/JpegEncoder.php
Строк: 110
<?php

declare(strict_types=1);

namespace 
InterventionImageDriversGdEncoders;

use 
InterventionImageColorsRgbColor as RgbColor;
use 
InterventionImageColorsRgbColorspace as Rgb;
use 
InterventionImageDriversGdCloner;
use 
InterventionImageEncodersJpegEncoder as GenericJpegEncoder;
use 
InterventionImageExceptionsDriverException;
use 
InterventionImageExceptionsStreamException;
use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageExceptionsStateException;
use 
InterventionImageInterfacesEncodedImageInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;

class 
JpegEncoder extends GenericJpegEncoder implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see EncoderInterface::encode()
     *
     * @throws InvalidArgumentException
     * @throws StateException
     * @throws ModifierException
     * @throws DriverException
     * @throws StreamException
     */
    
public function encode(ImageInterface $image): EncodedImageInterface
    
{
        
$backgroundColor $this->driver()->decodeColor(
            
$this->driver()->config()->backgroundColor,
        )->
toColorspace(Rgb::class);


        if (!
$backgroundColor instanceof RgbColor) {
            throw new 
ModifierException('Failed to normalize background color to rgb color space');
        }

        
$output Cloner::cloneBlended(
            
$image->core()->native(),
            
background$backgroundColor,
        );

        return 
$this->createEncodedImage(function ($stream) use ($output): void {
            
imageinterlace($output$this->progressive);
            
imagejpeg($output$stream$this->quality);
        }, 
'image/jpeg');
    }
}
Онлайн: 1
Реклама