How to use the sigal.settings.create_settings function in sigal

To help you get started, we’ve selected a few sigal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saimn / sigal / tests / test_image.py View on Github external
def test_resize_image_portrait(tmpdir):
    """Test that the area is the same regardless of aspect ratio."""
    size = (300, 200)
    settings = create_settings(img_size=size)

    portrait_image = 'm57_the_ring_nebula-587px.jpg'
    portrait_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', portrait_image)
    portrait_dst = str(tmpdir.join(portrait_image))

    generate_image(portrait_src, portrait_dst, settings)
    im = Image.open(portrait_dst)

    # In the default mode, PILKit resizes in a way to never make an image
    # smaller than either of the lengths, the other is scaled accordingly.
    # Hence we test that the shorter side has the smallest length.
    assert im.size[0] == 200

    landscape_image = 'KeckObservatory20071020.jpg'
    landscape_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', landscape_image)
    landscape_dst = str(tmpdir.join(landscape_image))
github saimn / sigal / tests / test_image.py View on Github external
def test_generate_image_passthrough_symlink(tmpdir):
    "Test the generate_image function with use_orig=True and orig_link=True."

    dstfile = str(tmpdir.join(TEST_IMAGE))
    settings = create_settings(use_orig=True, orig_link=True)
    generate_image(SRCFILE, dstfile, settings)
    # Check the file was symlinked
    assert os.path.islink(dstfile)
    assert os.path.samefile(SRCFILE, dstfile)
github saimn / sigal / tests / test_video.py View on Github external
def test_process_video(tmpdir):
    base, ext = os.path.splitext(TEST_VIDEO)

    settings = create_settings(video_format='ogv', use_orig=True,
                               orig_link=True)
    process_video(SRCFILE, str(tmpdir), settings)
    dstfile = str(tmpdir.join(base + '.ogv'))
    assert os.path.realpath(dstfile) == SRCFILE

    settings = create_settings(video_format='mjpg')
    assert process_video(SRCFILE, str(tmpdir), settings) == Status.FAILURE

    settings = create_settings(thumb_video_delay=-1)
    assert process_video(SRCFILE, str(tmpdir), settings) == Status.FAILURE
github saimn / sigal / tests / test_image.py View on Github external
def test_generate_image_passthrough(tmpdir, image, path):
    "Test the generate_image function with use_orig=True."

    dstfile = str(tmpdir.join(image))
    settings = create_settings(use_orig=True)
    generate_image(path, dstfile, settings)
    # Check the file was copied, not (sym)linked
    st_src = os.stat(path)
    st_dst = os.stat(dstfile)
    assert st_src.st_size == st_dst.st_size
    assert not os.path.samestat(st_src, st_dst)
github saimn / sigal / tests / test_video.py View on Github external
def test_process_video(tmpdir):
    base, ext = os.path.splitext(TEST_VIDEO)

    settings = create_settings(video_format='ogv', use_orig=True,
                               orig_link=True)
    process_video(SRCFILE, str(tmpdir), settings)
    dstfile = str(tmpdir.join(base + '.ogv'))
    assert os.path.realpath(dstfile) == SRCFILE

    settings = create_settings(video_format='mjpg')
    assert process_video(SRCFILE, str(tmpdir), settings) == Status.FAILURE

    settings = create_settings(thumb_video_delay=-1)
    assert process_video(SRCFILE, str(tmpdir), settings) == Status.FAILURE
github saimn / sigal / tests / test_image.py View on Github external
def test_process_image(tmpdir):
    "Test the process_image function."

    status = process_image('foo.txt', 'none.txt', {})
    assert status == Status.FAILURE

    settings = create_settings(img_processor='ResizeToFill', make_thumbs=False)
    status = process_image(SRCFILE, str(tmpdir), settings)
    assert status == Status.SUCCESS
    im = Image.open(os.path.join(str(tmpdir), TEST_IMAGE))
    assert im.size == settings['img_size']
github saimn / sigal / tests / test_video.py View on Github external
def test_generate_video_fit_height(tmpdir, fmt):
    """largest fitting dimension is height"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings = create_settings(video_size=(50, 100), video_format=fmt)
    generate_video(SRCFILE, dstfile, settings,
                   options=settings[fmt + '_options'])

    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_dst[0] == 50
    # less than 2% error on ratio
    assert abs(size_dst[0]/size_dst[1] - size_src[0]/size_src[1]) < 2e-2
github saimn / sigal / tests / test_image.py View on Github external
def test_exif_copy(tmpdir):
    "Test if EXIF data can transferred copied to the resized image."

    test_image = '11.jpg'
    src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
                            test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(300, 400), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert simple['iso'] == 50

    settings['copy_exif_data'] = False
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert not simple
github saimn / sigal / tests / test_image.py View on Github external
def test_generate_image_processor(tmpdir):
    "Test generate_image with a wrong processor name."

    init_logging('sigal')
    dstfile = str(tmpdir.join(TEST_IMAGE))
    settings = create_settings(img_size=(200, 200),
                               img_processor='WrongMethod')

    with pytest.raises(SystemExit):
        generate_image(SRCFILE, dstfile, settings)
github saimn / sigal / tests / test_image.py View on Github external
def test_exif_gps(tmpdir):
    """Test reading out correct geo tags"""

    test_image = 'flickr_jerquiaga_2394751088_cc-by-nc.jpg'
    src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
                            test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(400, 300), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert 'gps' in simple

    lat = 34.029167
    lon = -116.144167

    assert abs(simple['gps']['lat'] - lat) < 0.0001
    assert abs(simple['gps']['lon'] - lon) < 0.0001