I have a product that you can alter the look of by adding additional products / designs to.
Our builder is in HTML5, and the product you alter is on a canvas.
I need the ability to share the final product that the user has built, effectively I want to take a screenshot of the final product and then have it open in a lightbox (with share buttons for social media).
It can be stored locally or server side.
Any help on this would be hugely grateful, I've found a few solutions but involve PHP, we have PHP turned off on the server.
I found a nice script on here, which I thought I could convert and have a selection via coordinates instead of an mp4, but failed to do so, I can't see this way working...
See: http://codepen.io/alexwhitfield/pen/XbMamB
Html:
<html lang="en">
<head>
<meta charset=utf-8>
<title>Screenshot stuff</title>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="video-canvas.css" />
</head>
<body>
<video controls>
<source src="https://www.clogau.co.uk/feeds/airport/resources/ClogauAdvert10secs.mp4 " type="video/mp4">
</video>
<canvas></canvas>
<footer>
</footer>
<button id="snap" onclick="snap()">Take screenshot</button>
</body>
</html>
CSS:
article, aside, figure, figcaption, footer, header, hgroup, menu, nav, section { display:block; }
video, canvas {
border:1px solid #000;
}
button {
margin-top:10px;
}
footer {
font-size:11px;
color:#aaa;
margin-top:10px;
}
small {
color:#aaa;
font-size:11px;
display:block;
}
a {
color:#aaa;
text-decoration:none;
}
JavaScript
// Get handles on the video and canvas elements
var video = document.querySelector('video');
var canvas = document.querySelector('canvas');
// Get a handle on the 2d context of the canvas element
var context = canvas.getContext('2d');
// Define some vars required later
var w, h, ratio;
// Add a listener to wait for the 'loadedmetadata' state so the video's dimensions can be read
video.addEventListener('loadedmetadata', function() {
// Calculate the ratio of the video's width to height
ratio = video.videoWidth / video.videoHeight;
// Define the required width as 100 pixels smaller than the actual video's width
w = video.videoWidth - 100;
// Calculate the height based on the video's width and the ratio
h = parseInt(w / ratio, 10);
// Set the canvas width and height to the values just calculated
canvas.width = w;
canvas.height = h;
}, false);
// Takes a snapshot of the video
function snap() {
// Define the size of the rectangle that will be filled (basically the entire element)
context.fillRect(0, 0, w, h);
// Grab the image from the video
context.drawImage(video, 0, 0, w, h);
}
Thanks
Alex