Example #1
0
 def _process_cache(self):
     """
     Actually does the work.
     """
     log.debug('_processCache')
     image = self._conversion_queue.get()[2]
     # Generate the QImage for the image.
     if image.image is None:
         # Let's see if the image was requested with specific dimensions
         width = self.width if image.width == -1 else image.width
         height = self.height if image.height == -1 else image.height
         image.image = resize_image(image.path, width, height, image.background,
                                    Settings().value('advanced/ignore aspect ratio'))
         # Set the priority to Lowest and stop here as we need to process more important images first.
         if image.priority == Priority.Normal:
             self._conversion_queue.modify_priority(image, Priority.Lowest)
             return
         # For image with high priority we set the priority to Low, as the byte stream might be needed earlier the
         # byte stream of image with Normal priority. We stop here as we need to process more important images first.
         elif image.priority == Priority.High:
             self._conversion_queue.modify_priority(image, Priority.Low)
             return
     # Generate the byte stream for the image.
     if image.image_bytes is None:
         image.image_bytes = image_to_byte(image.image)
Example #2
0
    def test_resize_thumb(self):
        """
        Test the resize_thumb() function
        """
        # GIVEN: A path to an image.
        image_path = os.path.join(TEST_PATH, 'church.jpg')
        wanted_width = 777
        wanted_height = 72
        # We want the background to be white.
        wanted_background_hex = '#FFFFFF'
        wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()

        # WHEN: Resize the image and add a background.
        image = resize_image(image_path, wanted_width, wanted_height, wanted_background_hex)

        # THEN: Check if the size is correct and the background was set.
        result_size = image.size()
        self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.')
        self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
        self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
Example #3
0
    def resize_thumb_test(self):
        """
        Test the resize_thumb() function
        """
        # GIVEN: A path to an image.
        image_path = os.path.join(TEST_PATH, 'church.jpg')
        wanted_width = 777
        wanted_height = 72
        # We want the background to be white.
        wanted_background_hex = '#FFFFFF'
        wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()

        # WHEN: Resize the image and add a background.
        image = resize_image(image_path, wanted_width, wanted_height, wanted_background_hex)

        # THEN: Check if the size is correct and the background was set.
        result_size = image.size()
        self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.')
        self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
        self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
Example #4
0
 def _process_cache(self):
     """
     Actually does the work.
     """
     log.debug('_processCache')
     image = self._conversion_queue.get()[2]
     # Generate the QImage for the image.
     if image.image is None:
         image.image = resize_image(image.path, self.width, self.height, image.background)
         # Set the priority to Lowest and stop here as we need to process more important images first.
         if image.priority == Priority.Normal:
             self._conversion_queue.modify_priority(image, Priority.Lowest)
             return
         # For image with high priority we set the priority to Low, as the byte stream might be needed earlier the
         # byte stream of image with Normal priority. We stop here as we need to process more important images first.
         elif image.priority == Priority.High:
             self._conversion_queue.modify_priority(image, Priority.Low)
             return
     # Generate the byte stream for the image.
     if image.image_bytes is None:
         image.image_bytes = image_to_byte(image.image)
Example #5
0
    def test_resize_thumb_ignoring_aspect_ratio(self):
        """
        Test the resize_thumb() function ignoring aspect ratio
        """
        # GIVEN: A path to an image.
        image_path = str(RESOURCE_PATH / 'church.jpg')
        wanted_width = 1000
        wanted_height = 1000
        # We want the background to be white.
        wanted_background_hex = '#FFFFFF'
        wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()

        # WHEN: Resize the image and add a background.
        image = resize_image(image_path, wanted_width, wanted_height,
                             wanted_background_hex, True)

        # THEN: Check if the size is correct and the background was set.
        result_size = image.size()
        assert wanted_height == result_size.height(
        ), 'The image should have the requested height.'
        assert wanted_width == result_size.width(
        ), 'The image should have the requested width.'
        assert image.pixel(
            0, 0) == wanted_background_rgb, 'The background should be white.'