Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 803281d

Browse files
committed
image-cors: Allow canvas images to respect the cross-origin attribute.
Currently, if a canvas image is hosted on a different server from which the canvas is served, a security error will be thrown by the browser. The change made will respect the cross-origin attribute if its set on the image.
1 parent 7ba34c9 commit 803281d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/shapes.coffee

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,23 @@ defineShape 'Image',
122122
@y = args.y or 0
123123
@scale = args.scale or 1
124124
@image = args.image or null
125+
@crossOrigin = (args.image and args.image.crossOrigin) or null
125126
getBoundingRect: ->
126127
{@x, @y, width: @image.width * @scale, height: @image.height * @scale}
127-
toJSON: -> {@x, @y, imageSrc: @image.src, imageObject: @image, @scale}
128+
toJSON: () ->
129+
toJSONData = {@x, @y, imageSrc: @image.src, imageObject: @image, @scale}
130+
if @crossOrigin
131+
toJSONData['crossOrigin'] = @crossOrigin
132+
return toJSONData
128133
fromJSON: (data) ->
129134
img = null
130135
if data.imageObject?.width
131136
img = data.imageObject
132137
else
133138
img = new Image()
134139
img.src = data.imageSrc
140+
if data.crossOrigin
141+
img.crossOrigin = data.crossOrigin
135142
createShape('Image', {x: data.x, y: data.y, image: img, scale: data.scale})
136143
move: ( moveInfo={} ) ->
137144
@x = @x - moveInfo.xDiff

0 commit comments

Comments
 (0)