mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-22 21:04:08 +02:00
Update poster.ts
This commit is contained in:
@@ -90,37 +90,61 @@ export const poster = defineObject({
|
|||||||
let newDy = dy;
|
let newDy = dy;
|
||||||
|
|
||||||
if (options.fit === 'cover') {
|
if (options.fit === 'cover') {
|
||||||
if (targetAspect > srcAspect) {
|
const ratio = targetAspect / srcAspect;
|
||||||
const fitHeight = targetWidth / srcAspect;
|
|
||||||
const crop = (fitHeight - targetHeight) / fitHeight / 2;
|
let uRange: number;
|
||||||
newAy = ay + crop * (by - ay);
|
let vRange: number;
|
||||||
newBy = by - crop * (by - ay);
|
|
||||||
newCy = cy + crop * (dy - cy);
|
if (ratio < 1) {
|
||||||
newDy = dy - crop * (dy - cy);
|
uRange = ratio; // < 1
|
||||||
|
vRange = 1;
|
||||||
} else {
|
} else {
|
||||||
const fitWidth = targetHeight * srcAspect;
|
uRange = 1;
|
||||||
const crop = (fitWidth - targetWidth) / fitWidth / 2;
|
vRange = 1 / ratio; // < 1
|
||||||
newAx = ax + crop * (bx - ax);
|
|
||||||
newBx = bx - crop * (bx - ax);
|
|
||||||
newCx = cx + crop * (dx - cx);
|
|
||||||
newDx = dx - crop * (dx - cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uMin = (1 - uRange) / 2;
|
||||||
|
const uMax = uMin + uRange;
|
||||||
|
const vMin = (1 - vRange) / 2;
|
||||||
|
const vMax = vMin + vRange;
|
||||||
|
|
||||||
|
newAx = uMin;
|
||||||
|
newBx = uMax;
|
||||||
|
newCx = uMin;
|
||||||
|
newDx = uMax;
|
||||||
|
|
||||||
|
newAy = 1 - vMax;
|
||||||
|
newBy = 1 - vMax;
|
||||||
|
newCy = 1 - vMin;
|
||||||
|
newDy = 1 - vMin;
|
||||||
} else if (options.fit === 'contain') {
|
} else if (options.fit === 'contain') {
|
||||||
if (targetAspect > srcAspect) {
|
const ratio = targetAspect / srcAspect;
|
||||||
const fitWidth = targetHeight * srcAspect;
|
|
||||||
const crop = (fitWidth - targetWidth) / fitWidth / 2;
|
let uRange: number;
|
||||||
newAx = ax + crop * (bx - ax);
|
let vRange: number;
|
||||||
newBx = bx - crop * (bx - ax);
|
|
||||||
newCx = cx + crop * (dx - cx);
|
if (ratio > 1) {
|
||||||
newDx = dx - crop * (dx - cx);
|
uRange = ratio; // > 1
|
||||||
|
vRange = 1;
|
||||||
} else {
|
} else {
|
||||||
const fitHeight = targetWidth / srcAspect;
|
uRange = 1;
|
||||||
const crop = (fitHeight - targetHeight) / fitHeight / 2;
|
vRange = 1 / ratio; // > 1
|
||||||
newAy = ay + crop * (by - ay);
|
|
||||||
newBy = by - crop * (by - ay);
|
|
||||||
newCy = cy + crop * (dy - cy);
|
|
||||||
newDy = dy - crop * (dy - cy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uMin = (1 - uRange) / 2;
|
||||||
|
const uMax = uMin + uRange;
|
||||||
|
const vMin = (1 - vRange) / 2;
|
||||||
|
const vMax = vMin + vRange;
|
||||||
|
|
||||||
|
newAx = uMin;
|
||||||
|
newBx = uMax;
|
||||||
|
newCx = uMin;
|
||||||
|
newDx = uMax;
|
||||||
|
|
||||||
|
newAy = 1 - vMax;
|
||||||
|
newBy = 1 - vMax;
|
||||||
|
newCy = 1 - vMin;
|
||||||
|
newDy = 1 - vMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
uvs[4] = newAx;
|
uvs[4] = newAx;
|
||||||
|
|||||||
Reference in New Issue
Block a user