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

declare(strict_types=1);

namespace 
InterventionImageDriversGdEncoders;

use 
GdImage;
use 
InterventionImageDriversGdCloner;
use 
InterventionImageEncodedImage;
use 
InterventionImageEncodersPngEncoder as GenericPngEncoder;
use 
InterventionImageExceptionsAnimationException;
use 
InterventionImageExceptionsColorException;
use 
InterventionImageExceptionsRuntimeException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;

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

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

    
/**
     * Prepare given image instance for PNG format output according to encoder settings
     *
     * @param ImageInterface $image
     * @throws RuntimeException
     * @throws ColorException
     * @throws AnimationException
     * @return GdImage
     */
    
private function prepareOutput(ImageInterface $image): GdImage
    
{
        if (
$this->indexed) {
            
$output = clone $image;
            
$output->reduceColors(255);

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

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