Beispiel #1
0
    def adjust_focal_points(self):
        source_width, source_height = self.engine.size

        self.focal_points = None

        if self.context.request.focal_points:
            if self.context.request.should_crop:
                self.focal_points = []
                crop = self.context.request.crop
                for point in self.context.request.focal_points:
                    if point.x < crop['left'] or point.x > crop['right'] or point.y < crop['top'] or point.y > crop['bottom']:
                        continue
                    point.x -= crop['left'] or 0
                    point.y -= crop['top'] or 0
                    self.focal_points.append(point)
            else:
                self.focal_points = self.context.request.focal_points

        if not self.focal_points:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
Beispiel #2
0
    def adjust_focal_points(self):
        source_width, source_height = self.engine.size

        self.focal_points = None

        if self.context.request.focal_points:
            if self.context.request.should_crop:
                self.focal_points = []
                crop = self.context.request.crop
                for point in self.context.request.focal_points:
                    if point.x < crop['left'] or point.x > crop[
                            'right'] or point.y < crop[
                                'top'] or point.y > crop['bottom']:
                        continue
                    point.x -= crop['left'] or 0
                    point.y -= crop['top'] or 0
                    self.focal_points.append(point)
            else:
                self.focal_points = self.context.request.focal_points

        if not self.focal_points:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width, source_height)
            ]

        self.engine.focus(self.focal_points)
Beispiel #3
0
 def calculate_focal_points(self):
     if self.context['focal_points']:
         self.focal_points = self.context['focal_points']
     else:
         self.focal_points = [
             FocalPoint.from_alignment(self.context['halign'],
                                       self.context['valign'],
                                       self.source_width,
                                       self.source_height)
         ]
Beispiel #4
0
    def calculate_focal_points(self):
        source_width, source_height = self.engine.size

        if self.context['focal_points']:
            self.focal_points = self.context['focal_points']
        else:
            self.focal_points = [
                FocalPoint.from_alignment(self.context['halign'],
                                          self.context['valign'], source_width,
                                          source_height)
            ]
Beispiel #5
0
def assert_point_from_alignment(point):
    comp_point = FocalPoint.from_alignment(point[0],
                                           point[1],
                                           width=point[2],
                                           height=point[3])

    assert comp_point.x == point[4], "Expected x => %.2f Got x => %.2f" % (
        point[4], comp_point.x)
    assert comp_point.y == point[5], "Expected y => %.2f Got y => %.2f" % (
        point[5], comp_point.y)
    assert comp_point.weight == 1.0
Beispiel #6
0
    def calculate_focal_points(self):
        source_width, source_height = self.engine.size

        if self.context.request.focal_points:
            self.focal_points = self.context.request.focal_points
        else:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width, source_height)
            ]

        self.engine.focus(self.focal_points)
