Exemplo n.º 1
0
    def save(self, obj, commit=True):
        if self.upload_type in self.cleaned_data:
            upload_path = os.path.join(settings.TMP_PATH, self.upload_type,
                                       self.upload_hash)

            dirname = obj.get_promo_img_dir()
            destination = os.path.join(dirname, '%s' % obj.id)

            remove_promo_imgs(destination)
            resize_promo_imgs(upload_path, destination,
                              mkt.PROMO_IMG_SIZES, set_modified_on=[obj])

            log.info('Finished processing promo img for %s' % obj.id)
Exemplo n.º 2
0
    def save(self, obj, commit=True):
        if self.upload_type in self.cleaned_data:
            upload_path = os.path.join(settings.TMP_PATH, self.upload_type,
                                       self.upload_hash)

            dirname = obj.get_promo_img_dir()
            destination = os.path.join(dirname, '%s' % obj.id)

            remove_promo_imgs(destination)
            resize_promo_imgs(upload_path,
                              destination,
                              mkt.PROMO_IMG_SIZES,
                              set_modified_on=[obj])

            log.info('Finished processing promo img for %s' % obj.id)
Exemplo n.º 3
0
def _promo_img_uploader(resize_size, final_size):
    img = get_image_path('game_1920.jpg')
    original_size = (1920, 1080)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.WEBAPP_PROMO_IMG_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.jpg',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        shutil.copyfile(img, src.name)
        # Sanity check.
        with storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_promo_imgs(src.name, dest_name, resize_size,
                                      locally=True)
        eq_(val, {'promo_img_hash': '33759cf2'})
        with storage.open('%s-%s.png' % (dest_name, rsize)) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (
                fsize[1], dest_image.size[1]))

        if os.path.exists(dest_image.filename):
            os.remove(dest_image.filename)
        assert not os.path.exists(dest_image.filename)

    assert not os.path.exists(src.name)
Exemplo n.º 4
0
def _promo_img_uploader(resize_size, final_size):
    img = get_image_path('game_1050.jpg')
    original_size = (1050, 591)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.WEBAPP_PROMO_IMG_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b',
                                          suffix='.jpg',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        copy_stored_file(img,
                         src.name,
                         src_storage=local_storage,
                         dest_storage=private_storage)
        # Sanity check.
        with private_storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_promo_imgs(src.name, dest_name, resize_size)
        eq_(val, {'promo_img_hash': '215dd2a2'})
        dest_img_name = '%s-%s.png' % (dest_name, rsize)
        with public_storage.open(dest_img_name) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (fsize[1], dest_image.size[1]))

        if public_storage.exists(dest_img_name):
            public_storage.delete(dest_img_name)
        assert not public_storage.exists(dest_img_name)

    assert not private_storage.exists(src.name)
Exemplo n.º 5
0
def _promo_img_uploader(resize_size, final_size):
    img = get_image_path('game_1050.jpg')
    original_size = (1050, 591)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.WEBAPP_PROMO_IMG_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.jpg',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        copy_stored_file(img, src.name, src_storage=local_storage,
                         dest_storage=private_storage)
        # Sanity check.
        with private_storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_promo_imgs(src.name, dest_name, resize_size)
        eq_(val, {'promo_img_hash': '215dd2a2'})
        dest_img_name = '%s-%s.png' % (dest_name, rsize)
        with public_storage.open(dest_img_name) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (
                fsize[1], dest_image.size[1]))

        if public_storage.exists(dest_img_name):
            public_storage.delete(dest_img_name)
        assert not public_storage.exists(dest_img_name)

    assert not private_storage.exists(src.name)