1export const initCanvas = (canvas, size) => {
3 const ctx = canvas.getContext('2d');
5 let ratio = window.devicePixelRatio || 1;
7 canvas.width = x * ratio;
8 canvas.height = y * ratio;
9 canvas.style.width = x + 'px';
10 canvas.style.height = y + 'px';
12 ctx.scale(ratio, ratio);
17export const cleanupCanvas = canvas => {
22export const loadImg = src =>
23 new Promise((resolve, reject) => {
24 const img = new Image();
25 img.onload = () => resolve(img);
26 img.onerror = () => reject(`Error loading image. src: ${src}`);
30export const dataURItoBlob = dataURI => {
31 // convert base64 to raw binary data held in a string
32 // doesn't handle URLEncoded DataURIs
33 const byteString = atob(dataURI.split(',')[1]);
34 // separate out the mime component
35 const mimeString = dataURI
39 // write the bytes of the string to an ArrayBuffer
40 const ab = new ArrayBuffer(byteString.length);
41 // create a view into the buffer
42 let ia = new Uint8Array(ab);
43 // set the bytes of the buffer to the correct values
44 for (var i = 0; i < byteString.length; i++) {
45 ia[i] = byteString.charCodeAt(i);
47 // write the ArrayBuffer to a blob, and you're done
48 const blob = new Blob([ab], { type: mimeString });
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list