Beispiel #7
0
    def calculate_focal_points(self):
        source_width, source_height = self.engine.size

        if self.context['focal_points']:
            self.focal_points = self.context['focal_points']
        else:
            self.focal_points = [
                FocalPoint.from_alignment(self.context['halign'],
                                          self.context['valign'],
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
Beispiel #8
0
    def calculate_focal_points(self):
        source_width, source_height = self.engine.size

        if self.context.request.focal_points:
            self.focal_points = self.context.request.focal_points
        else:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
 def process(self, canvas_width, canvas_height, size):
     try:
         self.engine.load(self.buffer, self.extension)
         width, height = self.engine.size
         new_width, new_height = calc_new_size_by_height(width, height, canvas_height)
         focal_points = StandaloneFaceDetector.features_to_focal_points(
             StandaloneFaceDetector.get_features(self.thumbor_filter.context, self.engine))
         if focal_points:
             self.resize_focal_points(focal_points, float(new_width) / width)
         else:
             focal_points.append(FocalPoint.from_alignment('center', 'top', new_width, new_height))
         self.engine.resize(new_width, new_height)
         self.engine.focus(focal_points)
         StandaloneFaceDetector.auto_crop(self.engine, focal_points, size, canvas_height)
     except Exception as err:
         logger.exception(err)
Beispiel #10
0
 def process(self, canvas_width, canvas_height, size):
     try:
         self.engine.load(self.buffer, None)
         width, height = self.engine.size
         new_width, new_height = calc_new_size_by_height(
             width, height, canvas_height)
         focal_points = StandaloneFaceDetector.features_to_focal_points(
             StandaloneFaceDetector.get_features(
                 self.thumbor_filter.context, self.engine))
         if focal_points:
             self.resize_focal_points(focal_points,
                                      float(new_width) / width)
         else:
             focal_points.append(
                 FocalPoint.from_alignment('center', 'top', new_width,
                                           new_height))
         self.engine.resize(new_width, new_height)
         self.engine.focus(focal_points)
         StandaloneFaceDetector.auto_crop(self.engine, focal_points, size,
                                          canvas_height)
     except Exception as err:
         logger.exception(err)
Beispiel #11
0
    def adjust_focal_points(self):
        source_width, source_height = self.engine.size

        self.focal_points = []

        if self.context.request.focal_points:
            crop = self.context.request.crop
            for point in self.context.request.focal_points:
                point.x -= crop['left'] or 0
                point.y -= crop['top'] or 0
                if point.x < 0 or point.x > self.target_width or \
                        point.y < 0 or point.y > self.target_height:
                    continue
                self.focal_points.append(point)

        if not self.focal_points:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
Beispiel #12
0
 def test_aligned_point_top_left(self):
     point = FocalPoint.from_alignment('left', 'top', 300, 200)
     expect(point.x).to_equal(0)
     expect(point.y).to_equal(0)
     expect(point.weight).to_equal(1.0)
Beispiel #13
0
 def test_aligned_point_center_middle(self):
     point = FocalPoint.from_alignment('center', 'middle', 300, 200)
     expect(point.x).to_equal(150)
     expect(point.y).to_equal(100)
     expect(point.weight).to_equal(1.0)
Beispiel #14
0
 def test_aligned_point_bottom_right(self):
     point = FocalPoint.from_alignment('right', 'bottom', 300, 200)
     expect(point.x).to_equal(300)
     expect(point.y).to_equal(200)
     expect(point.weight).to_equal(1.0)
Beispiel #15
0
 def test_aligned_point_top_left(self):
     point = FocalPoint.from_alignment('left', 'top', 300, 200)
     expect(point.x).to_equal(0)
     expect(point.y).to_equal(0)
     expect(point.weight).to_equal(1.0)
Beispiel #16
0
 def topic(self):
     return FocalPoint.from_alignment('left', 'top', 300, 200)
Beispiel #17
0
 def topic(self):
     return FocalPoint.from_alignment('left', 'top', 300, 200)
Beispiel #18
0
 def topic(self):
     return FocalPoint.from_alignment('center', 'middle', 300, 200)
def assert_point_from_alignment(point):
    comp_point = FocalPoint.from_alignment(point[0], point[1], width=point[2], height=point[3])

    assert comp_point.x == point[4], "Expected x => %.2f Got x => %.2f" % (point[4], comp_point.x)
    assert comp_point.y == point[5], "Expected y => %.2f Got y => %.2f" % (point[5], comp_point.y)
    assert comp_point.weight == 1.0
Beispiel #20
0
 def topic(self):
     return FocalPoint.from_alignment('right', 'bottom', 300, 200)
Beispiel #21
0
 def test_aligned_point_bottom_right(self):
     point = FocalPoint.from_alignment('right', 'bottom', 300, 200)
     expect(point.x).to_equal(300)
     expect(point.y).to_equal(200)
     expect(point.weight).to_equal(1.0)
Beispiel #22
0
 def test_aligned_point_center_middle(self):
     point = FocalPoint.from_alignment('center', 'middle', 300, 200)
     expect(point.x).to_equal(150)
     expect(point.y).to_equal(100)
     expect(point.weight).to_equal(1.0)
Beispiel #23
0
 def topic(self):
     return FocalPoint.from_alignment('right', 'bottom', 300, 200)
Beispiel #24
0
 def topic(self):
     return FocalPoint.from_alignment('center', 'middle', 300, 200)