def _crop_if_smaller( self, full_area, last_successful_location, last_successful_part_size, stitched_image, ): # type: (Region, Point, RectangleSize, Image) -> Image act_image_width = last_successful_location.x + last_successful_part_size.width act_image_height = last_successful_location.y + last_successful_part_size.height logger.info("Extracted entire size: {}".format(full_area.size)) logger.info( "Actual stitched size: {} x {}".format(act_image_width, act_image_height) ) self.debug_screenshot_provider.save( stitched_image, self._debug_msg("_stitched_before_trim") ) if ( act_image_width < stitched_image.width or act_image_height < stitched_image.height ): logger.info("Trimming unnecessary margins...") stitched_image = image_utils.get_image_part( stitched_image, Region( 0, 0, min([act_image_width, stitched_image.width]), min([act_image_height, stitched_image.height]), ), ) logger.info("Done") return stitched_image
def sub_screenshot(self, region, throw_if_clipped=False): # type: (Region, bool) -> EyesImagesScreenshot argument_guard.not_none(region) # We want to get the sub-screenshot in as-is coordinates type. sub_screenshot_region = self.intersected_region( region, self.SCREENSHOT_AS_IS) if sub_screenshot_region.is_size_empty and ( throw_if_clipped or not sub_screenshot_region.size == region.size): raise OutOfBoundsError( "Region [{}] is out of screenshot bounds [{}]".format( region, self._bounds)) sub_screenshot_image = image_utils.get_image_part( self._image, sub_screenshot_region) # Notice that we need the bounds-relative coordinates as parameter # for new sub-screenshot. relative_sub_screenshot_region = self.convert_region_location( sub_screenshot_region, self.SCREENSHOT_AS_IS, self.CONTEXT_RELATIVE) return EyesImagesScreenshot(sub_screenshot_image, relative_sub_screenshot_region.location)
def _crop_if_needed(self, image, region_in_screenshot): # type: (Image, Region) -> Image if not region_in_screenshot.is_size_empty: image = image_utils.get_image_part(image, region_in_screenshot) self.debug_screenshot_provider.save(image, self._debug_msg("cropper")) return image
def sub_screenshot(self, region, throw_if_clipped=False): # type: (Region, bool) -> EyesWebDriverScreenshot # We calculate intersection based on as-is coordinates. as_is_sub_screenshot_region = self.intersected_region( region, self.SCREENSHOT_AS_IS) if (as_is_sub_screenshot_region.is_size_empty or throw_if_clipped and as_is_sub_screenshot_region.size != region.size): raise OutOfBoundsError( "Region [%s] is out of screenshot bounds [%s]" % (region, self.frame_window)) sub_image = image_utils.get_image_part(self.image, as_is_sub_screenshot_region) return EyesWebDriverScreenshot.from_screenshot( self._driver, sub_image, Region(region.left, region.top, sub_image.width, sub_image.height), self._frame_location_in_screenshot, )
def _crop_if_needed(self, image, region_in_screenshot): # type: (Image, Region) -> Image if not region_in_screenshot.is_size_empty: image = image_utils.get_image_part(image, region_in_screenshot) return image