I am trying to write a jQuery plugin that will have similar functionality for the Flash-based product editor on Zazzle.com. I need to know how, using the canvas context.drawImage()
function, I can insert an image and resize it to fit the canvas without distorting it.
The image is 500x500px in size as well as the canvas, but for some reason, when I set 500x500 for the image size, this is the way to go.
Here is my complete code:
(function( $ ) { jQuery.fn.productEditor = function( options ) { var defaults = { 'id' : 'productEditor', 'width' : '500px', 'height' : '500px', 'bgImage' : 'http://www.wattzup.com/projects/jQuery-product-editor/sampleProduct.jpg' }; return this.each(function() { var $this = $(this) var options = $.extend( defaults, options );
Any other constructive criticism is also welcome.
source share