- Installation
- NPM Module Required
- Canvas Dependencies Required
- Documentation
- Image Format
- Align Format
- Mod List
- Download the release from here
- Extract files and folder to your bot's directory actions folder
- Get all canvas dependencies from here
- Basic Section
- canvas
- glob
- node-fetch
- chalk
- chart.js
- GIF Section
- pixel-gif
- Font Section
- opentype.js
- Image Recognize Section
- tesseract.js
- Extension
- unzipper
- chalk
- node-fetch
- gifski https://github.com/ImageOptim/gifski/releases
- dwebp https://developers.google.com/speed/webp/download
- palette.js https://github.com/google/palette.js/blob/master/palette.js
- Image Options
- Crop Image
- Edit Border
- Filter Image
- Generate Progress Bar
- Image Recognize
- Generate Graph
DBM.Actions.Canvas.createImage(url, options) => Promise[Image]Image type support png, jpg, gif webp(still image) and of course base64 image, it can be web image or local
- [String]
urlsource image from local or url - [Object]
options- [Integer]
delayDelay for gif if image is animated - [Integer]
loopLoop for gif if image is animated - [Integer]
overlapRedraw gif by previous frame, value should be0-2,0is Auto,1is True and2is False
- [Integer]
this.Canvas.createImage('https://www.website.com/image_**.png', { delay: 100, loop: 0, overlap: 0 }).then((image) => {
})
// or with async/await:
const image = await this.Canvas.createImage('.\resources\img.gif')
}
DBM.Actions.Canvas.drawImage(img1, img2, options) => [Image]Draw img2 on top of img1 with ton of options
- [Image]
img1img2image generate from canvas - [Object]
options- [Integer]
xPosition x of left of img1 - [Integer]
yPosition y of top of img1 - [Integer]
opacityor name as transparent, which control img2 when it draw, not effect on img1, effective value range is from 0 to 100 - [Integer | String]
effectdraw effect for img2, exist value is'mask'or1, leave it empty for draw overlay - [Boolean]
expandit will expand img1 size if img2 is large than img1
- [Integer]
this.Canvas.drawImage(img1 ,img2, { x: 5, y: 5, opacity: 100, expand: false })DBM.Actions.Canvas.drawText(img, text, options) => [Image]Draw text on above image with support font TrueType and OpenType
- [Image]
imgimage generate from canvas - [String]
textText that will write on the image - [Object]
options- [Integer]
xPosition x of img - [Integer]
yPosition y of img - [String]
colorColor of the text, example'#000000'or'000000' - [Integer]
sizeSize of the font - [Integer | String]
alignAlignment for the text, value should be0to8or'TL','TC','TR','ML','BL'... - [String]
typeFill type, exist value is'fill'or'stroke' - [Integer]
maxWidthWidth from start of the text to end of it, if set to80the width of text will below or equal to the maxWidth - [String]
fontThe path of the font file - [Boolean]
antialiasanti alias for the text - [Boolean]
rotateRotate for the text, effective range should be0-359 - [Boolean | Integer]
autoWrapAuto wrap for text if text's width is bigger than max width, exist value is1ortrue, leave it blank to disable it
- [Integer]
this.Canvas.drawText(img, 'Hello World', { x: 5, y: 5, color: '#000000', size: 20, align: 'TL', type: 'fill', maxWidth: 40, font: 'fonts\arial.ttf', rotate: 180, antialias: true})DBM.Actions.Canvas.controlImage(img, options) => [Image]Control image function includes resize or scale, flip and rotate
- [Image]
imgimage generate from canvas - [Object]
options- [Object]
resizeOptions for resize- [Integer]
widthwidth for the image - [Integer]
heightheight for the image - [Boolean]
aspectRatioSettrueto keep the image look same after scale
- [Integer]
- [Integer | String]
flipFlip image with 3 possible way,0-3orhorizontal,verticalanddiagonal - [Integer]
rotateRotate the image, the width and the height will auto change to size after rotate - [Integer | String]
resamplingResize image with resample method, exist value is0to2or'good'|'bilinear','best'|'bicubic','fast'|'nearest' - [Integer | String]
opacityControl image opacity with value50%for global opacity or use number between1to255for each pixel opacity
- [Object]
this.Canvas.controlImage(img, { resize: { width: 500, aspectRatio: true }, rotate: 90 })DBM.Actions.Canvas.cropImage(img, options)Crop image to smaller or bigger
- [Image]
imgimage generate from canvas - [Object]
options- [Integer | String]
widthWidth of the new image size, example50or'125%' - [Integer | String]
heightHeight of the new image size, example25or'75%' - [Integer | String]
alignAlignment for the cropping position, value should be0to9or'TL','TC','TR','ML','BL'... - [Integer | String]
align2Alignment for the cropping position, ifalignvalue is9, then this parameter is required, value should be0to8or'TL','TC','TR','ML','BL'... - [Integer]
xPosition x for the alignment - [Integer]
yPosition y for the alignment
- [Integer | String]
this.Canvas.cropImage(img, { width: '50%', height: '50%', align: 9, align2: 4, x: 15, y: 25 })DBM.Actions.Canvas.editBorder(img, type, radius) => [Image]Edit image border to get a better look, bounder either is circle or round
- [Image]
imgimage generate from canvas - [Integer | String]
typeBorder type, circle type value is'circle'|1and round type is'corner'or0 - [Integer]
radiusIf border type iscorner, this parameter is required
this.Canvas.editBorder(img , 'corner', 50)DBM.Actions.Canvas.Filter(img, type, value) => [Image]Add some filter to the image
- [Image]
imgimage generate from canvas - [Integer | String]
typeType for the filter, value should be0-8or'blur','huerotate', 'brightness', 'contrast', 'grayscale', 'invert', 'opacity', 'saturate' and 'sepia' - [Integer]
valueTotal percent of the filter will add to image, effective range should be0-100
this.Canvas.Filter(img, 'huerotate', 50)DBM.Actions.Canvas.generateProgress(options, lineCap, lineWidth, percent, color) => [Image]Generate progress bar from options and other info
- [Object]
options- [Integer | String]
typeType for progress bar, circle type value is'circle'|1and basic type is'basic','normalor0 - [Integer]
widthWidth of progress bar if type isbasic, else is radius forcircle - [Integer]
heightHeight of progress bar if type isbasic, else if dimention for total width and height of the image forcircle
- [Integer | String]
- [Integer | String]
lineCapLine cap for basic style is0or'square'and for round type is1or'round' - [Integer]
lineWidthLine width is stroke width - [Integer]
percentPercent available from0to100 - [String]
colorColor of the progress bar, example'#000000'or'000000'
this.Canvas.generateProgress({ type: 'circle', width: 100, height: 240 }, 'round', 20, 50, '#000000')DBM.Actions.Canvas.Recognize(img, options) => Promise[String]Text recognize from tesseract.js
- [Image]
imgimage generate from canvas - [Object]
options- [Integer]
leftLeft of the rectangle that scan - [Integer]
topTop of the rectangle that scan - [Integer]
widthWidth of the rectangle - [Integer]
heightHeight of the rectangle - [String]
langTarget language, it can be'eng+chi_tra'for English and Traditional Chinese - [Integer]
offsetOffset for the rectangle if max is more than 1 - [String]
offsetTypeOffset type for the offset value, value should be'percentage','percent','pixel'and'px' - [Integer]
maxMax try for each image, the more try doesnt mean will have better result - [Boolean]
forceMaxIf found a perfect result andforceMaxis false, it will stop the work
- [Integer]
this.Canvas.Recognize(img, { left: 0, top: 0, width: 200, height: 200, lang: 'eng', offset: 5, offsetType: 'pixel', max: 3, forceMax: false, acceptRange: 80, forceAccept: true, debug: false })DBM.Actions.Canvas.generateChart(type, width, height, title, labels, data, sort, bgColor, bgColorAlpha, borderWidth, borderColor, borderColorAlpha, options) => [Image]Generate many type of graph with chart.js
- [String]
typeType of graph, value should be 'line','bar', 'horizontalBar', 'radar', 'pie', 'doughnut' and 'polarArea' - [Integer]
widthWidth for the image - [Integer]
heightHeight for the image - [String]
titleTitle of the graph - [Array]
labelsAn array of all labels, example['bar1', 'bar2', 'bar3'] - [Array]
dataAn array of all data, example[10,20,30] - [Integer]
sortSort for result, value should be0,1or2 - [String]
bgColorColor of the object, example'222831,00adb5,eeeeee' - [Integer]
bgColorAlphaControl object's opacity with value between0to1 - [Integer]
borderWidthBorder's width of the object - [String]
borderColorBorder's color of the object, example'222831,00adb5,eeeeee' - [Integer]
borderColorAlphaControl border object's opacity with value between0to1 - [Object]
optionPlease check at Chart.js
this.Canvas.generateChart('bar', 800, 400, 'Score', ['Team Red', 'Team Blue', 'Team Green'], [33, 66, 99], 2, , 0.1, 1, , 1, {})DBM.Actions.Canvas.toBuffer(img) => [Buffer]Convert gif/still image to buffer
- [Image]
imgimage generate from canvas
const buffer = DBM.Actions.Canvas.toBuffer(img)DBM.Actions.Canvas.Export(img, destination)Save gif/still image to local directly
- [Image]
imgimage generate from canvas - [String]
destinationlocal path for image
const buffer = DBM.Actions.Canvas.Export(img, 'resources\\export.png')DBM.Actions.Canvas.toAttachment(img ,name) => [Discord Attachment]Convert image to discord attachment
- [Image]
imgimage generate from canvas - [String]
namename for the attachment, example'image.png'or'image'
this.Canvas.toAttachment(img, 'image')DBM.Actions.Canvas.bridge(img, type) => Promise[image]Function convert Canvas image to Jimp image or Jimp image to Canvas image
- [Image]
imgtarget image - [Integer]
typevalue for (C->J) is0and (J->C) is blank or any number that value is not0
this.Canvas.bridge(img, 1).then((image) => {
})
// or with async/await:
const image = await this.Canvas.bridge(img, 0)
}- Still Image
- [Object] Type
- [Boolean]
animatedIs animated, default value isfalse - [Array]
extensionspossible of image extension - [Image]
imageimage with base64 format, it should start withdata:image/png;base64
- [Boolean]
- Mainly format from
png,jpg,webp, orbase64
- [Object] Type
- Animated/GIF Image
- [Object] Type
- [Integer]
widthWidth of the gif - [Integer]
heightHeight of the gif - [Boolean]
animatedIs animated, default value istrue - [Array]
extensionspossible of image extension - [Array]
imagesArray images of the gif- [Image]
imgimage generate from canvas
- [Image]
- [Integer]
delayDelay for the each frame - [Integer]
loopCountLoop for the gif, if it is0, mean infinity loop - [Integer]
totalFramesTotal frames in this gif image
- [Integer]
- Mainly format from
gifor multiple local png image
- [Object] Type
- [Integer] Type 1
alignvalid from0to8
- [String] Type 2
alignvalid values'TL','TC','TR','ML','MC','MR','BL','BC'and'BR'
- Canvas Create Image
- Canvas Create Background
- Canvas Crop Image
- Canvas Draw Image on Image
- Canvas Draw Text on Image
- Canvas Edit Image Border
- Canvas Generate Progress Bar
- Canvas Gif to Png
- Canvas Image Bridge
- Canvas Image Filter
- Canvas Image Options
- Canvas Image Recognize
- Canvas Save Image
- Canvas Send Image
- Canvas Set Gif Option
- Store Canvas Info
- Canvas Generate Graph
- About Canvas Mod