Is it possible to give the canvas a background colour? So that when the image is submitted it will have a colour rather than be blank (if the image isnt big enough). Does anyone have any ideas on how to do this please?
Filling the canvas context with a colour doesnt seem to work
https://jsfiddle.net/n7xL5c37/1/
var canvas = document.getElementById('canvas');
var image = new Image();
image.src = 'http://placehold.it/300x550';
image.onload = function () {
var canvasContext = canvas.getContext('2d');
var wrh = image.width / image.height;
var newWidth = canvas.width;
var newHeight = newWidth / wrh;
if (newHeight > canvas.height) {
newHeight = canvas.height;
newWidth = newHeight * wrh;
}
var xOffset = newWidth < canvas.width ? ((canvas.width - newWidth) / 2) : 0;
var yOffset = newHeight < canvas.height ? ((canvas.height - newHeight) / 2) : 0;
canvasContext.drawImage(image, xOffset, yOffset, newWidth, newHeight);
canvasContext.fillStyle = "red";
};