Beispiel #1
0
def test_set_dpi_on_tiff(sample_images):
    test_jp2 = os.path.join(sample_images, "dummy.tif")
    sample_image = core.Image(test_jp2)
    assert sample_image.exif['Exif.Image.XResolution'] != "400/1"
    assert sample_image.exif['Exif.Image.YResolution'] != "400/1"
    assert sample_image.exif['Exif.Image.ResolutionUnit'] == "2"

    # core.set_dpi(test_jp2, 300, 300)
    core.set_dpi(image=str(test_jp2), x=300, y=300)
    sample_image2 = core.Image(test_jp2)
    assert sample_image2.exif['Exif.Image.XResolution'] == "300/1"
    assert sample_image2.exif['Exif.Image.YResolution'] == "300/1"
    assert sample_image2.exif['Exif.Image.ResolutionUnit'] == "2"
 def generate_jp2(source_file: str, output_file_path: str):
     in_args = [
         "Clevels=5",
         "Clayers=8",
         "Corder=RLCP",
         "Cuse_sop=yes",
         "Cuse_eph=yes",
         "Cmodes=RESET|RESTART|CAUSAL|ERTERM|SEGMARK",
         "-no_weights",
         "-slope",
         "42988",
         "-jp2_space",
         "sRGB",
     ]
     pykdu_compress.kdu_compress_cli2(source_file,
                                      output_file_path,
                                      in_args=in_args)
     set_dpi(output_file_path, x=400, y=400)
    def transform(self, source: str, destination: str,
                  logger: logging.Logger) -> str:
        """Transform jp2 hathi.

        Args:
            source:
            destination:
            logger: System logger. For debugging or passing processing data

        """
        if destination.endswith(".jp2"):
            new_file = destination
        else:
            dest = os.path.abspath(os.path.dirname(destination))
            base_name = os.path.splitext(os.path.basename(source))[0]
            new_name = f"{base_name}.jp2"
            new_file = os.path.join(dest, new_name)

        self.make_jp2(source, new_file)
        logger.info(f"Fixing up {new_file} to 400 dpi")
        set_dpi(new_file, x=400, y=400)
        return new_file
    def process(self, source_file, destination_path):
        basename, ext = os.path.splitext(os.path.basename(source_file))

        output_file_path = os.path.join(destination_path, basename + ".jp2")

        in_args = [
            "Clevels=5",
            "Clayers=8",
            "Corder=RLCP",
            "Cuse_sop=yes",
            "Cuse_eph=yes",
            "Cmodes=RESET|RESTART|CAUSAL|ERTERM|SEGMARK",
            "-no_weights",
            "-slope",
            "42988",
            "-jp2_space",
            "sRGB",
        ]
        pykdu_compress.kdu_compress_cli2(source_file,
                                         output_file_path,
                                         in_args=in_args)
        set_dpi(output_file_path, x=400, y=400)

        self.status = "Generated {}".format(output_file_path)