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

declare(strict_types=1);

namespace 
InterventionImageDriversGdModifiers;

use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersOrientModifier as GenericOrientModifier;

class 
OrientModifier extends GenericOrientModifier implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see ModifierInterface::apply()
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        
$image match ($this->orientation($image)) {
            
=> $image->flip(),
            
=> $image->rotate(180),
            
=> $image->rotate(180)->flip(),
            
=> $image->rotate(90)->flip(),
            
=> $image->rotate(90),
            
=> $image->rotate(270)->flip(),
            
=> $image->rotate(270),
            default => 
$image
        
};

        return 
$this->markAligned($image);
    }

    
/**
     * Return exif information about image orientation.
     */
    
private function orientation(ImageInterface $image): int
    
{
        
$orientation $image->exif('IFD0.Orientation');

        return 
is_numeric($orientation) ? (int) $orientation 0;
    }

    
/**
     * Set exif data of image to top-left orientation, marking the image as
     * aligned and making sure the rotation correction process is not
     * performed again.
     */
    
private function markAligned(ImageInterface $image): ImageInterface
    
{
        
$exif $image->exif()->map(function ($item) {
            if (
is_array($item) && array_key_exists('Orientation'$item)) {
                
$item['Orientation'] = 1;
                return 
$item;
            }

            return 
$item;
        });

        return 
$image->setExif($exif);
    }
}
Онлайн: 1
Реклама