src/Layer.js
function resize(newWidth, newHeight) {

        // Default size to zero
        newWidth = newWidth || 0;
        newHeight = newHeight || 0;

        // Calculate new dimensions of internal canvas
        var canvasWidth  = Math.ceil(newWidth  / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
        var canvasHeight = Math.ceil(newHeight / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;

        // Resize only if canvas dimensions are actually changing
        if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {

            // Copy old data only if relevant and non-empty
            var oldData = null;
            if (!empty && canvas.width !== 0 && canvas.height !== 0) {

                // Create canvas and context for holding old data
                oldData = document.createElement("canvas");
                oldData.width = Math.min(layer.width, newWidth);
                oldData.height = Math.min(layer.height, newHeight);

                var oldDataContext = oldData.getContext("2d");

                // Copy image data from current
                oldDataContext.drawImage(canvas,
                        0, 0, oldData.width, oldData.height,
                        0, 0, oldData.width, oldData.height);

            }

            // Preserve composite operation
            var oldCompositeOperation = context.globalCompositeOperation;

            // Resize canvas
            canvas.width = canvasWidth;
            canvas.height = canvasHeight;

            // Redraw old data, if any
            if (oldData)
                context.drawImage(oldData,
                    0, 0, oldData.width, oldData.height,
                    0, 0, oldData.width, oldData.height);

            // Restore composite operation
            context.globalCompositeOperation = oldCompositeOperation;

            // Acknowledge reset of stack (happens on resize of canvas)
            stackSize = 0;
            context.save();

        }

        // If the canvas size is not changing, manually force state reset
        else
            layer.reset();

        // Assign new layer dimensions
        layer.width = newWidth;
        layer.height = newHeight;

    }
function resize(newWidth, newHeight) {

        // Default size to zero
        newWidth = newWidth || 0;
        newHeight = newHeight || 0;

        // Calculate new dimensions of internal canvas
        var canvasWidth  = Math.ceil(newWidth  / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
        var canvasHeight = Math.ceil(newHeight / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;

        // Resize only if canvas dimensions are actually changing
        if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {

            // Copy old data only if relevant and non-empty
            var oldData = null;
            if (!empty && canvas.width !== 0 && canvas.height !== 0) {

                // Create canvas and context for holding old data
                oldData = document.createElement("canvas");
                oldData.width = Math.min(layer.width, newWidth);
                oldData.height = Math.min(layer.height, newHeight);

                var oldDataContext = oldData.getContext("2d");

                // Copy image data from current
                oldDataContext.drawImage(canvas,
                        0, 0, oldData.width, oldData.height,
                        0, 0, oldData.width, oldData.height);

            }

            // Preserve composite operation
            var oldCompositeOperation = context.globalCompositeOperation;

            // Resize canvas
            canvas.width = canvasWidth;
            canvas.height = canvasHeight;

            // Redraw old data, if any
            if (oldData)
                context.drawImage(oldData,
                    0, 0, oldData.width, oldData.height,
                    0, 0, oldData.width, oldData.height);

            // Restore composite operation
            context.globalCompositeOperation = oldCompositeOperation;

            // Acknowledge reset of stack (happens on resize of canvas)
            stackSize = 0;
            context.save();

        }

        // If the canvas size is not changing, manually force state reset
        else
            layer.reset();

        // Assign new layer dimensions
        layer.width = newWidth;
        layer.height = newHeight;

    }
function resize ( newWidth , newHeight ) { // Default size to zero newWidth = newWidth || 0 ; newHeight = newHeight || 0 ; // Calculate new dimensions of internal canvas var canvasWidth = Math . ceil ( newWidth / CANVAS_SIZE_FACTOR ) * CANVAS_SIZE_FACTOR ; var canvasHeight = Math . ceil ( newHeight / CANVAS_SIZE_FACTOR ) * CANVAS_SIZE_FACTOR ; // Resize only if canvas dimensions are actually changing if ( canvas . width !== canvasWidth || canvas . height !== canvasHeight ) { // Copy old data only if relevant and non-empty var oldData = null ; if ( ! empty && canvas . width !== 0 && canvas . height !== 0 ) { // Create canvas and context for holding old data oldData = document . createElement ( "canvas" ) ; oldData . width = Math . min ( layer . width , newWidth ) ; oldData . height = Math . min ( layer . height , newHeight ) ; var oldDataContext = oldData . getContext ( "2d" ) ; // Copy image data from current oldDataContext . drawImage ( canvas , 0 , 0 , oldData . width , oldData . height , 0 , 0 , oldData . width , oldData . height ) ; } // Preserve composite operation var oldCompositeOperation = context . globalCompositeOperation ; // Resize canvas canvas . width = canvasWidth ; canvas . height = canvasHeight ; // Redraw old data, if any if ( oldData ) context . drawImage ( oldData , 0 , 0 , oldData . width , oldData . height , 0 , 0 , oldData . width , oldData . height ) ; // Restore composite operation context . globalCompositeOperation = oldCompositeOperation ; // Acknowledge reset of stack (happens on resize of canvas) stackSize = 0 ; context . save ( ) ; } // If the canvas size is not changing, manually force state reset else layer . reset ( ) ; // Assign new layer dimensions layer . width = newWidth ; layer . height = newHeight ; }
Resizes the canvas element backing this Layer. This function should only
be used internally.

@private
@param {Number} [newWidth=0]
The new width to assign to this Layer.

@param {Number} [newHeight=0]
The new height to assign to this Layer.
Resizes the canvas element backing this Layer . This function should only be used internally .