<commit_before><?php
/**
 * Based on the code of ResizeTransformer by <NAME>
 *
 * @copyright	Copyright 2013, <NAME> - http://www.handmadesite.net
 * @license		http://opensource.org/licenses/mit-license.php - Licensed under the MIT License
 * @link		http://milesj.me/code/php/transit
 */

namespace Transit\Transformer\Image;

use Transit\File;
use \InvalidArgumentException;

/**
 * Resizes an image to new dimensions.
 *
 * @package Transit\Transformer\Image
 */
class FitTransformer extends AbstractImageTransformer {

	/**
	 * Configuration.
	 *
	 * @type array {
	 * 		@type int $quality		Quality of JPEG image
	 * 		@type int $maxWidth		Width of output image
	 * 		@type int $maxHeight		Height of output image
	 * 		@type bool $expand		Allow image to be resized larger than the base dimensions
         *              @type mixed $fill               Fill bounds with given (rgb) color or don't
         *              @type string $verticalAlign
         *              @type string $horizontalAlign
	 * }
	 */
	protected $_config = array(
		'maxWidth' => null,
		'maxHeight' => null,
		'quality' => 100,
		'expand' => false,
                'fill' => false,
                'vericalAlign' => 'center',
                'horizontalAlogn' => 'center'
	);

	/**
	 * {@inheritdoc}
	 *
	 * @throws \InvalidArgumentException
	 */
	public function transform(File $file, $self = false) {
		$config = $this->getConfig();
		$baseWidth = $file->width();
		$baseHeight = $file->height();
		$maxWidth = $config['maxWidth'];
		$maxHeight = $config['maxHeight'];
		$newWidth = null;
		$newHeight = null;

		if (!is_numeric($maxWidth) || !is_numeric($maxHeight)) {
			throw new InvalidArgumentException('Invalid maxWidth or maxHeight for fit');
                }

                $heightAspect = $baseHeight / $maxHeight;
                $widthAspect = $baseWidth / $maxWidth;

                if (!$config['expand'] && ($maxWidth > $baseWidth) && ($maxHeight > $baseHeight)) {
                        $newWidth = $baseWidth;
                        $newHeight = $baseHeight;<commit_msg>Added more checks for arguments<commit_after><?php
/**
 * Based on the code of ResizeTransformer by <NAME>
 *
 * @copyright	Copyright 2013, <NAME> - http://www.handmadesite.net
 * @license		http://opensource.org/licenses/mit-license.php - Licensed under the MIT License
 * @link		http://milesj.me/code/php/transit
 */

namespace Transit\Transformer\Image;

use Transit\File;
use \InvalidArgumentException;

/**
 * Resizes an image to new dimensions.
 *
 * @package Transit\Transformer\Image
 */
class FitTransformer extends AbstractImageTransformer {

	/**
	 * Configuration.
	 *
	 * @type array {
	 * 		@type int $quality		Quality of JPEG image
	 * 		@type int $maxWidth		Width of output image
	 * 		@type int $maxHeight		Height of output image
	 * 		@type bool $expand		Allow image to be resized larger than the base dimensions
         *              @type mixed $fill               Fill bounds with given (rgb) color or don't
         *              @type string $verticalAlign
         *              @type string $horizontalAlign
	 * }
	 */
	protected $_config = array(
		'maxWidth' => null,
		'maxHeight' => null,
		'quality' => 100,
		'expand' => false,
                'fill' => false,
                'vericalAlign' => 'center',
                'horizontalAlign' => 'center'
	);

	/**
	 * {@inheritdoc}
	 *
	 * @throws \InvalidArgumentException
	 */
	public function transform(File $file, $self = false) {
		$config = $this->getConfig();
		$baseWidth = $file->width();
		$baseHeight = $file->height();
		$maxWidth = $config['maxWidth'];
		$maxHeight = $config['maxHeight'];
		$newWidth = null;
		$newHeight = null;

		if (!is_numeric($maxWidth) || !is_numeric($maxHeight)) {
			throw new InvalidArgumentException('Invalid maxWidth or maxHeight for fit');
                }

                if($config['fill']) {

                    if(!in_array($config['verticalAlign'], array('top','center', 'bottom')))
                        throw new InvalidArgumentException('Invalid verticalAlign argument');

                    if(!in_array($config['horizontalAlign'], array('left','center', 'right')))
                        throw new InvalidArgumentException('Invalid horizontalAlign argument');

                    if(count($config['fill'])!= 3)
                        throw new InvalidArgumentException('Invalid color definition in fill');

                    foreach ($config['fill'] as $clr)
                        if(!is_numeric($clr) || ($clr < 0) || ($clr > 255))
                            throw new InvalidArgumentException('Invalid color definition in fill');
                }

                $heightAspect = $baseHeight / $maxHeight;
                $widthAspect = $baseWidth / $maxWidth;

                if (!$config['expand'] && ($maxWidth > $baseWidth) && ($maxHeight > $baseHeight)) {
                        $newWidth = $baseWidth;
                        $newHeight = $baseHeight;
{'fraction_non_alphanumeric': 0.13111467522052928, 'fraction_numerical': 0.003809141940657578, 'mean_word_length': 2.3438337801608577, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1684545', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1346, 'n_words': 369}