image-js
Version:
Image processing and manipulation in JavaScript
27 lines • 1.29 kB
JavaScript
import { line } from 'bresenham-zingl';
import { getDefaultColor } from '../utils/getDefaultColor.js';
import { getOutputImage } from '../utils/getOutputImage.js';
import { setBlendedVisiblePixel } from '../utils/setBlendedVisiblePixel.js';
import checkProcessable from '../utils/validators/checkProcessable.js';
import { validateColor } from '../utils/validators/validators.js';
/**
* Draw a line defined by two points onto an image.
* @param image - Image to process.
* @param from - Line starting point.
* @param to - Line ending point.
* @param options - Draw Line options.
* @returns The mask with the line drawing.
*/
export function drawLineOnImage(image, from, to, options = {}) {
const newImage = getOutputImage(image, options, { clone: true });
const { strokeColor = getDefaultColor(newImage), origin = { column: 0, row: 0 }, } = options;
validateColor(strokeColor, newImage);
checkProcessable(newImage, {
bitDepth: [8, 16],
});
line(Math.round(origin.column + from.column), Math.round(origin.row + from.row), Math.round(origin.column + to.column), Math.round(origin.row + to.row), (column, row) => {
setBlendedVisiblePixel(newImage, column, row, strokeColor);
});
return newImage;
}
//# sourceMappingURL=drawLineOnImage.js.map