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

declare(strict_types=1);

namespace 
InterventionImageDriversGdEncoders;

use 
GdImage;
use 
InterventionImageDriversGdCloner;
use 
InterventionImageEncodersPngEncoder as GenericPngEncoder;
use 
InterventionImageExceptionsDriverException;
use 
InterventionImageExceptionsStreamException;
use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageInterfacesEncodedImageInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;

class 
PngEncoder extends GenericPngEncoder implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see EncoderInterface::encode()
     *
     * @throws InvalidArgumentException
     * @throws StreamException
     * @throws DriverException
     */
    
public function encode(ImageInterface $image): EncodedImageInterface
    
{
        
$output $this->prepareOutput($image);

        return 
$this->createEncodedImage(function ($stream) use ($output): void {
            
imageinterlace($output$this->interlaced);
            
imagepng($output$stream, -1);
        }, 
'image/png');
    }

    
/**
     * Prepare given image instance for PNG format output according to encoder settings
     *
     * @throws InvalidArgumentException
     * @throws DriverException
     */
    
private function prepareOutput(ImageInterface $image): GdImage
    
{
        if (
$this->indexed) {
            
$output = clone $image;
            
$output->reduceColors(256);

            return 
$output->core()->native();
        }

        return 
Cloner::clone($image->core()->native());
    }
}
Онлайн: 1
Реклама