Exemplo n.º 1
0
    def test_operations(self):
        dj = ImageQuery(self.sample('django_colors.jpg'))
        tux = ImageQuery(self.sample('tux_transparent.png'))
        lynx = ImageQuery(self.sample('lynx_kitten.jpg'))

        dj.grayscale().save(self.tmp('test.jpg'))
        self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/django_colors_gray.jpg')))

        dj.paste(tux, 'center', 'bottom').save(self.tmp('test.jpg'))
        self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/django_colors_with_tux_center_bottom.jpg')))

        lynx.mirror().flip().invert().resize(400,300).save(self.tmp('test.jpg'))
        self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/lynx_kitten_mirror_flip_invert_resize_400_300.jpg')))

        lynx.fit(400,160).save(self.tmp('test.jpg'))
        self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/lynx_fit_400_160.jpg')))

        tux_blank = tux.blank(color='#000088').save(self.tmp('test.png'))
        self.assert_(self.compare(self.tmp('test.png'), self.sample('results/tux_blank_000088.png')))
        self.assertEqual(tux.size(), tux_blank.size())

        lynx.resize(400).save(self.tmp('test.jpg'))
        lynx.resize(400).sharpness(3).save(self.tmp('test2.jpg'))
        lynx.resize(400).sharpness(-1).save(self.tmp('test3.jpg'))
        self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/lynx_resize_400.jpg')))
        self.assert_(self.compare(self.tmp('test2.jpg'), self.sample('results/lynx_resize_400_sharpness_3.jpg')))
        self.assert_(self.compare(self.tmp('test3.jpg'), self.sample('results/lynx_resize_400_sharpness_-1.jpg')))
        self.assert_(not self.compare(self.tmp('test.jpg'), self.tmp('test2.jpg')))

        dj.text('Django ImageQuery', 'center', 10, os.path.join(self.font_dir, 'Vera.ttf'), 20, '#000000').save(self.tmp('test.jpg'))
        self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/django_colors_text_center_10.jpg')))

        self.assertEqual(dj.mimetype(), 'image/jpeg')
        self.assertEqual(tux.mimetype(), 'image/png')
Exemplo n.º 2
0
 def test_load_model_field(self):
     instance = ImageModel.objects.create(
         name='Hi', image=self.sample('django_colors.jpg'))
     instance = ImageModel.objects.get(pk=instance.pk)
     iq = ImageQuery(instance.image)
     iq.grayscale().save(self.tmp('test.jpg'))
     self.assert_(
         self.compare(self.tmp('test.jpg'),
                      self.sample('results/django_colors_gray.jpg')))
Exemplo n.º 3
0
 def test_custom_storage(self):
     shutil.copyfile(self.sample('django_colors.jpg'), os.path.join(self.tmpstorage_dir, 'customstorage.jpg'))
     # load from custom tmp storage
     iq = ImageQuery('customstorage.jpg', storage=self.tmpstorage)
     
     iq.grayscale().save('save.jpg')
     self.assert_(self.compare(os.path.join(self.tmpstorage_dir, 'save.jpg'), self.sample('results/django_colors_gray.jpg')))
     
     iq.grayscale().save('save.jpg', storage=self.tmpstorage_save)
     self.assert_(self.compare(os.path.join(self.tmpstorage_save_dir, 'save.jpg'), self.sample('results/django_colors_gray.jpg')))
     
     iq = ImageQuery('customstorage.jpg', storage=self.tmpstorage, cache_storage=self.tmpstorage_save)
     iq.grayscale().save('save.jpg')
     self.assert_(self.compare(os.path.join(self.tmpstorage_save_dir, 'save.jpg'), self.sample('results/django_colors_gray.jpg')))
Exemplo n.º 4
0
    def test_custom_storage(self):
        shutil.copyfile(self.sample('django_colors.jpg'),
                        os.path.join(self.tmpstorage_dir, 'customstorage.jpg'))
        # load from custom tmp storage
        iq = ImageQuery('customstorage.jpg', storage=self.tmpstorage)

        iq.grayscale().save('save.jpg')
        self.assert_(
            self.compare(os.path.join(self.tmpstorage_dir, 'save.jpg'),
                         self.sample('results/django_colors_gray.jpg')))

        iq.grayscale().save('save.jpg', storage=self.tmpstorage_save)
        self.assert_(
            self.compare(os.path.join(self.tmpstorage_save_dir, 'save.jpg'),
                         self.sample('results/django_colors_gray.jpg')))

        iq = ImageQuery('customstorage.jpg',
                        storage=self.tmpstorage,
                        cache_storage=self.tmpstorage_save)
        iq.grayscale().save('save.jpg')
        self.assert_(
            self.compare(os.path.join(self.tmpstorage_save_dir, 'save.jpg'),
                         self.sample('results/django_colors_gray.jpg')))
