-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing full gradients support for canvas background #4232
Comments
i think it has always ben possible, if there are difficulties, is time to fix it. As of now you have to enlive the gradient on your self i think. canvas.backgroundColor = myGradient.toLive() |
Please share your use case with a fiddle |
Not sure if i understand this right – but maybe you could give a hint on this fiddle? |
http://jsfiddle.net/tmchz9h0/9/ this is an example that show that is possible, just hard to do and uncomfrotable. |
thank you very much! it is workin with 2.0.0-beta3 |
One additional question to this approach – should this be working also (defining coords with %)?
Or did you worked on the gradient angle function (I know I was reading about this somewhere)... ? |
@asturur : why is it "hard to do and unconfortable" ? It looks like you can pass a pattern object, but also a gradient object to the .setBackgroundColor() function. http://jsfiddle.net/tmchz9h0/10/ But this information is not present in the documentation (it say : a string or a pattern object, it doesn't speak about a gradient object). Am i missing something ? |
well there is a difference between the object structure of a gradient when you want to set with the 'setGradient' method or when you want to create it with constructor. that is bad. Also the objects have a setGradient method and the canvas not. I would like to get a simpler gradient interface but that is more breaking changes and i do not want to do them now. |
@ncou yes the docs are probably outdated |
thank you, now it's more clear. as always my 2 cents opinion : adding a setGradient() function to the canvas object, could be an overkill, today setting a background with fabric.js is not really clear if you don't read carfully the doc => you can use "setBackgroundImage()" with an url, an image object, a rect object [who can include a pattern object], and you can use "setBackgroundColor()" with a rgb string, a pattern object, and a gradient object. |
i guess the safest is to deprecate both, keep them and add a generic setBackground that can handle both plus gradients and patterns. |
this could be a really clean solution, having one entry point to set a background is more easy. |
you just call it twice. needs just a better doc and explanation. |
@asturur while we are on this: there where some plans to introduce an angle for gradients instead of x1,x2,y1,y2 –. Are they abbandoned now? |
no they are not. the plan is making gradients simpler in some way, but mantain svg compatibility. svg heavily relies on that coords and gradient transform, while who creates gradients by code could easily use something easier. like percentages and angles. |
From @ncou Thank you. Here is my fiddle : I even tried something like : grad.gradientTransform = fabric.parseTransformAttribute([1,0,0,2,1,1]); after creating my Gradient object. but without success. |
I have tried to change the linear gradient to radial but it did not work. |
you need to use the correct parameters (r1 and r2 are missing). |
how can i set the canvas background with color picker? |
@Alwenjohn we can t really help with application problems here, please open a stackoverflow question and link it here eventually |
I tried: However when I do json stringify from canvas.toObject() to store the canvas in the database for later upload I get "{"version":"2.7.0","objects":[],"background":{}}" because the value of 'background' property is an 'CanvasGradient' |
i think gradients are supported if i'm not wrong. |
Yes Andrea, you are right.
I have tried to assign a gradient fabric object, as you suggested, and it worked.
Thank you once more.
…________________________________
De: Andrea Bogazzi <notifications@github.com>
Enviado: 27 de abril de 2019 10:20
Para: fabricjs/fabric.js
Cc: Ricardo Carvalho; Comment
Assunto: Re: [fabricjs/fabric.js] Missing full gradients support for canvas background (#4232)
i think gradients are supported if i'm not wrong.
Just assign a gradient fabric object?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#4232 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AJUVR7SFFFOSZZY5HQGDZC3PSQLEDANCNFSM4DXVF4IA>.
|
However I have found that when zooming the canvas or using toDataURL with multiplier (https://jsfiddle.net/8d30cfj1/1/) the gradient doesn't scale. |
oh that is weird. it should scale. i ll check. |
there is a flag in fabric for background zoom. It was a contentested option, some people thought it should scale other though it should not. Did you try it? |
Doesn't work with it either, is a bug. |
Thank you for your time on this.
I'm not working today but tomorrow i will look at this in more detail and i will give you some feedback as soon as possible.
…________________________________
From: Andrea Bogazzi <notifications@github.com>
Sent: Wednesday, May 1, 2019 11:21:15 AM
To: fabricjs/fabric.js
Cc: Ricardo Carvalho; Comment
Subject: Re: [fabricjs/fabric.js] Missing full gradients support for canvas background (#4232)
http://fabricjs.com/docs/fabric.StaticCanvas.html#backgroundVpt
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#4232 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AJUVR7RRSY4HRQBE6FMQF6TPTFVJXANCNFSM4DXVF4IA>.
|
anyone who wants to solve this problem can set a gradient as a background by setting css background as a gradient using javascript. const clrs = () => { const handleBgGradientOfPreviwer = ()=>{
} |
Now I have try this one and is working fine. var grad = new fabric.Gradient({ you can also study it from here |
Is it possible now with 2.0.0 to set a gradient for the canvas object?
The text was updated successfully, but these errors were encountered: