/** * @author j433866 [j433866@gmail.com] * @copyright Crown Copyright 2018 * @license Apache-2.0 */ import Operation from "../Operation"; import OperationError from "../errors/OperationError"; import Magic from "../lib/Magic"; import { parseQrCode } from "../lib/QRCode"; /** * Parse QR Code operation */ class ParseQRCode extends Operation { /** * ParseQRCode constructor */ constructor() { super(); this.name = "Parse QR Code"; this.module = "Image"; this.description = "Reads an image file and attempts to detect and read a Quick Response (QR) code from the image.

Normalise Image
Attempts to normalise the image before parsing it to improve detection of a QR code."; this.infoURL = "https://wikipedia.org/wiki/QR_code"; this.inputType = "byteArray"; this.outputType = "string"; this.args = [ { "name": "Normalise image", "type": "boolean", "value": false } ]; } /** * @param {byteArray} input * @param {Object[]} args * @returns {string} */ async run(input, args) { const [normalise] = args; const type = Magic.magicFileType(input); if (!type || type.mime.indexOf("image") !== 0) { throw new OperationError("Invalid file type."); } return await parseQrCode(input, normalise); } } export default ParseQRCode;