I am using Fabric JS to allow the user to have an interactive experience on my React app. Is it possible to apply a frame around a Fabric JS that is taken from an image? For instance, if the canvas is 400x400 px I can resize an image of a frame that is transparent in the middle to 410x410px and apply it on top of the canvas for the user to see? I have attached two images for reference.
const zoomIn = useCallback(() => {
// Get original height of canvas
const canvasDimensions = getInitialCanvasSize()
let zoom = HTML5Canvas.getZoom()
zoom += 0.2
if (zoom >= 2) zoom = 2
HTML5Canvas.setZoom(zoom)
HTML5Canvas.setWidth(canvasDimensions.width * HTML5Canvas.getZoom());
HTML5Canvas.setHeight(canvasDimensions.height * HTML5Canvas.getZoom());
}, [HTML5Canvas])
There is no option for canvas's border in fabricjs canvas docs
But you can still achieve this easily using following steps.
OR
Behind current canvas put this second canvas and control its width and image.
I don't recommend this one, as this will make it more complex to implement.
Now you get what your canvas looks like. You have width
of border, image/color
of border.
Steps:
410px
if canvas's width 400px
with border of 5px
.Directly follow above 2nd step
Export main canvas as image and put it over 2nd Canvas. And now you can export this as final image. For 2nd step check my answer on this stack