php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

Why does Point class reject negative values...? #839

Open jcogs-design opened 1 year ago

jcogs-design commented 1 year ago

Issue description

The Imagine Point class constrains point values to be positive (vis

   /**
     * Constructs a point of coordinates.
     *
     * @param int $x
     * @param int $y
     *
     * @throws \Imagine\Exception\InvalidArgumentException
     */
    public function __construct($x, $y)
    {
        if ($x < 0 || $y < 0) {
            throw new InvalidArgumentException(sprintf('A coordinate cannot be positioned outside of a bounding box (x: %s, y: %s given)', $x, $y));
        }

        $this->x = $x;
        $this->y = $y;
    }

Why is this? Is there a work-around for positioning drawn or pasted image objects so that they are partially placed outside of an image area?

If you disable the constraint, it appears that Imagine continues to work OK with negative values.

What version of Imagine are you using?

1.3.2

What's the PHP version you are using?

8.0.25

What's the imaging library you are using [gd/imagick/gmagick/any]?

GD2

What's the imaging library configuration

GD Version: "2.3.3" FreeType Support: true FreeType Linkage: "with freetype" GIF Read Support: true GIF Create Support: true JPEG Support: true PNG Support: true WBMP Support: true XPM Support: true XBM Support: true WebP Support: true BMP Support: true TGA Read Support: true JIS-mapped Japanese Font Support: false

Minimal PHP code to reproduce the error:

n/a

josequinta-pixelarus commented 1 year ago

Same question here. I want to crop an image below and above, same pixels in both sides. For this, I calc $positionY = ($finalHeigh - $originalImageHeight) / 2) and the result value is always negative. So, Imagine Point class returns an Exception. There are a reason to not allowing negative values in Point class? Thanks!

josequinta-pixelarus commented 1 year ago

There is another class, equivalent to Point class, that allows negative values. Imagine\Image\PointSigned It works. Anyway, I would like to understand why Point doesn't allow negative values.

ausi commented 1 year ago

The PointSigned class was added in #663

Anyway, I would like to understand why Point doesn't allow negative values.

I think because in many usages of this class, negative values are not allowed.