Exemplo n.º 5
0
 def test_load_model_field(self):
     instance = ImageModel.objects.create(name='Hi', image=self.sample('django_colors.jpg'))
     instance = ImageModel.objects.get(pk=instance.pk)
     iq = ImageQuery(instance.image)
     iq.grayscale().save(self.tmp('test.jpg'))
     self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/django_colors_gray.jpg')))
Exemplo n.º 6
0
 def test_load_simple_filename(self):
     iq = ImageQuery(self.sample('django_colors.jpg'))
     iq.grayscale().save(self.tmp('test.jpg'))
     self.assert_(self.compare(self.tmp('test.jpg'), self.sample('results/django_colors_gray.jpg')))
Exemplo n.º 7
0
 def test_load_simple_filename(self):
     iq = ImageQuery(self.sample('django_colors.jpg'))
     iq.grayscale().save(self.tmp('test.jpg'))
     self.assert_(
         self.compare(self.tmp('test.jpg'),
                      self.sample('results/django_colors_gray.jpg')))
Exemplo n.º 8
0
    def test_operations(self):
        dj = ImageQuery(self.sample('django_colors.jpg'))
        tux = ImageQuery(self.sample('tux_transparent.png'))
        lynx = ImageQuery(self.sample('lynx_kitten.jpg'))

        dj.grayscale().save(self.tmp('test.jpg'))
        self.assert_(
            self.compare(self.tmp('test.jpg'),
                         self.sample('results/django_colors_gray.jpg')))

        dj.paste(tux, 'center', 'bottom').save(self.tmp('test.jpg'))
        self.assert_(
            self.compare(
                self.tmp('test.jpg'),
                self.sample(
                    'results/django_colors_with_tux_center_bottom.jpg')))

        lynx.mirror().flip().invert().resize(400,
                                             300).save(self.tmp('test.jpg'))
        self.assert_(
            self.compare(
                self.tmp('test.jpg'),
                self.sample(
                    'results/lynx_kitten_mirror_flip_invert_resize_400_300.jpg'
                )))

        lynx.fit(400, 160).save(self.tmp('test.jpg'))
        self.assert_(
            self.compare(self.tmp('test.jpg'),
                         self.sample('results/lynx_fit_400_160.jpg')))

        tux_blank = tux.blank(color='#000088').save(self.tmp('test.png'))
        self.assert_(
            self.compare(self.tmp('test.png'),
                         self.sample('results/tux_blank_000088.png')))
        self.assertEqual(tux.size(), tux_blank.size())

        lynx.resize(400).save(self.tmp('test.jpg'))
        lynx.resize(400).sharpness(3).save(self.tmp('test2.jpg'))
        lynx.resize(400).sharpness(-1).save(self.tmp('test3.jpg'))
        self.assert_(
            self.compare(self.tmp('test.jpg'),
                         self.sample('results/lynx_resize_400.jpg')))
        self.assert_(
            self.compare(
                self.tmp('test2.jpg'),
                self.sample('results/lynx_resize_400_sharpness_3.jpg')))
        self.assert_(
            self.compare(
                self.tmp('test3.jpg'),
                self.sample('results/lynx_resize_400_sharpness_-1.jpg')))
        self.assert_(
            not self.compare(self.tmp('test.jpg'), self.tmp('test2.jpg')))

        dj.text('Django ImageQuery', 'center', 10,
                os.path.join(self.font_dir, 'Vera.ttf'), 20,
                '#000000').save(self.tmp('test.jpg'))
        self.assert_(
            self.compare(
                self.tmp('test.jpg'),
                self.sample('results/django_colors_text_center_10.jpg')))

        self.assertEqual(dj.mimetype(), 'image/jpeg')
        self.assertEqual(tux.mimetype(), 'image/png')