Ejemplo n.º 1
0
def test_create_apng(scaffold_spaced_dir: Path,
                     fx_samples_crbundle_002_create_optimized_apng_json: Dict,
                     fx_samples_sequence_dir_contents: List[Path]):
    crpack = fx_samples_crbundle_002_create_optimized_apng_json
    crbundle = CriteriaBundle({
        "create_aimg_criteria":
        CreationCriteria(crpack["criteria"]),
        "gif_opt_criteria":
        GIFOptimizationCriteria(crpack["gif_opt_criteria"]),
        "apng_opt_criteria":
        APNGOptimizationCriteria(crpack["apng_opt_criteria"]),
    })
    tmp_out_path = scaffold_spaced_dir.joinpath("not_tetris.png")
    out_path = create_aimg(fx_samples_sequence_dir_contents, tmp_out_path,
                           crbundle)
    assert out_path == tmp_out_path

    metadata = inspect_general(out_path)
    assert metadata.name['value'] == "not_tetris.png"
    assert metadata.base_filename['value'] == "not_tetris"
    assert metadata.width['value'] == 128
    assert metadata.height['value'] == 128
    assert metadata.loop_count['value'] == 0
    assert metadata.fps['value'] == 5
    assert metadata.average_delay['value'] == 200
    assert metadata.frame_count['value'] == 4
    assert metadata.has_transparency['value']
    assert metadata.hash_sha1[
        'value'] == "657b0c1b7231fc150337bad43a0db2bcea11ea8d"
Ejemplo n.º 2
0
def test_create_gif(scaffold_spaced_dir,
                    fx_samples_crbundle_001_create_optimized_gif_json: Dict,
                    fx_samples_sequence_dir_contents: List[Path]):
    crpack = fx_samples_crbundle_001_create_optimized_gif_json
    crbundle = CriteriaBundle({
        "create_aimg_criteria":
        CreationCriteria(crpack["criteria"]),
        "gif_opt_criteria":
        GIFOptimizationCriteria(crpack["gif_opt_criteria"]),
        "apng_opt_criteria":
        APNGOptimizationCriteria(crpack["apng_opt_criteria"]),
    })
    tmp_out_path = scaffold_spaced_dir.joinpath("checker_rotating.gif")
    out_path = create_aimg(fx_samples_sequence_dir_contents, tmp_out_path,
                           crbundle)
    assert out_path == tmp_out_path

    metadata = inspect_general(out_path)
    assert metadata.name['value'] == "checker_rotating.gif"
    assert metadata.base_filename['value'] == "checker_rotating"
    assert metadata.width['value'] == 71
    assert metadata.height['value'] == 71
    assert metadata.loop_count['value'] == 4
    assert metadata.fps['value'] == 10
    assert metadata.average_delay['value'] == 100
    assert metadata.frame_count['value'] == 4
    assert not metadata.has_transparency['value']
    assert metadata.hash_sha1[
        'value'] == "61b6cd7e939d90fc08c190b02d9745037f96edf7"
Ejemplo n.º 3
0
def test_inspect_agif(fx_samples_checker_agif_path):
    metadata = inspect_general(fx_samples_checker_agif_path)
    assert metadata.is_animated['value']
    assert metadata.format['value'] == 'GIF'
    assert metadata.delays['value'] == [200 for r in range(0, 4)]
    assert metadata.fps['value'] == 5
    assert metadata.width['value'] == 371
    assert metadata.height['value'] == 371
Ejemplo n.º 4
0
 def inspect_one(self, image_path: str, filter: str = ""):
     """Inspect a single image and then return its information"""
     image_path = Path(image_path).resolve()
     if not image_path.exists():
         raise FileNotFoundError(f"{image_path} not found")
     info = inspect_general(image_path, filter)
     if info:
         # print(info.__dict__)
         stdio.data(info.format_info())
Ejemplo n.º 5
0
def test_inspect_apng(fx_samples_checker_apng_path):
    # apng_im = APNG.open(fx_samples_checker_apng_path)
    metadata = inspect_general(fx_samples_checker_apng_path)
    # metadata = inspect_animated_png(fx_samples_checker_apng_path, apng_im)
    assert metadata.is_animated['value']
    assert metadata.format['value'] == 'PNG'
    assert metadata.delays['value'] == [500 for r in range(0, 4)]
    assert metadata.fps['value'] == 2
    assert metadata.width['value'] == 256
    assert metadata.height['value'] == 256
Ejemplo n.º 6
0
def modify_aimg(img_path: Path, out_path: Path, crbundle: CriteriaBundle) -> Path:
    orig_attribute = inspect_general(img_path, filter_on="animated")
    if orig_attribute is None:
        raise Exception("Error: cannot load image")
    criteria = crbundle.modify_aimg_criteria
    change_format = criteria.change_format(orig_attribute)

    if change_format or criteria.gif_must_rebuild():
        stdio.message("Rebuilding im...")
        return rebuild_aimg(img_path, out_path, orig_attribute, crbundle)
    else:
        stdio.message("Modifying im...")
        if criteria.format == "GIF":
            return _modify_gif(img_path, out_path, orig_attribute, crbundle)
        elif criteria.format == "PNG":
            return _modify_apng(img_path, out_path, orig_attribute, crbundle)
Ejemplo n.º 7
0
def test_inspect_static_image(fx_samples_sequence_dir_contents):
    metadata = inspect_general(fx_samples_sequence_dir_contents[0])
    assert not metadata.is_animated['value']
    assert metadata.format['value'] == 'PNG'
    assert metadata.width['value'] == 4
    assert metadata.height['value'] == 4