$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$type = imageExtensionToType($fileExt);
- // $$$ will exiftool work for *all* of our images?
- // BitsPerComponent present in jp2. Not present in jpeg.
+ // We look for all the possible tags of interest then act on the
+ // ones presumed present based on the file type
+ $tagsToGet = ' -ImageWidth -ImageHeight -FileType' // all formats
+ . ' -BitsPerComponent -ColorSpace' // jp2
+ . ' -BitDepth' // png
+ . ' -BitsPerSample'; // tiff
+
$cmd = getUnarchiveCommand($zipPath, $file)
- . ' | '. $exiftool . ' -s -s -s -ImageWidth -ImageHeight -BitsPerComponent -Colorspace -';
+ . ' | '. $exiftool . ' -S -fast' . $tagsToGet . ' -';
exec($cmd, $output);
- $width = intval($output[0]);
- $height = intval($output[1]);
- preg_match('/^(\d+)/', $output[2], $groups);
- $bits = intval($groups[1]);
- $colorspace = intval($output[3]);
-
- // Format-specific overrides
- if ('jpeg' == $type) {
- // Note: JPEG may be single channel grayscale. jpegtopnm will create PGM in this case.
- $bits = 8;
+ $tags = Array();
+ foreach ($output as $line) {
+ $keyValue = explode(": ", $line);
+ $tags[$keyValue[0]] = $keyValue[1];
}
+ $width = intval($tags["ImageWidth"]);
+ $height = intval($tags["ImageHeight"]);
+ $type = strtolower($tags["FileType"]);
+
+ switch ($tags["FileType"]) {
+ case "JP2":
+ $bits = intval($tags["BitsPerComponent"]);
+ break;
+ case "TIFF":
+ $bits = intval($tags["BitsPerSample"]);
+ break;
+ case "JPEG":
+ $bits = 8;
+ break;
+ case "PNG":
+ $bits = intval($tags["BitDepth"]);
+ break;
+ default:
+ BRfatal("Unsupported image type");
+ break;
+ }
+
+
$retval = Array('width' => $width, 'height' => $height,
'bits' => $bits, 'type' => $type);
} else if ('jpg' == $fileExt) {
$decompressCmd = ' | jpegtopnm ' . reduceCommand($scale);
+
+} else if ('png' == $fileExt) {
+ $decompressCmd = ' | pngtopnm ' . reduceCommand($scale);
} else {
BRfatal('Unknown source file extension: ' . $fileExt);
});
+/// nybc200109 - 1-bit tiff zip
+asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
+ expect(1);
+ $.getScript( jsLocateURL('nybc200109'), function() {
+ equals(br.numLeafs,
+ 694,
+ 'Number of pages');
+ start();
+ });
+});
+
+asyncTest("Image info for 1-bit tiff", function() {
+ expect(3);
+ var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
+ var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
+
+ $.getJSON(imageInfoURL, function(data) {
+ equals(data != null, true, 'data is not null');
+ if (data != null) {
+ equals(data.width, expected.width, 'Image width');
+ same(data, expected, 'Image info object');
+ }
+ start();
+ });
+});
+
+asyncTest("Load 1-bit tiff image from zip", function() {
+ expect(2);
+ var pageURI = br.getPageURI(6, 16);
+ var img = new Image();
+ $(img).bind( 'load error', function(eventObj) {
+ equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+ equals(this.width, 318, 'Image width');
+ start();
+ })
+ .attr('src', pageURI);
+});
+
+
+
/// asamoandictiona00pragoog - tiff zip
asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
expect(1);
});
});
+asyncTest("Image info for 8-bit tiff", function() {
+ expect(3);
+ var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
+ var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
+
+ $.getJSON(imageInfoURL, function(data) {
+ equals(data != null, true, 'data is not null');
+ if (data != null) {
+ equals(data.width, expected.width, 'Image width');
+ same(data, expected, 'Image info object');
+ }
+ start();
+ });
+});
+
asyncTest("Load tiff image from zip", function() {
expect(2);
var pageURI = br.getPageURI(23, 8);