GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - imyelo/toDataURL: url or <img> element to DataURL

BranchesTags
Open more actions menu

Latest commit

 

History

19 Commits
19 Commits

Folders and files

NameName
Last commit message
Last commit date
dest
dest
 
 
example
example
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
Gruntfile.js
Gruntfile.js
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
component.json
component.json
 
 
package.json
package.json
 
 

Repository files navigation

toDataURL

npm version Build Status Built with Grunt Codeship

url or <img> element to DataURL

Install

npm install --save to-data-url

Usage

define(['toDataURL'], function (toDataURL) {
    var element = document.getElementByTagName('img')[0];
    var src = 'https://avatars0.githubusercontent.com/u/7076521?v=2&s=84';

    /* you can get the dataUrl from an element (not a url) synchronously, */
    console.log(toDataURL(element));
    // > data:image/png;base64,iVBORw0KGgo...

    /* but that sync method may cause some issues, so you can also make it by an async way. */
    toDataURL(element, {
        callback: function (err, data) {
            if (!err) console.log(data);
            // > data:image/png;base64,iVBORw0KGgo...
        }
    });

    /* or get the dataUrl from a url asynchronously */
    toDataURL(src, {
        callback: function (err, data) {
            if (!err) console.log(data);
            // > data:image/png;base64,iVBORw0KGgo...
        }
    });

    /* and define the width and height */
    toDataURL(src, {
        width: 120,
        height: 120,
        callback: function (err, data) {
            if (!err) console.log(data);
            // > data:image/png;base64,iVBORw0KGgo...
        }
    });

    /* maybe you just want the base64 data */
    toDataURL(src, {
        purify: true,
        callback: function (err, data) {
            if (!err) console.log(data);
            // > iVBORw0KGgo...
        }
    });
});

API

toDataURL(image, options)

params

  • image {Image|String}
  • options {Object}

return

  • data {null|String}

options

  • width {Number=0}
  • height {Number=0}
  • purify {Boolean=false}
  • callback {Function}

callback

  • err {Error}
  • data {String}

Release History

  • 0.1.0
    • support toDataURL(elem, [width], [height])
  • 1.0.0
    • support toDataURL(elem, {[callback], [width], [height], [purify]})
    • support toDataURL(src, {callback, [width], [height], [purify]})
    • deprecate toDataURL(elem, width, height)
  • 1.0.1
    • friendly expection message
    • add duojs compiler

License

the MIT License

Bitdeli Badge

About

url or <img> element to DataURL

Topics

dataurlimgjavascript

Resources

Readme
MIT license
Activity

Stars

8 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.