Add rotation support for non-jp2 images
authorMichael Ang <mang@archive.org>
Mon, 23 May 2011 23:18:06 +0000 (23:18 +0000)
committerMichael Ang <mang@archive.org>
Mon, 23 May 2011 23:18:06 +0000 (23:18 +0000)
BookReaderIA/datanode/BookReaderImages.inc.php
BookReaderIA/test/unit/Images.js

index 32a3b8f..7811942 100644 (file)
@@ -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:
index 14fb114..33a2511 100644 (file)
@@ -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);
+        
+    });
+});
+