示例#1
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')))
示例#2
0
    def test_hash_calculation(self):
        dj = ImageQuery(self.sample('django_colors.jpg'))
        dj1 = dj.scale(100, 100)
        self.assertNotEqual(dj1._name(), dj._name())
        dj2 = ImageQuery(self.sample('django_colors.jpg')).scale(100, 100)

        self.assertEqual(dj1._name(), dj2._name())
        self.assertNotEqual(dj._name(), dj2._name())
        dj3 = dj.scale(101, 101)
        self.assertNotEqual(dj1._name(), dj3._name())
示例#3
0
    def test_hash_calculation(self):
        dj = ImageQuery(self.sample('django_colors.jpg'))
        dj1 = dj.scale(100,100)
        self.assertNotEqual(dj1._name(), dj._name())
        dj2 = ImageQuery(self.sample('django_colors.jpg')).scale(100,100)

        self.assertEqual(dj1._name(), dj2._name())
        self.assertNotEqual(dj._name(), dj2._name())
        dj3 = dj.scale(101,101)
        self.assertNotEqual(dj1._name(), dj3._name())
示例#4
0
    def test_template_format(self):
        from django import template

        tpl = template.Template(
            '{% load imagequery_tags %}{% image_format "test" image %}')
        ctx = template.Context({
            'image':
            ImageQuery(self.sample('django_colors.jpg')),
        })
        result = tpl.render(ctx)
        self.assertEqual(result, 'cache/test_format/django_colors.jpg')
示例#5
0
        def _get_query(self):
            from imagequery.query import ImageQuery

            try:
                data = pickle.loads(str(self.query_data))
            except pickle.UnpicklingError:
                raise RuntimeError('could not load data')
            return ImageQuery(
                source=data['source'],
                storage=data['storage'],
                cache_storage=data['cache_storage'],
            )
示例#6
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')))
示例#7
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')))
示例#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')
示例#9
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')))
示例#10
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')))
示例#11
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')))
示例#12
0
 def test_format(self):
     iq = ImageQuery(self.sample('django_colors.jpg'))
     f = TestFormat(iq)
     self.assert_(
         self.compare(f.path(),
                      self.sample('results/django_colors_gray.jpg')))
示例#13
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')