MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / redactImageAllText

Function redactImageAllText

dlp/redactImageFileAllText.js:40–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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}

Callers 1

mainFunction · 0.85

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected