|
1 | 1 | import { Image } from '../Image';
|
2 | 2 | import { getClamp } from '../utils/clamp';
|
3 |
| -import { getBorderInterpolation, BorderType } from '../utils/interpolateBorder'; |
| 3 | +import { BorderType, getBorderInterpolation } from '../utils/interpolateBorder'; |
4 | 4 | import {
|
5 | 5 | getInterpolationFunction,
|
6 | 6 | InterpolationType,
|
7 | 7 | } from '../utils/interpolatePixel';
|
8 | 8 | import { assert } from '../utils/validators/assert';
|
9 | 9 |
|
| 10 | +import { transform } from './transform'; |
| 11 | + |
10 | 12 | export interface ResizeOptions {
|
11 | 13 | /**
|
12 | 14 | * Width of the output image.
|
@@ -58,7 +60,25 @@ export function resize(image: Image, options: ResizeOptions): Image {
|
58 | 60 | borderType = 'constant',
|
59 | 61 | borderValue = 0,
|
60 | 62 | } = options;
|
61 |
| - const { width, height } = checkOptions(image, options); |
| 63 | + const { width, height, xFactor, yFactor } = checkOptions(image, options); |
| 64 | + |
| 65 | + if (interpolationType === 'nearest') { |
| 66 | + return transform( |
| 67 | + image, |
| 68 | + [ |
| 69 | + [xFactor, 0, xFactor / 2], |
| 70 | + [0, yFactor, yFactor / 2], |
| 71 | + ], |
| 72 | + { |
| 73 | + interpolationType, |
| 74 | + borderType, |
| 75 | + borderValue, |
| 76 | + height, |
| 77 | + width, |
| 78 | + }, |
| 79 | + ); |
| 80 | + } |
| 81 | + |
62 | 82 | const newImage = Image.createFrom(image, { width, height });
|
63 | 83 | const interpolate = getInterpolationFunction(interpolationType);
|
64 | 84 | const interpolateBorder = getBorderInterpolation(borderType, borderValue);
|
|
0 commit comments