Skip to content

Instantly share code, notes, and snippets.

@Deliaz
Last active June 2, 2017 09:50
Show Gist options
  • Select an option

  • Save Deliaz/716f686153b0d97bd0fda9ec1d54e6b8 to your computer and use it in GitHub Desktop.

Select an option

Save Deliaz/716f686153b0d97bd0fda9ec1d54e6b8 to your computer and use it in GitHub Desktop.

Revisions

  1. Deliaz revised this gist Jun 2, 2017. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions get_image_screenshot.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,18 @@
    var getImage = function (videoEl, scale = 1) {
    /**
    * Takes a screenshot from video.
    * @param videoEl {Element} Video element
    * @param scale {Number} Screenshot scale (default = 1)
    * @returns {Element} Screenshot image element
    */
    function getScreenshot(videoEl, scale) {
    scale = scale || 1;

    const canvas = document.createElement("canvas");
    canvas.width = videoEl.clientWidth * scale;
    canvas.height = videoEl.clientHeight * scale;
    canvas.getContext('2d').drawImage(videoEl, 0, 0, canvas.width, canvas.height);

    const image = new Image()
    image.src = canvas.toDataURL();
    return image;
    };
    }
  2. Deliaz created this gist Jun 2, 2017.
    9 changes: 9 additions & 0 deletions get_image_screenshot.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    var getImage = function (videoEl, scale = 1) {
    const canvas = document.createElement("canvas");
    canvas.width = videoEl.clientWidth * scale;
    canvas.height = videoEl.clientHeight * scale;
    canvas.getContext('2d').drawImage(videoEl, 0, 0, canvas.width, canvas.height);
    const image = new Image()
    image.src = canvas.toDataURL();
    return image;
    };