def generate(self, factor=1):
        thumb_name = self.get_storage_name(factor)

        tmpfile = MoveableNamedTemporaryFile(thumb_name)
        resizer = GmConvertCommand(
            infile=self.source,
            outfile=tmpfile.temporary_file_path(),
            options=self.get_gm_options(factor)
        )
        assert resizer.execute()

        thumbnail_storage.save(thumb_name, tmpfile)

        return True
    def generate(self, factor=1):
        thumb_name = self.get_storage_name(factor)

        tmpfile = MoveableNamedTemporaryFile(thumb_name)
        resizer = GmConvertCommand(
            infile=self.source,
            outfile=tmpfile.temporary_file_path(),
            options=self.get_gm_options(factor)
        )
        assert resizer.execute(fail_silently=True)

        if self.options['pngquant'] and os.path.splitext(thumb_name)[1] == '.png':
            optimizer = PngquantCommand(
                pngfile=tmpfile.temporary_file_path(), quality=self.options['pngquant'])
            assert optimizer.execute()

        thumbnail_storage.save(thumb_name, tmpfile)

        return True
Exemple #3
0
 def test_temporary_file_path(self):
     tmp = MoveableNamedTemporaryFile('test.jpg')
     assert tmp.temporary_file_path() == tmp.file.name
     assert tmp.temporary_file_path().endswith('.jpg') is True
Exemple #4
0
 def test_close(self):
     tmp = MoveableNamedTemporaryFile('test.jpg')
     tmp.close()
     assert tmp.file.file.closed is True
Exemple #5
0
 def test_chunks(self):
     tmp = MoveableNamedTemporaryFile('test.jpg')
     tmp.file.write(force_bytes('test123'))
     tmp.file.seek(0)
     assert tmp.chunks() == force_bytes('test123')