Skip to content

Commit e3423c3

Browse files
committed
fix: wrong image orientation on IOS device
1 parent be4fbab commit e3423c3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ export function drawImageInCanvas(img) {
177177
return canvas;
178178
}
179179

180+
/**
181+
* Detect IOS device
182+
* see: https://stackoverflow.com/a/9039885
183+
* @returns {boolean} isIOS device
184+
*/
185+
function isIOS() {
186+
return [
187+
'iPad Simulator',
188+
'iPhone Simulator',
189+
'iPod Simulator',
190+
'iPad',
191+
'iPhone',
192+
'iPod',
193+
].includes(navigator.platform)
194+
// iPad on iOS 13 detection
195+
|| (navigator.userAgent.includes('Mac') && 'ontouchend' in document);
196+
}
197+
180198
/**
181199
* drawFileInCanvas
182200
*
@@ -186,6 +204,9 @@ export function drawImageInCanvas(img) {
186204
export async function drawFileInCanvas(file) {
187205
let img;
188206
try {
207+
if (isIOS()) {
208+
throw new Error('Skip createImageBitmap on IOS device'); // see https://github.com/Donaldcwl/browser-image-compression/issues/118
209+
}
189210
img = await createImageBitmap(file);
190211
} catch (e) {
191212
const dataUrl = await getDataUrlFromFile(file);

0 commit comments

Comments
 (0)