当前位置: 首页>>代码示例>>Python>>正文


Python FocalPoint.from_dict方法代码示例

本文整理汇总了Python中thumbor.point.FocalPoint.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python FocalPoint.from_dict方法的具体用法?Python FocalPoint.from_dict怎么用?Python FocalPoint.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thumbor.point.FocalPoint的用法示例。


在下文中一共展示了FocalPoint.from_dict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: smart_detect

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
    def smart_detect(self):
        if self.context['detectors'] and self.context['smart']:
            storage = self.context['storage']
            engine = self.context['engine']
            storage_key = '%s_%d_%d' % (self.context['image_url'], engine.size[0], engine.size[1])
            if self.context['crop_left']:
                storage_key = storage_key + '_%d_%d_%d_%d' % (self.context['crop_left'],
                                                              self.context['crop_top'],
                                                              self.context['crop_right'],
                                                              self.context['crop_bottom']
                                                             )
            focal_points = storage.get_detector_data(storage_key)
            if focal_points:
                for point in focal_points:
                    self.context['focal_points'].append(FocalPoint.from_dict(point))
            else:
                detectors = self.context['detectors']
                detectors[0](index=0, detectors=detectors).detect(self.context)

                points = []
                focal_points = self.context['focal_points']

                for point in focal_points:
                    points.append(point.to_dict())

                storage.put_detector_data(storage_key, points)
开发者ID:cezarsa,项目名称:thumbor,代码行数:28,代码来源:transformer.py

示例2: after_smart_detect

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
    def after_smart_detect(self, focal_points=[], points_from_storage=False):
        self.manual_crop()
        self.calculate_target_dimensions()

        for point in focal_points:
            self.context.request.focal_points.append(FocalPoint.from_dict(point))

        if self.context.request.focal_points and self.context.modules.storage and not points_from_storage:
            storage = self.context.modules.storage
            points = []
            for point in self.context.request.focal_points:
                points.append(point.to_dict())

            storage.put_detector_data(self.smart_storage_key, points)

        self.adjust_focal_points()

        if self.context.request.debug:
            self.debug()
        else:
            if self.context.request.fit_in:
                self.fit_in_resize()
            else:
                self.auto_crop()
                self.resize()
            self.flip()

        self.done_callback()
开发者ID:MechanisM,项目名称:thumbor,代码行数:30,代码来源:transformer.py

示例3: after_smart_detect

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
    def after_smart_detect(self, focal_points=[], points_from_storage=False):
        for point in focal_points:
            self.context.request.focal_points.append(FocalPoint.from_dict(point))

        if self.context.request.focal_points and self.context.modules.storage and not points_from_storage:
            storage = self.context.modules.storage
            points = []
            for point in self.context.request.focal_points:
                points.append(point.to_dict())

            storage.put_detector_data(self.smart_storage_key, points)

        if self.running_smart_detection:
            self.should_run_image_operations = True
            return

        self.do_image_operations()
开发者ID:caeugusmao,项目名称:thumbor,代码行数:19,代码来源:transformer.py

示例4: test_new_point_to_dict

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
 def test_new_point_to_dict(self):
     point = FocalPoint.from_dict({'x': 10.1, 'y': 20.1, 'z': 5.1})
     expect(point.to_dict()).to_be_like({'x': 10.1, 'y': 20.1, 'z': 5.1, 'origin': 'alignment', 'width': 1.0, 'height': 1.0})
开发者ID:GDxU,项目名称:thumbor,代码行数:5,代码来源:test_point.py

示例5: test_new_point_from_dict

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
 def test_new_point_from_dict(self):
     point = FocalPoint.from_dict({'x': 10.1, 'y': 20.1, 'z': 5.1})
     expect(point.x).to_equal(10.1)
     expect(point.y).to_equal(20.1)
     expect(point.weight).to_equal(5.1)
开发者ID:GDxU,项目名称:thumbor,代码行数:7,代码来源:test_point.py

示例6: callback

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
        def callback(buffer):
            if buffer is None:
                self._error(404)
                return

            context = dict(
                loader=self.loader,
                engine=self.engine,
                storage=self.storage,
                buffer=buffer,
                should_crop=should_crop,
                crop_left=crop_left,
                crop_top=crop_top,
                crop_right=crop_right,
                crop_bottom=crop_bottom,
                fit_in=fit_in,
                should_flip_horizontal=horizontal_flip,
                width=width,
                should_flip_vertical=vertical_flip,
                height=height,
                halign=halign,
                valign=valign,
                extension=extension,
                focal_points=[]
            )

            self.engine.load(buffer, extension)

            if meta:
                context['engine'] = JSONEngine(self.engine, image)

            if self.detectors and should_be_smart:
                focal_points = self.storage.get_detector_data(image)
                if focal_points:
                    for point in focal_points:
                        context['focal_points'].append(FocalPoint.from_dict(point))
                else:
                    with tempfile.NamedTemporaryFile(suffix='.jpg') as temp_file:
                        jpg_buffer = buffer if extension in ('.jpg', '.jpeg') else self.engine.read('.jpg')
                        temp_file.write(jpg_buffer)
                        temp_file.seek(0)
                        context['file'] = temp_file.name
                        self.detectors[0](index=0, detectors=self.detectors).detect(context)

                    points = []
                    focal_points = context['focal_points']

                    for point in focal_points:
                        points.append(point.to_dict())

                    self.storage.put_detector_data(image, points)

            Transformer(context).transform()

            if meta:
                content_type = 'text/javascript' if options.META_CALLBACK_NAME else 'application/json'
            else:
                content_type = CONTENT_TYPE[context['extension']]

            self.set_header('Content-Type', content_type)

            results = context['engine'].read(context['extension'])

            self.write(results)
            self.finish()
开发者ID:cicerocomp,项目名称:thumbor,代码行数:67,代码来源:__init__.py

示例7: topic

# 需要导入模块: from thumbor.point import FocalPoint [as 别名]
# 或者: from thumbor.point.FocalPoint import from_dict [as 别名]
 def topic(self):
     return FocalPoint.from_dict({'x': 10.1, 'y': 20.1, 'z': 5.1})
开发者ID:cezarsa,项目名称:thumbor,代码行数:4,代码来源:point_vows.py


注:本文中的thumbor.point.FocalPoint.from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。