pg-mvc-service 2.0.9 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -224,10 +224,17 @@ class Base64Client {
|
|
|
224
224
|
if ('rate' in toSize) {
|
|
225
225
|
rate = toSize.rate;
|
|
226
226
|
}
|
|
227
|
-
else if ('w' in toSize && 'h' in toSize) {
|
|
227
|
+
else if ('w' in toSize && 'h' in toSize && 'func' in toSize) {
|
|
228
228
|
const wRate = toSize.w / width;
|
|
229
229
|
const hRate = toSize.h / height;
|
|
230
|
-
|
|
230
|
+
switch (toSize.func) {
|
|
231
|
+
case 'max':
|
|
232
|
+
rate = Math.max(wRate, hRate);
|
|
233
|
+
break;
|
|
234
|
+
case 'min':
|
|
235
|
+
rate = Math.min(wRate, hRate);
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
231
238
|
}
|
|
232
239
|
else if ('w' in toSize) {
|
|
233
240
|
rate = toSize.w / width;
|
|
@@ -236,14 +243,16 @@ class Base64Client {
|
|
|
236
243
|
rate = toSize.h / height;
|
|
237
244
|
}
|
|
238
245
|
// 画像は1倍より大きくできないので
|
|
239
|
-
if (rate >= 1) {
|
|
246
|
+
if (rate >= 1 || rate <= 0) {
|
|
240
247
|
return base64Data;
|
|
241
248
|
}
|
|
242
249
|
let resizedImage;
|
|
243
250
|
// フォーマットに応じて処理を分岐
|
|
251
|
+
const targetWidth = Math.round(width * rate);
|
|
252
|
+
const targetHeight = Math.round(height * rate);
|
|
244
253
|
if (format === 'png') {
|
|
245
254
|
resizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
246
|
-
.resize(
|
|
255
|
+
.resize(targetWidth, targetHeight, {
|
|
247
256
|
fit: 'inside',
|
|
248
257
|
withoutEnlargement: true
|
|
249
258
|
})
|
|
@@ -253,7 +262,7 @@ class Base64Client {
|
|
|
253
262
|
else {
|
|
254
263
|
// JPEG、その他のフォーマット
|
|
255
264
|
resizedImage = yield (0, sharp_1.default)(imageBuffer)
|
|
256
|
-
.resize(
|
|
265
|
+
.resize(targetWidth, targetHeight, {
|
|
257
266
|
fit: 'inside',
|
|
258
267
|
withoutEnlargement: true
|
|
259
268
|
})
|
package/package.json
CHANGED
|
@@ -221,7 +221,7 @@ export class Base64Client {
|
|
|
221
221
|
return false;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
public async resizeImage(base64Data: string, toSize: {w: number} | {h: number} | {w: number; h: number}| {rate: number}): Promise<string> {
|
|
224
|
+
public async resizeImage(base64Data: string, toSize: {w: number} | {h: number} | {w: number; h: number; func: 'max' | 'min'}| {rate: number}): Promise<string> {
|
|
225
225
|
if (ValidateStringUtil.isBase64(base64Data) === false) {
|
|
226
226
|
throw new Error("The specified data is not in base64 format");
|
|
227
227
|
}
|
|
@@ -236,10 +236,18 @@ export class Base64Client {
|
|
|
236
236
|
let rate = 1;
|
|
237
237
|
if ('rate' in toSize) {
|
|
238
238
|
rate = toSize.rate;
|
|
239
|
-
} else if ('w' in toSize && 'h' in toSize) {
|
|
239
|
+
} else if ('w' in toSize && 'h' in toSize && 'func' in toSize) {
|
|
240
240
|
const wRate = toSize.w / width;
|
|
241
241
|
const hRate = toSize.h / height;
|
|
242
|
-
|
|
242
|
+
switch (toSize.func) {
|
|
243
|
+
case 'max':
|
|
244
|
+
rate = Math.max(wRate, hRate);
|
|
245
|
+
break;
|
|
246
|
+
case 'min':
|
|
247
|
+
rate = Math.min(wRate, hRate);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
|
|
243
251
|
} else if ('w' in toSize) {
|
|
244
252
|
rate = toSize.w / width;
|
|
245
253
|
} else if ('h' in toSize) {
|
|
@@ -247,16 +255,18 @@ export class Base64Client {
|
|
|
247
255
|
}
|
|
248
256
|
|
|
249
257
|
// 画像は1倍より大きくできないので
|
|
250
|
-
if (rate >= 1) {
|
|
258
|
+
if (rate >= 1 || rate <= 0) {
|
|
251
259
|
return base64Data;
|
|
252
260
|
}
|
|
253
261
|
|
|
254
262
|
let resizedImage: Buffer;
|
|
255
263
|
|
|
256
264
|
// フォーマットに応じて処理を分岐
|
|
265
|
+
const targetWidth = Math.round(width * rate);
|
|
266
|
+
const targetHeight = Math.round(height * rate);
|
|
257
267
|
if (format === 'png') {
|
|
258
268
|
resizedImage = await sharp(imageBuffer)
|
|
259
|
-
.resize(
|
|
269
|
+
.resize(targetWidth, targetHeight, {
|
|
260
270
|
fit: 'inside',
|
|
261
271
|
withoutEnlargement: true
|
|
262
272
|
})
|
|
@@ -265,7 +275,7 @@ export class Base64Client {
|
|
|
265
275
|
} else {
|
|
266
276
|
// JPEG、その他のフォーマット
|
|
267
277
|
resizedImage = await sharp(imageBuffer)
|
|
268
|
-
.resize(
|
|
278
|
+
.resize(targetWidth, targetHeight, {
|
|
269
279
|
fit: 'inside',
|
|
270
280
|
withoutEnlargement: true
|
|
271
281
|
})
|