diff --git a/src/openseadragon.js b/src/openseadragon.js
index 6eb8d09a..d2235381 100644
--- a/src/openseadragon.js
+++ b/src/openseadragon.js
@@ -255,6 +255,11 @@
* @property {Boolean} [preserveImageSizeOnResize=false]
* Set to true to have the image size preserved when the viewer is resized. This requires autoResize=true (default).
*
+ * @property {Boolean} [allowZoomToConstraintsOnResize=false]
+ * Set to true to allow the image to remain zoomed out past the home zoom level during resize.
+ * If false the image will be zoomed in if necessary such that it touches the edge of the viewer.
+ * This requires autoResize=true (default).
+ *
* @property {Number} [pixelsPerWheelLine=40]
* For pixel-resolution scrolling devices, the number of pixels equal to one scroll line.
*
@@ -995,6 +1000,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
pixelsPerWheelLine: 40,
autoResize: true,
preserveImageSizeOnResize: false, // requires autoResize=true
+ allowZoomToConstraintsOnResize: false, // requires autoResize=true
//DEFAULT CONTROL SETTINGS
showSequenceControl: true, //SEQUENCE
diff --git a/src/viewer.js b/src/viewer.js
index b0ee7757..0ed8b9ed 100644
--- a/src/viewer.js
+++ b/src/viewer.js
@@ -2947,11 +2947,18 @@ function resizeViewportAndRecenter( viewer, containerSize, oldBounds, oldCenter
viewport.resize( containerSize, true );
- // We try to remove blanks as much as possible
- var worldBounds = viewer.world.getHomeBounds();
- var newWidth = oldBounds.width <= worldBounds.width ? oldBounds.width : worldBounds.width;
- var newHeight = oldBounds.height <= worldBounds.height ?
- oldBounds.height : worldBounds.height;
+ var newWidth = oldBounds.width;
+ var newHeight = oldBounds.height;
+
+ if (!viewer.allowZoomToConstraintsOnResize) {
+ var worldBounds = viewer.world.getHomeBounds();
+ if (oldBounds.width > worldBounds.width) {
+ newWidth = worldBounds.width;
+ }
+ if (oldBounds.height > worldBounds.height) {
+ newHeight = worldBounds.height;
+ }
+ }
var newBounds = new $.Rect(
oldCenter.x - ( newWidth / 2.0 ),
@@ -2959,7 +2966,12 @@ function resizeViewportAndRecenter( viewer, containerSize, oldBounds, oldCenter
newWidth,
newHeight
);
- viewport.fitBounds( newBounds, true );
+
+ if (viewer.allowZoomToConstraintsOnResize) {
+ viewport.fitBoundsWithConstraints( newBounds, true );
+ } else {
+ viewport.fitBounds( newBounds, true );
+ }
}
function drawWorld( viewer ) {
diff --git a/test/demo/basic.html b/test/demo/basic.html
index 19572b86..9222a237 100644
--- a/test/demo/basic.html
+++ b/test/demo/basic.html
@@ -5,11 +5,20 @@
@@ -21,11 +30,12 @@