<commit_before><?php

/**
 * This File is part of the Thapp\JitImage\Filter\Oval package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For full copyright and license information, please refer to the LICENSE file
 * that was distributed with this package.
 */

namespace Thapp\JitImage\Filter\Circle;

use \Imagick;
use \ImagickDraw;
use \ImagickPixel;
use Thapp\JitImage\Filter\ImagickFilter;

/**
 * Class: ImagickCircFilter
 *
 * @uses ImagickFilter
 *
 * @package
 * @version
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class ImagickCircFilter extends ImagickFilter
{

    /**
     * run
     *
     * @access public
     * @return mixed
     */
    public function run()
    {

        extract($this->driver->getTargetSize());

        $image = $this->driver->getResource();

        $mask = new Imagick();
        $mask->newImage($width, $height, 'transparent');

        $mask->thresholdImage(-1);
        $mask->negateImage(1);
        $mask->setImageMatte(1);

        $circle = $this->makeCircle($width, $height);

        $mask->drawImage($circle);
        $mask->gammaImage(2.2);

        $image->setImageFormat('png');
        $image->setImageMatte(1);

        $image->setImageBackgroundColor('white');
        $image->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0);

        $this->driver->swapResource($image);
    }

    /**
     * getCoordinates
     *
     * @param mixed $width
     * @param mixed $height
     * @access protected
     * @return mixed
     */
    protected function getCoordinates($width, $height)
    {
        $max = (int)ceil(max($width, $height) / 2);
        $min = (int)ceil(min($width, $height) / 2);


        return $width > $height ?
            [$max, $min, $max, $this->getOption('o', 1)]:
            [$min, $max, $this->getOption('o', 1), $max];
    }

    /**
     * makeCircle
     *
     * @param mixed $width
     * @param mixed $height
     * @access protected
     * @return mixed
     */
    protected function makeCircle($width, $height)
    {
        list($ox, $oy, $px, $py) = $this->getCoordinates($width, $height);

        $circle = new ImagickDraw();
        $circle->setFillColor('white');
        $circle->circle($ox, $oy, $px, $py);

        return $circle;
    }

}
<commit_msg>no need for swapping resource<commit_after><?php

/**
 * This File is part of the Thapp\JitImage\Filter\Oval package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For full copyright and license information, please refer to the LICENSE file
 * that was distributed with this package.
 */

namespace Thapp\JitImage\Filter\Circle;

use \Imagick;
use \ImagickDraw;
use \ImagickPixel;
use Thapp\JitImage\Filter\ImagickFilter;

/**
 * Class: ImagickCircFilter
 *
 * @uses ImagickFilter
 *
 * @package
 * @version
 * @author Thomas Appel <<EMAIL>>
 * @license MIT
 */
class ImagickCircFilter extends ImagickFilter
{

    /**
     * run
     *
     * @access public
     * @return mixed
     */
    public function run()
    {

        extract($this->driver->getTargetSize());

        $image = $this->driver->getResource();

        $mask = new Imagick();
        $mask->newImage($width, $height, 'transparent');

        $mask->thresholdImage(-1);
        $mask->negateImage(1);
        $mask->setImageMatte(1);

        $circle = $this->makeCircle($width, $height);

        $mask->drawImage($circle);
        $mask->gammaImage(2.2);

        $image->setImageMatte(1);

        $image->setImageBackgroundColor('white');
        $image->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0);
        $image->setImageFormat('png');
    }

    /**
     * getCoordinates
     *
     * @param mixed $width
     * @param mixed $height
     * @access protected
     * @return mixed
     */
    protected function getCoordinates($width, $height)
    {
        $max = (int)ceil(max($width, $height) / 2);
        $min = (int)ceil(min($width, $height) / 2);


        return $width > $height ?
            [$max, $min, $max, $this->getOption('o', 1)]:
            [$min, $max, $this->getOption('o', 1), $max];
    }

    /**
     * makeCircle
     *
     * @param mixed $width
     * @param mixed $height
     * @access protected
     * @return mixed
     */
    protected function makeCircle($width, $height)
    {
        list($ox, $oy, $px, $py) = $this->getCoordinates($width, $height);

        $circle = new ImagickDraw();
        $circle->setFillColor('white');
        $circle->circle($ox, $oy, $px, $py);

        return $circle;
    }

}

{'fraction_non_alphanumeric': 0.162410394265233, 'fraction_numerical': 0.005376344086021506, 'mean_word_length': 2.445216049382716, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 58, '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': '6956610', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1439, 'n_words': 314}