Esempio n. 1
0
    def test_save_file(self):
        file_path_fixture = self.get_fixture_file_path("thumbnails/th01.png")
        th_file = FileStorage(stream=open(file_path_fixture, "rb"),
                              filename="th01.png")
        full_path = thumbnail.save_file("shots", "instance-id", th_file)

        thumbnail.turn_into_thumbnail(full_path, thumbnail.RECTANGLE_SIZE)
        im = Image.open(full_path)
        (width, height) = im.size
        self.assertEqual(width, 150)
        self.assertEqual(height, 100)
Esempio n. 2
0
    def test_turn_into_thumbnail(self):
        file_path_fixture = self.get_fixture_file_path("thumbnails/th01.png")
        full_path = thumbnail.get_full_path("shots", "instance-id")
        thumbnail.create_type_folder("shots")
        shutil.copyfile(file_path_fixture, full_path)

        thumbnail.turn_into_thumbnail(full_path)
        im = Image.open(full_path)
        (width, height) = im.size
        self.assertEqual(width, 150)
        self.assertEqual(height, 100)
Esempio n. 3
0
 def save_thumbnail(person, thumbnail):
     from zou.app import app
     with app.app_context():
         thumbnail_path = "/tmp/ldap_th.jpg"
         with open(thumbnail_path, "wb") as th_file:
             th_file.write(thumbnail)
         thumbnail_png_path = thumbnail_utils.convert_jpg_to_png(
             thumbnail_path)
         thumbnail_utils.turn_into_thumbnail(
             thumbnail_png_path, size=thumbnail_utils.BIG_SQUARE_SIZE)
         file_store.add_picture("thumbnails", person["id"],
                                thumbnail_png_path)
         os.remove(thumbnail_png_path)
         persons_service.update_person(person["id"], {"has_avatar": True})
Esempio n. 4
0
    def post(self, instance_id):
        if not self.is_exist(instance_id):
            abort(404)

        self.check_permissions(instance_id)
        self.prepare_creation(instance_id)

        tmp_folder = current_app.config["TMP_DIR"]
        uploaded_file = request.files["file"]
        thumbnail_path = thumbnail_utils.save_file(
            tmp_folder, instance_id, uploaded_file
        )
        thumbnail_path = thumbnail_utils.turn_into_thumbnail(
            thumbnail_path, size=self.size
        )
        file_store.add_picture("thumbnails", instance_id, thumbnail_path)
        os.remove(thumbnail_path)
        self.clear_cache_file(instance_id)

        thumbnail_url_path = thumbnail_utils.url_path(
            self.data_type, instance_id
        )
        self.emit_event(instance_id)

        return {"thumbnail_path": thumbnail_url_path}, 201
Esempio n. 5
0
    def test_turn_into_thumbnail(self):
        file_path_fixture = self.get_fixture_file_path("thumbnails/th01.png")
        full_path = os.path.join(TEST_FOLDER,
                                 thumbnail.get_file_name("instance-id"))
        fs.copyfile(file_path_fixture, full_path)

        thumbnail.turn_into_thumbnail(full_path)
        im = Image.open(full_path)
        (width, height) = im.size
        self.assertEqual(width, 180)
        self.assertEqual(height, 101)

        thumbnail.turn_into_thumbnail(full_path, thumbnail.RECTANGLE_SIZE)
        im = Image.open(full_path)
        (width, height) = im.size
        self.assertEqual(width, 150)
        self.assertEqual(height, 100)