image-js
Version:
Image processing and manipulation in JavaScript
26 lines • 1.12 kB
JavaScript
import { getDefaultColor } from '../utils/getDefaultColor.js';
import { getOutputImage } from '../utils/getOutputImage.js';
import checkProcessable from '../utils/validators/checkProcessable.js';
import { validateColor } from '../utils/validators/validators.js';
/**
* Draw a polyline defined by an array of points on an image.
* @param image - Image to process.
* @param points - Polyline array of points.
* @param options - Draw polyline options.
* @returns The image with the polyline drawing.
*/
export function drawPolylineOnImage(image, points, options = {}) {
const { strokeColor: color = getDefaultColor(image), origin = { column: 0, row: 0 }, } = options;
checkProcessable(image, {
bitDepth: [8, 16],
});
const newImage = getOutputImage(image, options, { clone: true });
validateColor(color, newImage);
for (let i = 0; i < points.length - 1; i++) {
const from = points[i];
const to = points[i + 1];
newImage.drawLine(from, to, { out: newImage, strokeColor: color, origin });
}
return newImage;
}
//# sourceMappingURL=drawPolylineOnImage.js.map