summaryrefslogtreecommitdiffstats
path: root/src/services/jobs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/jobs.ts')
-rw-r--r--src/services/jobs.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/services/jobs.ts b/src/services/jobs.ts
index 354c66d..878593b 100644
--- a/src/services/jobs.ts
+++ b/src/services/jobs.ts
@@ -1,6 +1,7 @@
1import * as e621 from "../api/e926"; 1import * as e621 from "../api/e926";
2import * as mastodon from "../api/mastodon"; 2import * as mastodon from "../api/mastodon";
3import config from "../config"; 3import config from "../config";
4import { imageSize } from "image-size";
4import Sharp from "sharp"; 5import Sharp from "sharp";
5 6
6export async function postSpecificPicture(id: number) { 7export async function postSpecificPicture(id: number) {
@@ -33,11 +34,15 @@ async function handlePost(post: e621.Post) {
33 34
34 let file = await e621.client.get(post.file.url).buffer(); 35 let file = await e621.client.get(post.file.url).buffer();
35 36
36 if (Buffer.byteLength(file) > 1024 * 1024 * 9) { 37 const dims = imageSize(file);
38 const width = dims.width ?? 0;
39 const height = dims.height ?? 0;
40
41 if (Buffer.byteLength(file) > 1024 * 1024 * 9 || width > 2000 || height > 2000) {
37 console.log(`Compressing...`); 42 console.log(`Compressing...`);
38 43
39 file = await Sharp(file) 44 file = await Sharp(file)
40 .resize(1800, 1800, { fit: "inside", withoutEnlargement: true }) 45 .resize(2000, 2000, { fit: "inside", withoutEnlargement: true })
41 .jpeg({ quality: 80, mozjpeg: true }) 46 .jpeg({ quality: 80, mozjpeg: true })
42 .toBuffer(); 47 .toBuffer();
43 } 48 }