Skip to content

Commit

Permalink
migrate workers (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
herrmannplatz authored Jun 12, 2017
1 parent 5e333ca commit 7309736
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
19 changes: 0 additions & 19 deletions app/worker/image-worker.coffee

This file was deleted.

24 changes: 24 additions & 0 deletions app/worker/image-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
importScripts('jimp.min.js');

const MAX_SIZE = 1448;
const MAX_FILE_SIZE = 310 * 1024;
const COMPRESSION = 80;

self.addEventListener('message', event =>

Jimp.read(event.data).then((image) => {

if ((image.bitmap.width > MAX_SIZE) || (image.bitmap.height > MAX_SIZE)) {
image.scaleToFit(MAX_SIZE, MAX_SIZE);
}

if (image.bitmap.data.length > MAX_FILE_SIZE) {
image.quality(COMPRESSION);
}

return image.getBuffer(Jimp.AUTO, (err, src) => {
self.postMessage(src);
return self.close();
});
})
);
18 changes: 0 additions & 18 deletions app/worker/profile-image-worker.coffee

This file was deleted.

22 changes: 22 additions & 0 deletions app/worker/profile-image-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
importScripts('jimp.min.js');

const MAX_SIZE = 280;
const MAX_FILE_SIZE = 1024 * 1024;
const COMPRESSION = 80;

self.addEventListener('message', event =>

Jimp.read(event.data).then((image) => {

image.cover(MAX_SIZE, MAX_SIZE);

if (image.bitmap.data.length > MAX_FILE_SIZE) {
image.quality(COMPRESSION);
}

return image.getBuffer(Jimp.AUTO, (err, src) => {
self.postMessage(src);
return self.close();
});
})
);

0 comments on commit 7309736

Please sign in to comment.