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

feat: Add method toBlob #10399

Merged
merged 4 commits into from
Jan 26, 2025
Merged

feat: Add method toBlob #10399

merged 4 commits into from
Jan 26, 2025

Conversation

zhe-he
Copy link
Contributor

@zhe-he zhe-he commented Jan 13, 2025

Before this method existed, I needed to do it this way.

const base64 = object.toDataURL();
const url = URL.createObjectURL(dataurl2blob(base64));

After this method was added, I only need to do it this way.

const blob = await object.toBlob();
const url = URL.createObjectURL(blob);

#3283

Copy link

codesandbox bot commented Jan 13, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@asturur
Copy link
Member

asturur commented Jan 13, 2025

This is fine.
I need to think a second of the api options but is ok to add this

@zhe-he
Copy link
Contributor Author

zhe-he commented Jan 14, 2025

The export type might need to add support for WebP.

https://github.com/fabricjs/fabric.js/blob/master/src/typedefs.ts#L46
export type ImageFormat = 'jpeg' | 'png'; ->
export type ImageFormat = 'jpeg' | 'png' | 'webp';

@asturur
Copy link
Member

asturur commented Jan 14, 2025

Yes webP support can be added, is well supported now

@asturur
Copy link
Member

asturur commented Jan 26, 2025

The export type might need to add support for WebP.

https://github.com/fabricjs/fabric.js/blob/master/src/typedefs.ts#L46 export type ImageFormat = 'jpeg' | 'png'; -> export type ImageFormat = 'jpeg' | 'png' | 'webp';

We may try this in another PR, We need to verify if node-canvas does webp or we need to have different type for node/browser

@asturur asturur merged commit a88ad1a into fabricjs:master Jan 26, 2025
20 of 22 checks passed
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