Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jcogs-design opened this issue Dec 10, 2022 · 3 comments
Open

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

jcogs-design opened this issue Dec 10, 2022 · 3 comments

Comments

@jcogs-design
Copy link

jcogs-design commented Dec 10, 2022

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
Copy link

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
Copy link

josequinta-pixelarus commented Feb 14, 2023

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
Copy link
Collaborator

ausi commented Feb 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants