From 2cb1704f4f6aeef358bd0bc3a4fcc364fcec9e23 Mon Sep 17 00:00:00 2001 From: Michael Ang Date: Mon, 23 May 2011 23:18:06 +0000 Subject: [PATCH 1/1] Add rotation support for non-jp2 images --- .../datanode/BookReaderImages.inc.php | 13 +++++++---- BookReaderIA/test/unit/Images.js | 22 ++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/BookReaderIA/datanode/BookReaderImages.inc.php b/BookReaderIA/datanode/BookReaderImages.inc.php index 32a3b8f..7811942 100644 --- a/BookReaderIA/datanode/BookReaderImages.inc.php +++ b/BookReaderIA/datanode/BookReaderImages.inc.php @@ -62,7 +62,7 @@ class BookReaderImages 'h' => 'height', 'x' => 'x', 'y' => 'y', - 'rotate' => 'rotate' + 'rot' => 'rotate' ); // Paths to command-line tools @@ -383,7 +383,7 @@ class BookReaderImages $unzipCmd = $this->getUnarchiveCommand($zipPath, $file); $decompressCmd = $this->getDecompressCmd($imageInfo, $powReduce, $rotate, $scale, $region, $stdoutLink); - + // Non-integer scaling is currently disabled on the cluster // if (isset($_REQUEST['height'])) { // $cmd .= " | pnmscale -height {$_REQUEST['height']} "; @@ -650,9 +650,14 @@ class BookReaderImages $regionString = sprintf('[%dx%d+%d+%d]', $region['w'], $region['h'], $region['x'], $region['y']); // The argument to ImageMagick's scale command is a "geometry". We pass in the new width/height - $scaleString = sprintf("%dx%d", $region['w'] / $scale, $region['h'] / $scale); + $scaleString = ' -scale ' . sprintf("%dx%d", $region['w'] / $scale, $region['h'] / $scale); + + $rotateString = ''; + if ($rotate && $rotate != '0') { + $rotateString = ' -rotate ' . $rotate; // was previously checked to be a known value + } - $decompressCmd = ' | convert -' . $regionString . ' -scale ' . $scaleString . ' pnm:-'; + $decompressCmd = ' | convert -' . $regionString . $scaleString . $rotateString . ' pnm:-'; break; default: diff --git a/BookReaderIA/test/unit/Images.js b/BookReaderIA/test/unit/Images.js index 14fb114..33a2511 100644 --- a/BookReaderIA/test/unit/Images.js +++ b/BookReaderIA/test/unit/Images.js @@ -185,7 +185,7 @@ asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/ .attr('src', pageURI); }); -asyncTest('Load image region from tiff - archive.org/download/fightingflyingc00rickgoog/page/n17_x1944_y1708_w668_h584.jpg', function() { +asyncTest('Load image region from tiff, via br.getRegionURI - fightingflyingc00rickgoog - n17_x1944_y1708_w668_h584', function() { $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() { @@ -203,3 +203,23 @@ asyncTest('Load image region from tiff - archive.org/download/fightingflyingc00r }); }); + +asyncTest('Same image rotated 90 degrees, br.getRegionURI - fightingflyingc00rickgoog - n17_x1944_y1708_w668_h584_rot90', function() { + + $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() { + + expect(3); + var pageURI = br.getRegionURI(17, undefined, 90, 1944, 1708, 668, 584); + + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, 584, 'Image width'); + equals(this.height, 668, 'Image height'); + start(); + }) + .attr('src', pageURI); + + }); +}); + -- 2.20.1