Skip to content

Instantly share code, notes, and snippets.

@CodingFabian
Created June 12, 2014 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodingFabian/0a7c539c081c96538e6a to your computer and use it in GitHub Desktop.
Save CodingFabian/0a7c539c081c96538e6a to your computer and use it in GitHub Desktop.
thubnail resize diff
diff --git a/web/thumbnail_view.js b/web/thumbnail_view.js
index 90d4e89..9766530 100644
--- a/web/thumbnail_view.js
+++ b/web/thumbnail_view.js
@@ -97,12 +97,12 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport) {
this.resume = null;
};
- this.getPageDrawContext = function thumbnailViewGetPageDrawContext() {
+ this.getPageDrawContext = function thumbnailViewGetPageDrawContext(w, h) {
var canvas = document.createElement('canvas');
canvas.id = 'thumbnail' + id;
- canvas.width = this.canvasWidth;
- canvas.height = this.canvasHeight;
+ canvas.width = w || this.canvasWidth;
+ canvas.height = h || this.canvasHeight;
canvas.className = 'thumbnailImage';
canvas.setAttribute('aria-label', mozL10n.get('thumb_page_canvas',
{page: id}, 'Thumbnail of Page {{page}}'));
@@ -187,10 +187,10 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport) {
return;
}
this.renderingState = RenderingStates.FINISHED;
- var ctx = this.getPageDrawContext();
- ctx.drawImage(img, 0, 0, img.width, img.height,
- 0, 0, ctx.canvas.width, ctx.canvas.height);
-
+ var ctx = this.getPageDrawContext(img.width, img.height);
+ ctx.drawImage(img, 0, 0);
+ ctx.canvas.style.width = this.canvasWidth + "px";
+ ctx.canvas.style.height = this.canvasHeight + "px";
this.hasImage = true;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment