Exemplo n.º 1
0
def crop_image(image, region_to_crop):
    # type: (Image.Image, Region) -> Image.Image
    argument_guard.is_a(image, Image.Image)
    argument_guard.is_a(region_to_crop, Region)

    image_region = Region.from_(image)
    image_region = image_region.intersect(region_to_crop)
    if image_region.is_size_empty:
        logger.warning(
            "requested cropped area results in zero-size image! "
            "Cropped not performed. Returning original image."
        )
        return image

    if image_region != region_to_crop:
        logger.warning("requested cropped area overflows image boundaries.")

    cropped_image = image.crop(
        box=(
            image_region.left,
            image_region.top,
            image_region.right,
            image_region.bottom,
        )
    )
    return cropped_image
Exemplo n.º 2
0
 def _floating_provider_from(self, region, bounds):
     if isinstance(region, Region):
         logger.debug("floating: FloatingRegionByRectangle")
         return FloatingRegionByRectangle(Region.from_(region), bounds)
     raise TypeError(
         "Unsupported floating region: \n\ttype: {} \n\tvalue: {}".format(
             type(region), region))
Exemplo n.º 3
0
 def __init__(self, image, location=None):
     super(EyesImagesScreenshot, self).__init__(image)
     if location is None:
         location = Point.ZERO()
     argument_guard.is_a(location, Point)
     self._location = location
     self._bounds = Region.from_(location, self.image)
Exemplo n.º 4
0
 def __init__(self, image, location=None):
     super(EyesImagesScreenshot, self).__init__(image)
     if location is None:
         location = Point.zero()
     argument_guard.is_a(location, Point)
     self._location = location
     self._bounds = Region.from_(
         location, dict(width=self._image.width, height=self._image.height)
     )
Exemplo n.º 5
0
def _region_from_element(element, screenshot):
    # type: (AnyWebElement, EyesWebDriverScreenshot) -> Region
    location = element.location
    if screenshot:
        # Element's coordinates are context relative, so we need to convert them first.
        adjusted_location = screenshot.location_in_screenshot(
            Point.from_(location), CoordinatesType.CONTEXT_RELATIVE)
    else:
        adjusted_location = Point.from_(location)
    region = Region.from_(adjusted_location, element.size)
    return region
Exemplo n.º 6
0
    def intersected_region(self, region, coordinates_type):
        # type: (Region, CoordinatesType) -> Region
        argument_guard.not_none(region)
        argument_guard.not_none(coordinates_type)

        if region.is_size_empty:
            return Region.from_(region)

        intersected_region = self.convert_region_location(
            region, region.coordinates_type, self.CONTEXT_RELATIVE)
        intersected_region.intersect(self._bounds)

        if region.is_size_empty:
            return region

        intersected_region.location = self.convert_location(
            intersected_region.location, self.CONTEXT_RELATIVE,
            coordinates_type)
        return intersected_region
Exemplo n.º 7
0
 def get_regions(self, eyes, screenshot):
     # type: (EyesBase, EyesScreenshot) -> List[Region]
     return [Region.from_(self._region)]