| 38 | // const outputPath = 'result.png'; |
| 39 | |
| 40 | async function redactImageAllText() { |
| 41 | // Enable redaction of all text. |
| 42 | const imageRedactionConfigs = [{redactAllText: true}]; |
| 43 | |
| 44 | // Load image |
| 45 | const fileTypeConstant = |
| 46 | ['image/jpeg', 'image/bmp', 'image/png', 'image/svg'].indexOf( |
| 47 | mime.getType(filepath) |
| 48 | ) + 1; |
| 49 | const fileBytes = Buffer.from(fs.readFileSync(filepath)).toString('base64'); |
| 50 | |
| 51 | // Construct the Redact request to be sent by the client. |
| 52 | // Do not specify the type of info to redact. |
| 53 | const request = { |
| 54 | parent: `projects/${projectId}/locations/global`, |
| 55 | byteItem: { |
| 56 | type: fileTypeConstant, |
| 57 | data: fileBytes, |
| 58 | }, |
| 59 | imageRedactionConfigs: imageRedactionConfigs, |
| 60 | }; |
| 61 | |
| 62 | // Run image redaction request |
| 63 | const [response] = await dlp.redactImage(request); |
| 64 | |
| 65 | // Parse the response and process results. |
| 66 | const image = response.redactedImage; |
| 67 | fs.writeFileSync(outputPath, image); |
| 68 | console.log(`Saved image redaction results to path: ${outputPath}`); |
| 69 | } |
| 70 | redactImageAllText(); |
| 71 | // [END dlp_redact_image_all_text] |
| 72 | } |