Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize/scale entire canvas with all objects in fabricjs without loss of quality

Is there way how to scale/resize entire canvas made in fabric.js ? I have <canvas className="canvas" ref="canvas" width="895" height="560"></canvas> then const canvas = new fabric.Canvas(this.refs.canvas),can i change width and height of canvas element and all objects inside ??

like image 823
Lukáš Unzeitig Avatar asked Sep 19 '16 09:09

Lukáš Unzeitig


1 Answers

This question has been answered many times. The best answer on my opinion provided by one of fabricjs contributors Andrea Bogazzi here: https://stackoverflow.com/a/35019311/3710047

Basically, you can use fabricjs canvas methods:

canvas.setZoom(val);
canvas.setWidth(originalWidth * canvas.getZoom());
canvas.setHeight(originalHeight * canvas.getZoom());
like image 173
Pavlo Kozlov Avatar answered Nov 15 '22 04:11

Pavlo Kozlov