GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UpscaleFilter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 41
loc 41
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 8 8 4
B apply() 26 26 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""
2
This module implement a upscale filter.
3
"""
4
from .interface import ImagineFilterInterface
5
from PIL import Image
6
7
8 View Code Duplication
class UpscaleFilter(ImagineFilterInterface):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    """
10
    Upscale filter
11
    """
12
    size = None
13
14
    def __init__(self, **kwargs):
15
        """
16
        :param kwargs: dict
17
        """
18
        if 'min' in kwargs and isinstance(kwargs['min'], list) and len(kwargs['min']) == 2:
19
            self.size = kwargs.get('min')
20
        else:
21
            raise ValueError('Unsupported configuration')
22
23
    def apply(self, resource):
24
        """
25
        Apply filter to resource.
26
        :param resource: Image
27
        :return: Image
28
        """
29
        if not isinstance(resource, Image.Image):
30
            raise ValueError('Unsupported resource format: %s' % str(type(resource)))
31
32
        original_width, original_height = resource.size
33
34
        if original_width < self.size[0] and original_height < self.size[1]:
35
            k = original_width / float(original_height)
36
37
            if original_width >= original_height:
38
                target_width = self.size[0]
39
                target_height = int(target_width / k)
40
            else:
41
                target_height = self.size[1]
42
                target_width = int(target_height * k)
43
44
            resource_format = resource.format
45
            resource = resource.resize((target_width, target_height), Image.ANTIALIAS)
46
            resource.format = resource_format
47
48
        return resource
49