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

declare(strict_types=1);

namespace 
InterventionImageDriversImagickEncoders;

use 
Imagick;
use 
ImagickException;
use 
InterventionImageEncodedImage;
use 
InterventionImageEncodersPngEncoder as GenericPngEncoder;
use 
InterventionImageExceptionsEncoderException;
use 
InterventionImageExceptionsStreamException;
use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageExceptionsStateException;
use 
InterventionImageInterfacesEncodedImageInterface;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;

class 
PngEncoder extends GenericPngEncoder implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see EncoderInterface::encode()
     *
     * @throws InvalidArgumentException
     * @throws StreamException
     * @throws StateException
     * @throws EncoderException
     */
    
public function encode(ImageInterface $image): EncodedImageInterface
    
{
        try {
            if (
$this->indexed) {
                
// reduce colors
                
$output = clone $image;
                
$output->reduceColors(256);

                
$output $output->core()->native();
                
$output->setFormat('PNG');
                
$output->setImageFormat('PNG');
            } else {
                
$output = clone $image->core()->native();
                
$output->setFormat('PNG32');
                
$output->setImageFormat('PNG32');
            }

            
$output->setCompression(Imagick::COMPRESSION_ZIP);
            
$output->setImageCompression(Imagick::COMPRESSION_ZIP);

            if (
$this->interlaced) {
                
$output->setInterlaceScheme(Imagick::INTERLACE_LINE);
            }

            
$result = new EncodedImage($output->getImagesBlob(), 'image/png');
            
$output->clear();

            return 
$result;
        } catch (
ImagickException $e) {
            throw new 
EncoderException('Failed to encode png format'previous$e);
        }
    }
}
Онлайн: 2
Реклама