-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from pulibrary/jp2_precinct_support
Adds jp2 precinct support and iiif_img_info command line tool.
- Loading branch information
Showing
8 changed files
with
144 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ rmdirs.sh | |
files.txt | ||
|
||
big.jp2 | ||
|
||
xb526qv4524_05_0001.jp2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
#-*-coding:utf-8-*- | ||
|
||
# iiif_img_info | ||
# | ||
# Command line tool for extracting dumping iiif info.json to stdout. | ||
# | ||
# Syntax: $ iiif_img_info [-v] path/to/an/image.fmt | ||
# -v will show loris's debug logging. | ||
# | ||
# This tool does not report a profile or formats available as they are | ||
# depend on the server. The file extension must be a conventional image format | ||
# extension, e.g.: jpg, jp2, tif | ||
# | ||
|
||
from json import dumps | ||
from os.path import dirname | ||
from os.path import exists | ||
from os.path import isfile | ||
from os.path import join | ||
from os.path import realpath | ||
from os.path import splitext | ||
from sys import argv | ||
from sys import exit | ||
from sys import stderr | ||
from sys import stdout | ||
from urllib import pathname2url | ||
from urlparse import urljoin | ||
|
||
try: | ||
# Use the version on the system if it's there | ||
from loris.img_info import ImageInfo | ||
except ImportError: | ||
# Otherwise try from the source | ||
loris_proj_dp = dirname(dirname(realpath(__file__))) | ||
from sys import path | ||
path.append(loris_proj_dp) | ||
from loris.img_info import ImageInfo | ||
|
||
EX_USAGE = 64 | ||
EX_DATAERR = 65 | ||
EX_NOINPUT = 66 | ||
VERBOSE = '-v' | ||
|
||
|
||
if VERBOSE in argv: | ||
import logging | ||
logging.basicConfig(level=logging.DEBUG) | ||
argv.remove(VERBOSE) | ||
|
||
try: | ||
fp = realpath(argv[1]) | ||
except IndexError: | ||
stderr.write("\nPlease supply the path to an image file.\n\n") | ||
exit(EX_USAGE) | ||
|
||
if not exists(fp): | ||
stderr.write("\n%s does not exist.\n\n" % (fp,)) | ||
exit(EX_NOINPUT) | ||
|
||
fmt = splitext(fp)[1][1:] | ||
uri = urljoin('file:', pathname2url(fp)) | ||
|
||
try: | ||
info = ImageInfo.from_image_file(uri, fp, fmt) | ||
except Exception as e: | ||
stderr.write("\n%s\n\n" % (e,)) | ||
exit(EX_DATAERR) | ||
|
||
info_dict = info.to_dict() | ||
del info_dict['profile'] | ||
del info_dict['formats'] | ||
|
||
stdout.write("%s\n" % (dumps(info_dict, sort_keys=True, indent=4),)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters