protected function assertResource($resource)
    {
        if (!is_resource($resource) || get_resource_type($resource) !== 'gd') {
            throw new InvalidArgumentException('Invalid resource type.');
        }

        $width = imagesx($resource);
        $height = imagesy($resource);
        if ($width < 1 || $height < 1) {
            throw new InvalidImageDimensionException(
                sprintf('The resource image dimensions should be at least 1x1px. The resource image with %sx%spx dimensions given.', $width, $height)
            );
        }
    }