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

declare(strict_types=1);

namespace 
InterventionImageDriversGdModifiers;

use 
InterventionImageInterfacesImageInterface;
use 
InterventionImageInterfacesSpecializedInterface;
use 
InterventionImageModifiersAlignRotationModifier as GenericAlignRotationModifier;

class 
AlignRotationModifier extends GenericAlignRotationModifier implements SpecializedInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see ModifierInterface::apply()
     */
    
public function apply(ImageInterface $image): ImageInterface
    
{
        
$image match ($image->exif('IFD0.Orientation')) {
            
=> $image->flop(),
            
=> $image->rotate(180),
            
=> $image->rotate(180)->flop(),
            
=> $image->rotate(270)->flop(),
            
=> $image->rotate(270),
            
=> $image->rotate(90)->flop(),
            
=> $image->rotate(90),
            default => 
$image
        
};

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

    
/**
     * 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.
     *
     * @param ImageInterface $image
     * @return ImageInterface
     */
    
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);
    }
}
Онлайн: 2
Реклама