param img param quality param fileType export default function changeImageSize ( img , quality , fileType ) { const canvas = document . createElement ( 'canvas' ) ; const ctx = canvas . getContext ( '2d' ) ; if ( ! ctx ) { console . error ( '请使用高版本浏览器，该版本浏览器不支持生成缩略图' ) ; return '' ; } const { width , height } = img ; canvas . width = width ; canvas . height = height ; ctx . fillStyle = '#fff' ; ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ; ctx . drawImage ( img , 0 , 0 , width , height ) ; if ( quality && ! ( quality > 0 && quality <= 1 ) ) { console . error ( '请输入有效的压缩比例, 没有将默认使用 0.92' ) ; } return canvas . toDataURL ( fileType , quality ) ; }