<commit_before><?php
namespace Furniture\CommonBundle\Imagine\Filter\Loader;

use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
use Imagine\Exception\InvalidArgumentException;
use Imagine\Image\ImageInterface;
use Liip\ImagineBundle\Imagine\Filter\RelativeResize;

class AutoRelativeResizeLoader implements LoaderInterface
{
    
    /**
     * {@inheritDoc}
     */
    public function load(ImageInterface $image, array $options = array())
    {
        if( !count($options) )
            throw new InvalidArgumentException('Expected method/parameter pair, none given');
        
        //If need heighten resize
        if( $image->getSize()->getHeight() > $image->getSize()->getWidth() && isset($options['heighten']) ){
            return (new RelativeResize( 'heighten', $options['heighten']))->apply($image);
        //If need widen resize
        }elseif( isset($options['widen']) ){
            return (new RelativeResize( 'widen', $options['widen']))->apply($image);
        }
        
        throw new InvalidArgumentException('Unsupported options');
    }
    
}

<commit_msg>Image resize filter<commit_after><?php
namespace Furniture\CommonBundle\Imagine\Filter\Loader;

use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
use Imagine\Exception\InvalidArgumentException;
use Imagine\Image\ImageInterface;
use Liip\ImagineBundle\Imagine\Filter\RelativeResize;

class AutoRelativeResizeLoader implements LoaderInterface
{
    
    /**
     * {@inheritDoc}
     */
    public function load(ImageInterface $image, array $options = array())
    {
        if( !count($options) )
            throw new InvalidArgumentException('Expected method/parameter pair, none given');
        
        if($image->getSize()->getHeight() == $image->getSize()->getWidth()){
            
            if(isset($options['widen']) && $options['heighten']){
                if((int)$options['widen'] > (int)$options['heighten']){
                    return (new RelativeResize( 'heighten', $options['heighten']))->apply($image);
                }else{
                    return (new RelativeResize( 'widen', $options['widen']))->apply($image);
                }
            }elseif(isset($options['widen'])){
                return (new RelativeResize( 'widen', $options['widen']))->apply($image);
            }else{
                return (new RelativeResize( 'heighten', $options['heighten']))->apply($image);
            }
            
            
        }elseif( $image->getSize()->getHeight() > $image->getSize()->getWidth() && isset($options['heighten']) ){
            
            $image = (new RelativeResize( 'heighten', $options['heighten']))->apply($image);
        
            if( isset($options['widen']) && $image->getSize()->getWidth() > $options['widen'] ){
                $image = (new RelativeResize( 'widen', $options['widen']))->apply($image);
            }
            
            return $image;
        }elseif( isset($options['widen']) ){
            
            $image = (new RelativeResize( 'widen', $options['widen']))->apply($image);
            
            if( isset($options['heighten']) && $image->getSize()->getHeight() > $options['heighten'] ){
                $image = (new RelativeResize( 'heighten', $options['heighten']))->apply($image);
            }
            
            return $image;
            
        }elseif( isset($options['heighten']) ){
            return (new RelativeResize( 'heighten', $options['heighten']))->apply($image);
        }
        
        throw new InvalidArgumentException('Unsupported options');
    }
    
}


{'fraction_non_alphanumeric': 0.15981100611450805, 'fraction_numerical': 0.0, 'mean_word_length': 2.6062124248496996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772494', 'n_tokens_mistral': 963, 'n_tokens_neox': 951, 'n_words': 172}