File tree 2 files changed +5
-5
lines changed
2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { copyToClipboard } from './clipboard.js' ;
2
2
import { showTemporaryTooltip } from '../modules/tippy.js' ;
3
- import { imageBlobToPng } from '../utils.js' ;
3
+ import { convertImage } from '../utils.js' ;
4
4
const { i18n} = window . config ;
5
5
6
6
async function doCopy ( content , btn ) {
@@ -47,7 +47,7 @@ export function initCopyContent() {
47
47
} catch {
48
48
if ( isImage ) { // convert image to png as last-resort as some browser only support png copy
49
49
try {
50
- await doCopy ( await imageBlobToPng ( content ) , btn ) ;
50
+ await doCopy ( await convertImage ( content , 'image/png' ) , btn ) ;
51
51
} catch {
52
52
showTemporaryTooltip ( btn , i18n . copy_error ) ;
53
53
}
Original file line number Diff line number Diff line change @@ -104,8 +104,8 @@ export function blobToDataURI(blob) {
104
104
} ) ;
105
105
}
106
106
107
- // convert any image Blob to a png Blob
108
- export function imageBlobToPng ( blob ) {
107
+ // convert image Blob to another mime-type format.
108
+ export function convertImage ( blob , mime ) {
109
109
return new Promise ( async ( resolve , reject ) => {
110
110
try {
111
111
const img = new Image ( ) ;
@@ -118,7 +118,7 @@ export function imageBlobToPng(blob) {
118
118
canvas . toBlob ( ( blob ) => {
119
119
if ( ! ( blob instanceof Blob ) ) return reject ( new Error ( 'imageBlobToPng failed' ) ) ;
120
120
resolve ( blob ) ;
121
- } , 'image/png' ) ;
121
+ } , mime ) ;
122
122
} ) ;
123
123
img . addEventListener ( 'error' , ( ) => {
124
124
reject ( new Error ( 'imageBlobToPng failed' ) ) ;
You can’t perform that action at this time.
0 commit comments