Вход Регистрация
Файл: vendor/intervention/gif/src/Encoders/GifDataStreamEncoder.php
Строк: 107
<?php

declare(strict_types=1);

namespace 
InterventionGifEncoders;

use 
InterventionGifBlocksCommentExtension;
use 
InterventionGifBlocksFrameBlock;
use 
InterventionGifExceptionsEncoderException;
use 
InterventionGifGifDataStream;

class 
GifDataStreamEncoder extends AbstractEncoder
{
    
/**
     * Create new instance.
     */
    
public function __construct(GifDataStream $entity)
    {
        
parent::__construct($entity);
    }

    
/**
     * Encode current entity.
     *
     * @throws EncoderException
     */
    
public function encode(): string
    
{
        return 
implode('', [
            
$this->entity->header()->encode(),
            
$this->entity->logicalScreenDescriptor()->encode(),
            
$this->maybeEncodeGlobalColorTable(),
            
$this->encodeFrames(),
            
$this->encodeComments(),
            
$this->entity->trailer()->encode(),
        ]);
    }

    
/**
     * Decode global color table if present in gif data.
     */
    
private function maybeEncodeGlobalColorTable(): string
    
{
        if (!
$this->entity->hasGlobalColorTable()) {
            return 
'';
        }

        return 
$this->entity->globalColorTable()->encode();
    }

    
/**
     * Encode data blocks of source.
     *
     * @throws EncoderException
     */
    
private function encodeFrames(): string
    
{
        return 
implode(''array_map(
            
fn(FrameBlock $frame): string => $frame->encode(),
            
$this->entity->frames(),
        ));
    }

    
/**
     * Encode comment extension blocks of source.
     *
     * @throws EncoderException
     */
    
private function encodeComments(): string
    
{
        return 
implode(''array_map(
            
fn(CommentExtension $commentExtension): string => $commentExtension->encode(),
            
$this->entity->comments()
        ));
    }
}
Онлайн: 1
Реклама