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

[bug] specify the maximum size of Canvas supported by each browser #112

Merged
merged 3 commits into from
Aug 10, 2021

Conversation

raccoonback
Copy link
Contributor

@raccoonback raccoonback commented Aug 5, 2021

Purpose

Each browser limits the maximum size of a Canvas object.
So, need to resize the image to less than the maximum size that each browser restricts.
(However, the proportion/ratio of the image remains.)

you can test it using image

Cause

If the maximum size of Canvas supported by a browser that does not support OfflineCanvas is exceeded, canvas.toDataURL() returns "data:,".

} else { // checked on Win Edge 44, Win IE 11, Win Firefox 76, MacOS Firefox 77, MacOS Safari 13.1
const dataUrl = canvas.toDataURL(fileType, quality)
file = await getFilefromDataUrl(dataUrl, fileName, fileLastModified)
}

If the height or width of the canvas is 0 or larger than the maximum canvas size, the string "data:," is returned.

Therefore, the error i[0].match(/:(.*?);/)[1] in getFilefromDataUrl().

const mime = arr[0].match(/:(.*?);/)[1]
const bstr = globalThis.atob(arr[1])
let n = bstr.length
const u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}

So when we create an Image object,
if we set width, height within the maximum size of Canvas supported by the browser,
we can prevent not only Black image, but also i[0].match(/:(.*?) ;/)[1] errors.
( the proportion/ratio of the image remains.)

How to

  • resizes the maximum size of canvas supported by the browser when it is first created with Image Objects.
  • add a bowser dependency to obtain each browser name.

Releated issue

@raccoonback raccoonback force-pushed the specify-max-canvas-size branch from 1f6afac to 06376e5 Compare August 5, 2021 14:42
@raccoonback raccoonback changed the title Specify the maximum size of Canvas supported by each browser [bug] specify the maximum size of Canvas supported by each browser Aug 5, 2021
@Donaldcwl Donaldcwl merged commit 5be3de6 into Donaldcwl:master Aug 10, 2021
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

Successfully merging this pull request may close these issues.

2 participants