Skip to content
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

issue with setSrc for crossorigin images #6397

Closed
dkirchhof opened this issue Jun 19, 2020 · 4 comments · Fixed by #6414
Closed

issue with setSrc for crossorigin images #6397

dkirchhof opened this issue Jun 19, 2020 · 4 comments · Fixed by #6414
Labels

Comments

@dkirchhof
Copy link

Hello,
i have some trouble with changing the src of an image.

As you can see in the fiddle, i want to change the src of an image via the setSrc function.
After calling canvas.renderAll in the setSrc-callback nothing happens.
The image will be loaded twice (you can see it in the network panel of the chrome devtools). So the callback will be triggered after the first load, but the image will be rendered correctly after the image is loaded the second time. Also all image options like width and height will be reseted.

This problem occurs only if i set the crossOrigin option (to anonymous).

http://jsfiddle.net/v6e0hd5o/1/

Tested with fabricjs v. 4.0.0-beta.12 on chrome 83.

@melchiar
Copy link
Member

Don't forget to set crossOrigin: "anonymous" when calling setSrc() as well

http://jsfiddle.net/melchiar/jrnwu2tL/

@asturur
Copy link
Member

asturur commented Jun 19, 2020

There is some code in fabricJS that chrome 83 made broken.
The broken part makes sense, since fabricJS during setSRC will try to set the crossOrigin of the element to the one of the fabric.Image ( from the previous element ).
This is wrong, because the new element from setSrc will be loaded with the crossOrigin specified in the options and if different from the previous one will be changed again, invalidating the image completely.

It is effectively a bug, i m just not sure how should be fixed.

optionA:
you do setSrc and the fabric.Object gets the new crossOrigin specified in setSrc

option B:
you do setSrc and the image is loaded with the current crossOrigin

I really do not know what makes more sense.

@asturur asturur added the bug label Jun 19, 2020
@melchiar
Copy link
Member

Just my 2 cents... it seems to me that optionA is the most consistent. It makes sense that crossOrigin would be specified every time a new image is loaded, whether you're creating a new image object or changing the source of an existing image object. After all, the new url when calling setSrc() might be a local file and not need the property, yes?

@asturur
Copy link
Member

asturur commented Jun 20, 2020

Yes. Also to me asking to specify crossOrigin every load just bring attention to the fact that today you have to deal with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants