-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e333ca
commit 7309736
Showing
4 changed files
with
46 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}) | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}) | ||
); |