<commit_before><?php

// +----------------------------------------------------------------------+
// | Akelos PHP Framework - http://www.akelos.org                         |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2007, Akelos Media, S.L.  & <NAME> |
// |               2008-2009, <NAME>                       |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package ActiveSupport
 * @subpackage ImageManipulation
 * @author <NAME>
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

/**
 * CenteredCrop filter
 *
 * Options are:
 * 'width'
 * 'height'
 *
 * Example:
 *
 *     $Image = new AkImage('/photo.jpg'); *
 *     $Image->transform('centered_crop',array('size'=>'105x105'));
 *     $Image->save('/cropped.jpg');
 */
class AkImageCenteredCropFilter extends AkImageFilter
{
    function setOptions($options = array())
    {
        $default_options = array(
        'width'=> $this->Image->getWidth(),
        'height'=> $this->Image->getHeight()
        );

        $this->options = array_merge($default_options, $options);
        $this->_setWidthAndHeight_($this->options);
        $this->_variablizeOptions_($this->options);
    }

    function apply()
    {
        //width bigger
        if($this->Image->getWidth() > $this->Image->getHeight()){
            $ratio  = $this->Image->getHeight()/$this->options['height'];
            $width  = $this->Image->getWidth()/$ratio;
            $height = $this->options['height'];
            $x      = ($width-$this->options['width'])/2;
            $y      = 0;
        // height bigger
        }else{
            $ratio  = $this->Image->getWidth()/$this->options['width'];
            $height = $this->Image->getHeight()/$ratio;
            $width  = $this->options['width'];
            $x      = 0;
            $y      = ($height-$this->options['height'])/2;
        }
        $this->Image->Transform->resize($width, $height);
        $this->Image->Transform->crop($this->options['width'], $this->options['height'], $x, $y);
    }

    function getName()
    {
        return 'centered_crop';
    }

}

?><commit_msg>Do not resize when the image is smaller<commit_after><?php

// +----------------------------------------------------------------------+
// | Akelos PHP Framework - http://www.akelos.org                         |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2007, Akelos Media, S.L.  & <NAME> |
// |               2008-2009, <NAME>                       |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package ActiveSupport
 * @subpackage ImageManipulation
 * @author <NAME>
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

/**
 * CenteredCrop filter
 *
 * Options are:
 * 'width'
 * 'height'
 *
 * Example:
 *
 *     $Image = new AkImage('/photo.jpg'); *
 *     $Image->transform('centered_crop',array('size'=>'105x105'));
 *     $Image->save('/cropped.jpg');
 */
class AkImageCenteredCropFilter extends AkImageFilter
{
    function setOptions($options = array())
    {
        $default_options = array(
        'width'=> $this->Image->getWidth(),
        'height'=> $this->Image->getHeight()
        );

        $this->options = array_merge($default_options, $options);
        $this->_setWidthAndHeight_($this->options);
        $this->_variablizeOptions_($this->options);
    }

    function apply()
    {
        $height_ratio  = $this->Image->getHeight()/$this->options['height'];
        $width_ratio  = $this->Image->getWidth()/$this->options['width'];
        
        //width bigger
        if($this->Image->getWidth() > $this->Image->getHeight()){
            if($width_ratio>1){
                $width  = $this->Image->getWidth()/$height_ratio;
                $height = $this->options['height'];
                $x      = ($width-$this->options['width'])/2;
                $y      = 0;
                
                $this->_resizeAndCrop($width, $height, $x, $y);
            }
        // height bigger
        }else{
            if($height_ratio>1){
                $height = $this->Image->getHeight()/$width_ratio;
                $width  = $this->options['width'];
                $x      = 0;
                $y      = ($height-$this->options['height'])/2;
                
                $this->_resizeAndCrop($width, $height, $x, $y);
            }
        }
    }

    function getName()
    {
        return 'centered_crop';
    }
    
    private function _resizeAndCrop($width, $height, $x, $y)
    {
        $this->Image->Transform->resize($width, $height);
        $this->Image->Transform->crop($this->options['width'], $this->options['height'], $x, $y);
    }
}

?>
{'fraction_non_alphanumeric': 0.25414917016596683, 'fraction_numerical': 0.010797840431913617, 'mean_word_length': 1.5957446808510638, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '252437', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1389, 'n_words': 235}