Replies: 3 comments 10 replies
-
@asturur Hopefully you can give me some hints :) |
Beta Was this translation helpful? Give feedback.
7 replies
-
Thanks for the suggestion. Sadly didn't really do anything to the rendering
time. Really not sure what's going on.
…On Tue, Jun 1, 2021 at 2:34 PM Andrea Bogazzi ***@***.***> wrote:
the only change worth trying is to swap this line
https://gist.github.com/mfauveau/3c8ec7b8e0e23d82cedbceb8533fb39a#file-cli-js-L40
with something like:
process.stdout.write(canvas.lowerCanvasEl.toDataURL(args.f))
considering that to the native toDataURL you have to pass image/png and
not png only.
This is the only meaning full difference i can think of.
Doing what you are doing now ( that is the correct way to use fabricJS
since toDataUrl has many options that make everything simpler if you start
the export on a new element ) a new canvas with the same size gets created,
it gets repainted and then exported.
So basically you are doing everything twice exactly. This could justify a
multiplication of 2x on the timing, but not a 3x.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7081 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAH4U5HTE7RCKBDU764LNLTQUR2RANCNFSM45TAJUPA>
.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
my test: const fabric = require("fabric").fabric
const fs = require('fs')
const {
performance,
} = require('perf_hooks');
const data = '{"version":"4.5.0","objects":[{"type":"image","version":"4.5.0","originX":"left","originY":"top","left":112.13,"top":75,"width":101,"height":200,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":0.75,"scaleY":0.75,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"cropX":0,"cropY":0,"src":"https://pisces.bbystatic.com/image2/BestBuy_US/images/products/5801/5801400_bd.jpg;maxHeight=200;maxWidth=200","crossOrigin":null,"filters":[],"isDeletable":false},{"type":"textbox","version":"4.5.0","originX":"center","originY":"center","left":150,"top":270,"width":300,"height":20.34,"fill":"#000000","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"text":"Apple - iPhone XR 64 GB - White","fontSize":18,"fontWeight":"normal","fontFamily":"Lato","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"center","textBackgroundColor":"","charSpacing":0,"path":null,"direction":"ltr","minWidth":20,"splitByGrapheme":false,"styles":{}}],"background":"#ffffff"}';
const height = 400;
const width = 400;
if (data) {
const timeA = performance.now();
const canvas = new fabric.StaticCanvas(null, { width: width, height: height });
canvas.loadFromJSON(data, function() {
var pngData = canvas.toDataURL({
format: 'png'
});
const timeB = performance.now();
process.stdout.write((timeB - timeA).toString());
})
} result times
swapping to the other approach: const fabric = require("fabric").fabric
const fs = require('fs')
const {
performance,
} = require('perf_hooks');
const data = '{"version":"4.5.0","objects":[{"type":"image","version":"4.5.0","originX":"left","originY":"top","left":112.13,"top":75,"width":101,"height":200,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":0.75,"scaleY":0.75,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"cropX":0,"cropY":0,"src":"https://pisces.bbystatic.com/image2/BestBuy_US/images/products/5801/5801400_bd.jpg;maxHeight=200;maxWidth=200","crossOrigin":null,"filters":[],"isDeletable":false},{"type":"textbox","version":"4.5.0","originX":"center","originY":"center","left":150,"top":270,"width":300,"height":20.34,"fill":"#000000","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"text":"Apple - iPhone XR 64 GB - White","fontSize":18,"fontWeight":"normal","fontFamily":"Lato","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"center","textBackgroundColor":"","charSpacing":0,"path":null,"direction":"ltr","minWidth":20,"splitByGrapheme":false,"styles":{}}],"background":"#ffffff"}';
const height = 400;
const width = 400;
if (data) {
const timeA = performance.now();
const canvas = new fabric.StaticCanvas(null, { width: width, height: height });
canvas.loadFromJSON(data, function() {
var pngData = canvas.lowerCanvasEl.toDataURL('image/png');
const timeB = performance.now();
process.stdout.write((timeB - timeA).toString());
});
} results
Difference is minimal, and that is weird since we are basically saving a render. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys,
Can anyone think of a reason why Fabric.js would take x2/x3 more time vs Konva.js to generate a dataUrl (or SVG) from JSON in a Node CLI script?
The same canvas will generate in ~700ms with Konva and ~2s with Fabric.js.
It's my understanding that both use node-canvas for rendering but maybe I'm missing something that's making Fabric slower?
I've already built my app around Fabric so I'm really hoping we can find a solution :)
Fabric code extract:
Konva code extract:
Beta Was this translation helpful? Give feedback.
All reactions