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

declare(strict_types=1);

namespace 
InterventionImageDriversGdModifiers;

use 
GdImage;
use 
InterventionImageExceptionsColorDecoderException;
use 
InterventionImageExceptionsModifierException;
use 
InterventionImageExceptionsStateException;
use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersDrawEllipseModifier as GenericDrawEllipseModifier;

class 
DrawEllipseModifier extends GenericDrawEllipseModifier implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see ModifierInterface::apply()
     *
     * @throws ModifierException
     * @throws StateException
     * @throws ColorDecoderException
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        
$backgroundColor $this->driver()->colorProcessor($image)->export($this->backgroundColor());
        
$borderColor $this->driver()->colorProcessor($image)->export($this->borderColor());

        foreach (
$image as $frame) {
            
$this->drawEllipse($frame->native(), $backgroundColor$borderColor);
        }

        return 
$image;
    }

    
/**
     * Draw ellipse in given colors.
     *
     * @throws ModifierException
     */
    
private function drawEllipse(GdImage $canvasint $backgroundColorint $borderColor): void
    
{
        
imagealphablending($canvastrue);

        
// draw background
        
if ($this->drawable->hasBackgroundColor()) {
            
imagesetthickness($canvas0);
            
imagefilledellipse(
                
$canvas,
                
$this->drawable->position()->x(),
                
$this->drawable->position()->y(),
                
// slightly smaller ellipse to keep 1px bordered edges clean
                
$this->drawable->hasBorder() ? $this->drawable->width() - $this->drawable->width(),
                
$this->drawable->hasBorder() ? $this->drawable->height() - $this->drawable->height(),
                
$backgroundColor,
            );
        }

        
// draw border
        
if ($this->drawable()->hasBorder()) {
            
// gd's imageellipse ignores imagesetthickness
            // so i use imagearc with 360 degrees instead.
            
imagesetthickness($canvas$this->drawable->borderSize());
            
imagearc(
                
$canvas,
                
$this->drawable->position()->x(),
                
$this->drawable->position()->y(),
                
$this->drawable->width(),
                
$this->drawable->height(),
                
0,
                
360,
                
$borderColor,
            );
        }
    }
}
Онлайн: 1
Реклама