private function isInsideImage(ImageInterface $image, $x, $y, $width, $height)
    {
        if ($x < 0 || $y < 0) {
            return false;
        }
        if ($x + $width > $image->getSize()->getWidth()) {
            return false;
        }
        if ($y + $height > $image->getSize()->getHeight()) {
            return false;
        }

        return true;
    }