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

declare(strict_types=1);

namespace 
InterventionImageDriversGdModifiers;

use 
GdImage;
use 
InterventionImageExceptionsColorDecoderException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageExceptionsStateException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersDrawPolygonModifier as GenericDrawPolygonModifier;

class 
DrawPolygonModifier extends GenericDrawPolygonModifier implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see ModifierInterface::apply()
     *
     * @throws ModifierException
     * @throws StateException
     * @throws ColorDecoderException
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        foreach (
$image as $frame) {
            if (
$this->drawable->hasBackgroundColor()) {
                
$color $this->driver()->colorProcessor($image)->export($this->backgroundColor());
                
$this->drawPolygonBackground($frame->native(), $color);
            }

            if (
$this->drawable->hasBorder()) {
                
$borderColor $this->driver()->colorProcessor($image)->export($this->borderColor());
                
$this->drawPolygonBorder($frame->native(), $borderColor);
            }
        }

        return 
$image;
    }

    
/**
     * Draw polygon background in given color.
     *
     * @throws ModifierException
     */
    
private function drawPolygonBackground(GdImage $canvasint $color): void
    
{
        
imagealphablending($canvastrue);
        
imagesetthickness($canvas0);
        
$this->abortUnless(
            
imagefilledpolygon(
                
$canvas,
                
$this->drawable->toArray(),
                
$color,
            ),
            
'Unable to draw polygon background',
        );
    }

    
/**
     * Draw polygon border in given color.
     *
     * @throws ModifierException
     */
    
private function drawPolygonBorder(GdImage $canvasint $borderColor): void
    
{
        
imagealphablending($canvastrue);
        
imagesetthickness($canvas$this->drawable->borderSize());
        
$this->abortUnless(
            
imagepolygon(
                
$canvas,
                
$this->drawable->toArray(),
                
$borderColor,
            ),
            
'Unable to draw polygon border',
        );
    }
}
Онлайн: 2
Реклама