Skip to content

Instantly share code, notes, and snippets.

@ewanharris
Created November 24, 2020 12:36
Show Gist options
  • Save ewanharris/cd28e201f51ebb652315d8d2c999d229 to your computer and use it in GitHub Desktop.
Save ewanharris/cd28e201f51ebb652315d8d2c999d229 to your computer and use it in GitHub Desktop.
Image creation from LivePhoto
const win = Ti.UI.createWindow({ layout: 'vertical' });
const singleBtn = Ti.UI.createButton({ title: 'Select single', top: 50 });
singleBtn.addEventListener('click', () => {
selectImage(false);
});
win.add(singleBtn);
const multiBtn = Ti.UI.createButton({ title: 'Select multiple' });
multiBtn.addEventListener('click', () => {
selectImage(true);
});
win.add(multiBtn);
win.open();
function selectImage(allowMultiple) {
Ti.Media.requestPhotoGalleryPermissions((e) => {
if (!e.success) {
console.error('failed to get permissions');
console.error(e);
return;
}
Titanium.Media.openPhotoGallery({
success: function(e) {
if (e.livePhotos) {
console.time('livephoto');
const livePhoto = e.livePhotos[0].livePhoto;
for (let i = 0; i < 10; i++) {
console.timeLog('livephoto', `loop ${i} start`);
const lpView = Ti.UI.iOS.createLivePhotoView({
livePhoto
});
lpView.toImage();
console.timeLog('livephoto', `loop ${i} end`);
}
console.timeEnd('livephoto');
}
},
error: function(e) {
console.error('errored on openPhotoGallery')
console.error(e);
},
mediaTypes: [ Ti.Media.MEDIA_TYPE_PHOTO ],
allowMultiple
});
});
}
  • Takes a LivePhoto and will create a an LivePhotoView and calls toImage on it ten times, measuring the overall time taken and the time taken for each loop
  • On average for 10 loops it will taken around 9-10 seconds with each loop taking around 900-1000ms. It's possible this could be reduced by parallelising the conversion
  • While the images are being processed the UI is blocked, I'm uncertain whether it's possible to perform this an not block the UI

Logs

Loop 1

INFO]  livephoto: 1ms loop 0 start
[INFO]  livephoto: 904ms loop 0 end
[INFO]  livephoto: 904ms loop 1 start
[INFO]  livephoto: 1722ms loop 1 end
[INFO]  livephoto: 1722ms loop 2 start
[INFO]  livephoto: 2570ms loop 2 end
[INFO]  livephoto: 2570ms loop 3 start
[INFO]  livephoto: 3413ms loop 3 end
[INFO]  livephoto: 3413ms loop 4 start
[INFO]  livephoto: 4333ms loop 4 end
[INFO]  livephoto: 4333ms loop 5 start
[INFO]  livephoto: 5447ms loop 5 end
[INFO]  livephoto: 5447ms loop 6 start
[INFO]  livephoto: 6420ms loop 6 end
[INFO]  livephoto: 6420ms loop 7 start
[INFO]  livephoto: 7534ms loop 7 end
[INFO]  livephoto: 7534ms loop 8 start
[INFO]  livephoto: 8665ms loop 8 end
[INFO]  livephoto: 8665ms loop 9 start
[INFO]  livephoto: 9849ms loop 9 end
[INFO]  livephoto: 9850ms

Loop 2

INFO]  livephoto: 0ms loop 0 start
[INFO]  livephoto: 932ms loop 0 end
[INFO]  livephoto: 932ms loop 1 start
[INFO]  livephoto: 1789ms loop 1 end
[INFO]  livephoto: 1789ms loop 2 start
[INFO]  livephoto: 2747ms loop 2 end
[INFO]  livephoto: 2747ms loop 3 start
[INFO]  livephoto: 3794ms loop 3 end
[INFO]  livephoto: 3794ms loop 4 start
[INFO]  livephoto: 4878ms loop 4 end
[INFO]  livephoto: 4879ms loop 5 start
[INFO]  livephoto: 6000ms loop 5 end
[INFO]  livephoto: 6000ms loop 6 start
[INFO]  livephoto: 7040ms loop 6 end
[INFO]  livephoto: 7041ms loop 7 start
[INFO]  livephoto: 8112ms loop 7 end
[INFO]  livephoto: 8113ms loop 8 start
[INFO]  livephoto: 9255ms loop 8 end
[INFO]  livephoto: 9256ms loop 9 start
[INFO]  livephoto: 10282ms loop 9 end
[INFO]  livephoto: 10296ms

Loop 3

[INFO]  livephoto: 0ms loop 0 start
[INFO]  livephoto: 939ms loop 0 end
[INFO]  livephoto: 939ms loop 1 start
[INFO]  livephoto: 1768ms loop 1 end
[INFO]  livephoto: 1768ms loop 2 start
[INFO]  livephoto: 2671ms loop 2 end
[INFO]  livephoto: 2671ms loop 3 start
[INFO]  livephoto: 3649ms loop 3 end
[INFO]  livephoto: 3649ms loop 4 start
[INFO]  livephoto: 4611ms loop 4 end
[INFO]  livephoto: 4612ms loop 5 start
[INFO]  livephoto: 5589ms loop 5 end
[INFO]  livephoto: 5592ms loop 6 start
[INFO]  livephoto: 6684ms loop 6 end
[INFO]  livephoto: 6684ms loop 7 start
[INFO]  livephoto: 7835ms loop 7 end
[INFO]  livephoto: 7835ms loop 8 start
[INFO]  livephoto: 9002ms loop 8 end
[INFO]  livephoto: 9002ms loop 9 start
[INFO]  livephoto: 9986ms loop 9 end
[INFO]  livephoto: 9991ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment