**
This commit is contained in:
parent
1f4b917318
commit
f604780056
@ -43,34 +43,39 @@ DOTGRID.Renderer = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.svg64 = function () {
|
this.svg64 = function () {
|
||||||
this.update()
|
|
||||||
let xml = new XMLSerializer().serializeToString(this.el)
|
let xml = new XMLSerializer().serializeToString(this.el)
|
||||||
let svg64 = btoa(xml)
|
let svg64 = btoa(xml)
|
||||||
let b64Start = 'data:image/svg+xml;base64,'
|
let b64Start = 'data:image/svg+xml;base64,'
|
||||||
return b64Start + svg64
|
return b64Start + svg64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exporters
|
||||||
|
|
||||||
this.toPNG = function (size = DOTGRID.tool.settings.size, callback) {
|
this.toPNG = function (size = DOTGRID.tool.settings.size, callback) {
|
||||||
|
this.update()
|
||||||
|
|
||||||
let image64 = this.svg64()
|
let image64 = this.svg64()
|
||||||
let img = new Image()
|
let img = new Image()
|
||||||
let canvas = document.createElement('canvas')
|
let canvas = document.createElement('canvas')
|
||||||
canvas.width = (size.width) * 2
|
canvas.width = (size.width) * 2
|
||||||
canvas.height = (size.height) * 2
|
canvas.height = (size.height) * 2
|
||||||
let ctx = canvas.getContext('2d')
|
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
ctx.drawImage(img, 0, 0, (size.width) * 2, (size.height) * 2)
|
canvas.getContext('2d').drawImage(img, 0, 0, (size.width) * 2, (size.height) * 2)
|
||||||
let data = canvas.toDataURL('image/png')
|
callback(canvas.toDataURL('image/png'), 'export.png')
|
||||||
callback(data, 'export.png')
|
|
||||||
}
|
}
|
||||||
img.src = image64
|
img.src = image64
|
||||||
}
|
}
|
||||||
|
|
||||||
this.toSVG = function (callback) {
|
this.toSVG = function (callback) {
|
||||||
|
this.update()
|
||||||
|
|
||||||
const image64 = this.svg64()
|
const image64 = this.svg64()
|
||||||
callback(image64, 'export.svg')
|
callback(image64, 'export.svg')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.toGRID = function (callback) {
|
this.toGRID = function (callback) {
|
||||||
|
this.update()
|
||||||
|
|
||||||
const text = DOTGRID.tool.export()
|
const text = DOTGRID.tool.export()
|
||||||
const file = new Blob([text], { type: 'text/plain' })
|
const file = new Blob([text], { type: 'text/plain' })
|
||||||
callback(URL.createObjectURL(file), 'export.grid')
|
callback(URL.createObjectURL(file), 'export.grid')
|
||||||
|
Loading…
Reference in New Issue
Block a user