ensure image is square before transit
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { APIUtils, NoBody } from "../apiutils.ts";
|
||||
import * as BaseImages from "../data/content/baseimages.ts";
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import express from "express";
|
||||
import * as Images from "./../data/content/images.ts";
|
||||
import { Image } from "https://deno.land/x/imagescript@1.3.0/mod.ts";
|
||||
@@ -63,21 +62,6 @@ route.router.get(
|
||||
else height = num;
|
||||
}
|
||||
|
||||
if (cropSquare) {
|
||||
if (image.width > image.height) {
|
||||
image.crop(
|
||||
Math.round(image.width / 2) - Math.round(image.height / 2),
|
||||
0,
|
||||
image.height,
|
||||
image.height,
|
||||
);
|
||||
} else {image.crop(
|
||||
0,
|
||||
Math.round(image.height / 2) - Math.round(image.width / 2),
|
||||
image.width,
|
||||
image.width,
|
||||
);}
|
||||
}
|
||||
if (width && height) {
|
||||
const targetWidth = width > image.width ? image.width : width;
|
||||
const targetHeight = height > image.height ? image.height : height;
|
||||
@@ -100,6 +84,21 @@ route.router.get(
|
||||
}
|
||||
} else if (width) image.resize(width, Image.RESIZE_AUTO);
|
||||
else if (height) image.resize(Image.RESIZE_AUTO, height);
|
||||
if (cropSquare) {
|
||||
if (image.width > image.height) {
|
||||
image.crop(
|
||||
Math.round(image.width / 2) - Math.round(image.height / 2),
|
||||
0,
|
||||
image.height,
|
||||
image.height,
|
||||
);
|
||||
} else {image.crop(
|
||||
0,
|
||||
Math.round(image.height / 2) - Math.round(image.width / 2),
|
||||
image.width,
|
||||
image.width,
|
||||
);}
|
||||
}
|
||||
|
||||
rs.type("png").send(Buffer.from(await image.encode()));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user