UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

62 lines 2.24 kB
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 marker on the image. * @param image - Image to process. * @param point - Marker center point. * @param options - Draw marker options. * @returns The image with the marker drawing. */ export function drawMarker(image, point, options) { const newImage = getOutputImage(image, options, { clone: true }); const { strokeColor = getDefaultColor(newImage), fillColor, shape = 'cross', size: markerSize = 1, } = options; const size = Math.round(markerSize); validateColor(strokeColor, newImage); if (fillColor) { validateColor(fillColor, newImage); } checkProcessable(newImage, { bitDepth: [8, 16], }); if (shape === 'circle') { newImage.drawCircle(point, size, { strokeColor, fillColor, out: newImage, }); } if (shape === 'triangle') { const points = [ { row: point.row - size, column: point.column }, { row: point.row, column: point.column + size }, { row: point.row, column: point.column - size }, ]; newImage.drawPolygon(points, { strokeColor, fillColor, out: newImage, }); } if (shape === 'cross') { newImage.drawLine({ row: point.row - size, column: point.column }, { row: point.row + size, column: point.column }, { strokeColor, out: newImage }); newImage.drawLine({ row: point.row, column: point.column - size }, { row: point.row, column: point.column + size }, { strokeColor, out: newImage }); } if (shape === 'square') { const origin = { row: point.row - (size - 1) / 2, column: point.column - (size - 1) / 2, }; newImage.drawRectangle({ origin, width: size, height: size, strokeColor, fillColor, out: newImage, }); } return newImage; } //# sourceMappingURL=drawMarker.js.map