Hi Velo team,
I would like to combine two images and download the processed image, I was doing this with canvas but I don’t know how to finish this with velo, is this possible? Thanks.
Here is the code I was using,
///////////
compositeImg = () => {
const canvas = document . createElement ( ‘canvas’ )
const ctx = canvas . getContext ( ‘2d’ )
canvas . width = 800
canvas . height = 600
const url = this . changeCanvasToPic ()
const img1 = new Image ()
const img2 = new Image ()
img1 . src = url
img2 . src = ‘images/bg/’ + this . state . codeDate + ‘.jpg’
Image editing can be a complex sport. Generally, you have two methods, either using the browser canvas, like in your example above, or using WebGL. Canvas is part of the HTML5 standard so it works in browsers with regular JS & HTML, but direct access to DOM elements isn’t available out of the box in Velo - e.g.
const canvas = document.createElement('canvas');
won’t work in your page code.
You can approach it a few ways, but any method for image editing will require research.
Use Custom Elements to create a component with DOM access, which will get your code working with some modification
Use an npm library like node-canvas to simulate access to the canvas in your Wix backend code
Look for another editing library that makes use of buffers to do image editing, which is just the raw image data.
Not leaving you high and dry, here are some resources to get started.
Were you able to get this to work? I am able to use jimp for the same thing but could never get the jimp npm package to install in velo after I got it installed in the npm packages section.