<commit_before><?php
/**
 * This file is part of the Kappa package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

namespace Kappa\ThumbnailsHelper;

use Kappa\FileSystem\Directory;
use Kappa\FileSystem\File;
use Kappa\NetteFileSystem\Image;
use Nette\Object;

/**
 * Class ThumbnailsHelper
 * @package Kappa\ThumbnailsHelper
 */
class ThumbnailsHelper extends Object
{
	/** @var array */
	private $params;

	/**
	 * @param string $wwwDir
	 * @param string $thumbDir
	 * @param null|int $frequencyControl
	 * @throws DirectoryNotFoundException
	 */
	public function __construct($wwwDir, $thumbDir, $frequencyControl = null)
	{
		if (!is_dir($wwwDir)) {
			throw new DirectoryNotFoundException("Directory {$wwwDir} has not been found");
		}
		if (!is_dir($thumbDir)) {
			throw new DirectoryNotFoundException("Directory {$thumbDir} has not been found");
		}
		$this->params = array(
			'wwwDir' => realpath($wwwDir),
			'thumbDir' => realpath($thumbDir),
		);
		if ($frequencyControl) {
			$this->checkThumbs((int)$frequencyControl);
		}
	}

	/**
	 * @param string $original
	 * @param array $sizes
	 * @param string $flag
	 * @return string
	 */
	public function process($original, array $sizes = array(300, 100), $flag = "fit")
	{
		$original = new File($this->params['wwwDir'] . DIRECTORY_SEPARATOR . $original);
		$thumb = $this->createThumbName($original, $sizes);
		$imageInfo = @getimagesize($original->getInfo()->getPathname());
		if (file_exists($thumb) || ($imageInfo[0] <= $sizes[0] && $imageInfo[1] <= $sizes[1])) {
			$file = new File($thumb);

			return $file->getInfo()->getRelativePath($this->params['wwwDir']);
		} else {
			$image = Image::fromFile($original->getInfo()->getPathname());<commit_msg>Fixed resize small images<commit_after><?php
/**
 * This file is part of the Kappa package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

namespace Kappa\ThumbnailsHelper;

use Kappa\FileSystem\Directory;
use Kappa\FileSystem\File;
use Kappa\NetteFileSystem\Image;
use Nette\Object;

/**
 * Class ThumbnailsHelper
 * @package Kappa\ThumbnailsHelper
 */
class ThumbnailsHelper extends Object
{
	/** @var array */
	private $params;

	/**
	 * @param string $wwwDir
	 * @param string $thumbDir
	 * @param null|int $frequencyControl
	 * @throws DirectoryNotFoundException
	 */
	public function __construct($wwwDir, $thumbDir, $frequencyControl = null)
	{
		if (!is_dir($wwwDir)) {
			throw new DirectoryNotFoundException("Directory {$wwwDir} has not been found");
		}
		if (!is_dir($thumbDir)) {
			throw new DirectoryNotFoundException("Directory {$thumbDir} has not been found");
		}
		$this->params = array(
			'wwwDir' => realpath($wwwDir),
			'thumbDir' => realpath($thumbDir),
		);
		if ($frequencyControl) {
			$this->checkThumbs((int)$frequencyControl);
		}
	}

	/**
	 * @param string $original
	 * @param array $sizes
	 * @param string $flag
	 * @return string
	 */
	public function process($original, array $sizes = array(300, 100), $flag = "fit")
	{
		$original = new File($this->params['wwwDir'] . DIRECTORY_SEPARATOR . $original);
		$thumb = $this->createThumbName($original, $sizes);
		$imageInfo = @getimagesize($original->getInfo()->getPathname());
		if (file_exists($thumb)) {
			$file = new File($thumb);
			return $file->getInfo()->getRelativePath($this->params['wwwDir']);
		}
		if($imageInfo[0] <= $sizes[0] && $imageInfo[1] <= $sizes[1]) {
			return $original->getInfo()->getRelativePath($this->params['wwwDir']);
		} else {
			$image = Image::fromFile($original->getInfo()->getPathname());
{'fraction_non_alphanumeric': 0.16205428419372006, 'fraction_numerical': 0.005321979776476849, 'mean_word_length': 4.577151335311573, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 17, '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': '1683673', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1193, 'n_words': 290}