social-graphics-library
Advanced tools
Comparing version 1.3.3 to 1.4.0
import Call from "./model/call"; | ||
declare class SocialGraphicsLibrary { | ||
/** | ||
* Social graphics library | ||
*/ | ||
export default class SocialGraphicsLibrary { | ||
/** | ||
@@ -10,15 +13,6 @@ * Generators social graphics library | ||
* @param imgMode | ||
* @param [generateLink] | ||
*/ | ||
static generator(teamName: string, playerName: string, mode: string, containerId: string, imgMode: string): void; | ||
static generator(teamName: string, playerName: string, mode: string, containerId: string, imgMode: string, generateLink?: boolean): void; | ||
/** | ||
* Prints image | ||
* @param svgString | ||
* @param width | ||
* @param height | ||
* @param containerId | ||
* @param imgMode | ||
* @returns image | ||
*/ | ||
static printImage(svgString: string, width: number, height: number, containerId: string, imgMode: string): void; | ||
/** | ||
* Multis generator | ||
@@ -40,2 +34,1 @@ * @param teamName | ||
} | ||
export default SocialGraphicsLibrary; |
@@ -14,2 +14,6 @@ export default interface Call { | ||
imgMode: string; | ||
/** | ||
* generate link of call | ||
*/ | ||
generateLink: boolean; | ||
} |
@@ -33,4 +33,5 @@ import "./dist/sgl.bundle.js"; | ||
containerId: 'img-container-5', | ||
imgMode: 'png' | ||
imgMode: 'png', | ||
generateLink: true | ||
}]) | ||
}); |
{ | ||
"name": "social-graphics-library", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"description": "A script for generating social media logos and banners", | ||
@@ -59,2 +59,2 @@ "scripts": { | ||
"dependencies": {} | ||
} | ||
} |
185
src/glc.ts
@@ -1,13 +0,10 @@ | ||
import { False_Template } from "./template/false.template"; | ||
import { Logo_Template } from "./template/logo.template"; | ||
import Call from "./model/call"; | ||
import { Youtube_Template } from "./template/youtube-title.template"; | ||
import { Elevate_Template } from "./template/elevate-title.template"; | ||
import { Twitch_Template } from "./template/twitch-title.template"; | ||
import { Twitter_Template } from "./template/twitter-title.template"; | ||
import { Info } from "./model/info"; | ||
import Generator from "./controller/generator"; | ||
class SocialGraphicsLibrary { | ||
/** | ||
* Social graphics library | ||
*/ | ||
export default class SocialGraphicsLibrary { | ||
//#region generator | ||
/** | ||
@@ -20,174 +17,12 @@ * Generators social graphics library | ||
* @param imgMode | ||
* @param [generateLink] | ||
*/ | ||
public static generator(teamName: string, playerName:string, mode: string, containerId: string, imgMode: string): void { | ||
let svgString: string; | ||
let width: number; | ||
let height: number; | ||
public static generator(teamName: string, playerName:string, mode: string, containerId: string, imgMode: string, generateLink?: boolean): void { | ||
if (teamName === "" ) { | ||
teamName = "Community"; | ||
} | ||
Generator.run(teamName, playerName, mode, containerId, imgMode, generateLink); | ||
if (playerName === "") { | ||
playerName = "Player"; | ||
} | ||
switch (mode) { | ||
case "youtube-title": | ||
svgString = Youtube_Template.template(teamName, playerName); | ||
width = Youtube_Template.width; | ||
height = Youtube_Template.height; | ||
break; | ||
case "twitch-title": | ||
svgString = Twitch_Template.template(teamName, playerName); | ||
width = Twitch_Template.width; | ||
height = Twitch_Template.height; | ||
break; | ||
case "twitter-title": | ||
svgString = Twitter_Template.template(teamName, playerName); | ||
width = Twitter_Template.width; | ||
height = Twitter_Template.height; | ||
break; | ||
case "elavate-title": | ||
svgString = Elevate_Template.template(teamName, playerName); | ||
width = Elevate_Template.width; | ||
height = Elevate_Template.height; | ||
break; | ||
case "logo": | ||
svgString = Logo_Template.template(playerName); | ||
width = Logo_Template.width; | ||
height = Logo_Template.height; | ||
break; | ||
default: | ||
svgString = False_Template.template(); | ||
width = False_Template.width; | ||
height = False_Template.height; | ||
break; | ||
} | ||
this.printImage(svgString, width, height, containerId, imgMode); | ||
} | ||
//#endregion | ||
//#region printImage | ||
/** | ||
* Prints image | ||
* @param svgString | ||
* @param width | ||
* @param height | ||
* @param containerId | ||
* @param imgMode | ||
* @returns image | ||
*/ | ||
static printImage(svgString: string, width: number, height: number, containerId: string, imgMode:string):void { | ||
let xml = svgString, | ||
parser = new DOMParser(), | ||
result: XMLDocument = parser.parseFromString(xml, 'text/xml'), | ||
inlineSVG = result.getElementsByTagName('svg')[0]; | ||
inlineSVG.setAttribute('width', width.toString()); | ||
inlineSVG.setAttribute('height', height.toString()); | ||
let data = "data:image/svg+xml;charset=utf-8;base64, " + btoa(new XMLSerializer().serializeToString(inlineSVG)), | ||
img = new Image(), | ||
img2 = new Image(), | ||
canvas = document.createElement('canvas'), | ||
imgAtr: string, | ||
downloadLink = document.createElement('a'), | ||
container = document.getElementById(containerId)! | ||
; | ||
switch (imgMode) { | ||
case 'svg': | ||
width = width / 4; | ||
height = height / 4; | ||
img.setAttribute('src', data); | ||
img.setAttribute('width', width.toString()); | ||
img.setAttribute('height', height.toString()); | ||
downloadLink.setAttribute('href', data); | ||
downloadLink.setAttribute('download', 'image.' + imgMode); | ||
downloadLink.innerHTML = 'Download Link'; | ||
container.innerHTML = ""; | ||
container.appendChild(img); | ||
container.appendChild(downloadLink); | ||
return; | ||
case 'png': | ||
imgAtr = 'image/png'; | ||
break; | ||
case 'jpeg': | ||
imgAtr = 'image/jpeg'; | ||
break; | ||
case 'webp': | ||
imgAtr = 'image/webp'; | ||
break; | ||
default: | ||
data = "data:image/svg+xml;charset=utf-8;base64, " + btoa(False_Template.template()); | ||
width = False_Template.width; | ||
height = False_Template.height; | ||
imgAtr = 'image/png'; | ||
break; | ||
} | ||
canvas.setAttribute('width', width.toString()); | ||
canvas.setAttribute('height', height.toString()); | ||
canvas.setAttribute('id', 'render-canvas' + containerId); | ||
canvas.setAttribute('display', 'none'); | ||
img.setAttribute('src', data); | ||
img.setAttribute('width', width.toString()); | ||
img.setAttribute('height', height.toString()); | ||
try { | ||
container.appendChild(canvas); | ||
} catch (error) { | ||
throw new Error("The Container " + containerId + " is not defined!"); | ||
} | ||
let renderCanvas = <HTMLCanvasElement>document.getElementById('render-canvas' + containerId)!; | ||
let ctx: CanvasRenderingContext2D | null; | ||
let imgDataUrl: string; | ||
img.onload = async function() { | ||
ctx = renderCanvas.getContext('2d'); | ||
ctx!.drawImage(img, 0, 0); | ||
imgDataUrl = renderCanvas.toDataURL(imgAtr, 1.0); | ||
width = width / 4; | ||
height = height / 4; | ||
img2.setAttribute('src', imgDataUrl); | ||
img2.setAttribute('width', width.toString()); | ||
img2.setAttribute('height', height.toString()); | ||
downloadLink.setAttribute('href', imgDataUrl); | ||
downloadLink.setAttribute('download', 'image.' + imgMode); | ||
downloadLink.innerHTML = 'Download Link'; | ||
container.innerHTML = ""; | ||
container.appendChild(img2); | ||
container.appendChild(downloadLink); | ||
}; | ||
} | ||
//#endregion | ||
//#region multiGenerator | ||
@@ -202,3 +37,3 @@ /** | ||
calls.forEach( async element => { | ||
SocialGraphicsLibrary.generator(teamName, playerName, element.mode, element.containerId, element.imgMode); | ||
SocialGraphicsLibrary.generator(teamName, playerName, element.mode, element.containerId, element.imgMode, element.generateLink); | ||
}); | ||
@@ -225,3 +60,1 @@ } | ||
} | ||
export default SocialGraphicsLibrary; |
@@ -18,2 +18,7 @@ export default interface Call { | ||
/** | ||
* generate link of call | ||
*/ | ||
generateLink: boolean; | ||
} |
@@ -7,3 +7,3 @@ export class Info { | ||
*/ | ||
private readonly _version: string = "1.3.3" | ||
private readonly _version: string = "1.4.0" | ||
@@ -10,0 +10,0 @@ /** |
@@ -0,0 +0,0 @@ //#region setup |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ const path = require('path'); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5421454
70
1422