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

toSVG there is no crossOrigin Anonymous #3589

Closed
gzai opened this issue Dec 27, 2016 · 13 comments
Closed

toSVG there is no crossOrigin Anonymous #3589

gzai opened this issue Dec 27, 2016 · 13 comments

Comments

@gzai
Copy link

gzai commented Dec 27, 2016

Hi,

I add image with crossOrigin: 'Anonymous'

					fabric.Image.fromURL( photo_src , function(img) {
					  	img.set({
						    top: 0,
						    left: 0,
							selectable: false,
							evented: false,
							zindex: 0,
						});
						img.lockMovementX = true;
						img.lockMovementY = true;
						master_canvas.centerObject(img);
					  	master_canvas.add(img);
					}, { crossOrigin: 'Anonymous' });

convert to JSON ( with JSON.stringify )
"crossOrigin":"Anonymous" exist in image array

convert to SVG ( with toSVG )
crossOrigin Anonymous not exist in svg tag

so how to add crossOrigin Anonymous in fabric.loadSVGFromString ?

@asturur
Copy link
Member

asturur commented Dec 27, 2016

is crossOrigin a property supported by image tag in svg?

@butch2k
Copy link

butch2k commented Dec 27, 2016 via email

@gzai
Copy link
Author

gzai commented Dec 27, 2016

So, we can't add crossOrigin Anonymous in fabric.loadSVGfromString ?

@asturur
Copy link
Member

asturur commented Dec 27, 2016

not sure. we should do it to enable people to load svgs on canvas since canvas is the target of our loading.
Still most of real svg will not have a crossOrigin property there since does not exist.
The change should be really small to be honest.

@AlexanderIstomin
Copy link

faced with that issue too.
i'm exported canvas with image from s3 (crossOrigin set to anonymous) to svg then tried to load svg on another canvas with loadSVGFromString then tried to export that canvas with toDataURL - got tained canvas error.

@AlexanderIstomin
Copy link

as a dirty hack - set image's sources to datauri before exporting canvas to svg

@niyotaa
Copy link

niyotaa commented Mar 20, 2017

hi! i have the same issue. is there a work around to this problem?

@magbicaleman
Copy link

magbicaleman commented Jun 28, 2017

I'm on v 1.7.11, and through chrome I get some random results. At times I have no problem loading and svg using fabric.loadSVGFromURL, other times I get No 'Access-Control-Allow-Origin' header is present on the requested resource. This is from AWS S3.

The cors rule on the bucket are as follows

<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>

I added the { crossOrigin: 'anonymous'} to my options so the it looks like.

fabric.loadSVGFromURL(uri, func, null, options);

I'm not really sure what the issue is, so it's very had to debug what's causing this, for me. Any help would be appreciated. Thank you.

Edit

I've noticed, if the images are cached they get the No 'Access-Control-Allow-Origin' header is present on the requested resource., once I disable cache and refresh the image will work, then when I re-enable the cache the image will work again.

@JomaKar
Copy link

JomaKar commented Sep 21, 2018

@KudMath
Copy link

KudMath commented Jan 28, 2019

@magbicaleman hey there. I'm having the exact same pb (2 years later ^^). did you find a solution?

@ahmadsyahrizar
Copy link

me is having the same issue too.

@ab-etemadi
Copy link

ab-etemadi commented Mar 6, 2024

Hi @asturur
I'm encountering the same issue. I tried adding a simple SVG along with { crossOrigin: 'anonymous' } to its options. Interestingly, fabric.Image.fromURL works fine with { crossOrigin: 'anonymous' }, but fabric.loadSVGFromURL is inconsistent - sometimes it works, sometimes it doesn't.

here is my code

fabric.loadSVGFromURL(
        svgURL,
        function (objects, options) {
          const obj = fabric.util.groupSVGElements(objects, options);
          const canvasWidth = canvas?.clipPath.width;
          const canvasHeight = canvas?.clipPath.height;
          const targetWidth = canvasWidth / 5;
          const targetHeight = canvasHeight / 5;
          const scale = Math.min(targetWidth / obj.width, targetHeight / obj.height);
          obj.scale(scale);
          obj.set({
            left: canvasWidth / 2,
            top: canvasHeight / 2,
            originX: 'center',
            originY: 'center',
            name: GRAPHIC_SVG_GROUP_NAME,
          });

          canvas.add(obj).renderAll();
          canvas.setActiveObject(obj);
        },
        null,
        { crossOrigin: 'anonymous' },
      );

@asturur
Copy link
Member

asturur commented Mar 11, 2024

Which is the URL that is failing the crossOrigin check? the svgURL or the url of some image inside the svg?

I see the { crossOrigin: 'anonymous' }, is name ad imageLoadingOptions so is not affecting loading the svg itself.
That could be a bug or a feature since the svg and the image contained could come from different domains and have different cors rules.

Do you mind sharing the svg?

(i agree an option for the svg itself should be there and that by default we should always set crossOrigin: 'anonymous' where possible )

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

No branches or pull requests

10 participants