Beispiel #1
0
    def handle_output(self, term, cacher, result):

        # special case for switches
        if term.__class__.__name__ == "Switch":
            return self.handle_output(term.first_active(), cacher, result)

        outpath = cacher.get_path(term.first_active())
        outname = term.first_active().get_file_name()
        outdzi = utils.media_path_to_url(
                os.path.join(outpath, "%s.dzi" % os.path.splitext(outname)[0]))
        indzi = None
        if term.arity > 0 and term.input(0):
            inpath = cacher.get_path(term.input(0).first_active())
            inname = term.input(0).first_active().get_file_name()
            indzi = utils.media_path_to_url(
                    os.path.join(inpath, "%s.dzi" % os.path.splitext(inname)[0]))

        if term.outtype == numpy.ndarray:
            out = dict(type="image", output=outdzi)
            if indzi is not None:
                out["input"] = indzi
            return out
        elif term.outtype == dict:
            result.update(type="pseg", input=indzi)
            return result
        elif term.outtype == types.HocrString:
            return dict(type="hocr", data=result)
        elif issubclass(term.outtype, basestring):
            return dict(type="text", data=result)
Beispiel #2
0
    def handle_output(self, term, cacher, result):

        # special case for switches
        if term.__class__.__name__ == "Switch":
            return self.handle_output(term.first_active(), cacher, result)

        outpath = cacher.get_path(term.first_active())
        outname = term.first_active().get_file_name()
        outdzi = utils.media_path_to_url(
            os.path.join(outpath, "%s.dzi" % os.path.splitext(outname)[0]))
        indzi = None
        if term.arity > 0 and term.input(0):
            inpath = cacher.get_path(term.input(0).first_active())
            inname = term.input(0).first_active().get_file_name()
            indzi = utils.media_path_to_url(
                os.path.join(inpath, "%s.dzi" % os.path.splitext(inname)[0]))

        if term.outtype == numpy.ndarray:
            out = dict(type="image", output=outdzi)
            if indzi is not None:
                out["input"] = indzi
            return out
        elif term.outtype == dict:
            result.update(type="pseg", input=indzi)
            return result
        elif term.outtype == types.HocrString:
            return dict(type="hocr", data=result)
        elif issubclass(term.outtype, basestring):
            return dict(type="text", data=result)
Beispiel #3
0
 def run(self, filepath, path, **kwargs):
     """
     Create a DZI of the given file, as <path>/dzi/<basename>.
     """
     logger = self.get_logger()
     # find the deepzoom path
     if not os.path.exists(os.path.dirname(path)):
         os.makedirs(os.path.dirname(path))
     if not os.path.exists(path):
         creator = deepzoom.ImageCreator(tile_size=512,
                 tile_overlap=2, tile_format="png",
                 image_quality=1, resize_filter="nearest")
         logger.debug("Creating DZI path: %s", path)
         creator.create(filepath, path)
     return dict(out=utils.media_path_to_url(filepath),
             dst=utils.media_path_to_url(path))
Beispiel #4
0
 def run(self, project_pk, pid, attr, **kwargs):
     """
     Create a DZI of the given document, as <path>/dzi/<basename>.
     """
     logger = self.get_logger()
     project = Project.objects.get(pk=project_pk)
     storage = project.get_storage()
     doc = storage.get(pid)
     path = storage.document_attr_dzi_path(doc, attr)
     if not os.path.exists(os.path.dirname(path)):
         os.makedirs(os.path.dirname(path))
     if not os.path.exists(path):
         with storage.document_attr_content(doc, attr) as handle:
             creator = deepzoom.ImageCreator(tile_size=512,
                     tile_overlap=2, tile_format="png",
                     image_quality=1, resize_filter="nearest")
             logger.debug("Creating DZI path: %s", path)
             creator.create(handle, path)
     return dict(pid=pid, dst=utils.media_path_to_url(path))
 def attr_uri(self, doc, attr):
     """URI for image datastream."""
     return media_path_to_url(
         os.path.join(self.document_path(doc),
                      getattr(self, "%s_name" % attr)))
Beispiel #6
0
 def attr_uri(self, doc, attr):
     """URI for image datastream."""
     return media_path_to_url(
             os.path.join(self.document_path(doc), getattr(self, "%s_name" % attr)))