GroupDocs.Redactions provides a set of features to redact data of sensitive nature from images of various formats like JPG, PNG, TIFF and others. See full list at supported document formats article.
GroupDocs.Redaction supports two ways of redacting images, both in separate image files and embedded images:
You can put a colored box over a given area, such as header, footer, or an area, where customer’s data are expected to appear.
You can use any 3-rd party OCR engine to process the image, search it for text and redact sensitive data within the image.
GroupDocs.Redaction for Python via .NET also allows you to change image metadata (e.g. edit EXIF data of an image or act as an “EXIF eraser”).
Redact image area
In order to redact image area, you have to use ImageAreaRedaction class:
fromgroupdocs.redactionimportRedactor,RedactionStatusfromgroupdocs.redaction.optionsimportSaveOptionsfromgroupdocs.redaction.redactionsimportImageAreaRedaction,RegionReplacementOptionsfromgroupdocs.pydrawingimportColor,Point,Sizedefredact_image_area():# Define the top-left position of the area to redactsample_point=Point(385,485)# Define the size of the area which needs to be redactedsample_size=Size(1793,2069)# Define the color of the redaction boxcolor=Color.from_argb(255,220,20,60)# Specify the redaction optionsrepl_opt=RegionReplacementOptions(color,sample_size)img_red=ImageAreaRedaction(sample_point,repl_opt)# Load the document to be redactedwithRedactor("./sample.jpg")asredactor:# Apply the redactionresult=redactor.apply(img_red)ifresult.status!=RedactionStatus.FAILED:# By default, the redacted document is saved in PDF formatsave_options=SaveOptions()save_options.add_suffix=Truesave_options.rasterize_to_pdf=Truesave_options.redacted_file_suffix="redacted"redactor.save(save_options)if__name__=="__main__":redact_image_area()
sample.jpg is the sample file used in this example. Click here to download it.
The following example demonstrates how to edit exif data (erase them) from a photo or any other image:
fromgroupdocs.redactionimportRedactorfromgroupdocs.redaction.optionsimportSaveOptionsfromgroupdocs.redaction.redactionsimportEraseMetadataRedaction,MetadataFiltersdefclean_image_metadata():# Specify the redaction options to remove all image metadata (e.g. EXIF)er_opt=EraseMetadataRedaction(MetadataFilters.ALL)# Load the image to be redactedwithRedactor("./sample.jpg")asredactor:# Apply the redactionresult=redactor.apply(er_opt)# Save the redacted image next to the source fileso=SaveOptions()so.add_suffix=Trueso.rasterize_to_pdf=Falseso.redacted_file_suffix="redacted"redactor.save(so)if__name__=="__main__":clean_image_metadata()
sample.jpg is the sample file used in this example. Click here to download it.
You can redact image area within all kinds of embedded images inside a document.
The following example demonstrates how to redact all embedded images within a Microsoft Word document:
fromgroupdocs.redactionimportRedactor,RedactionStatusfromgroupdocs.redaction.optionsimportSaveOptionsfromgroupdocs.redaction.redactionsimportImageAreaRedaction,RegionReplacementOptionsfromgroupdocs.pydrawingimportColor,Point,Sizedefredact_embedded_images():# Define the top-left position of the area to redactsample_point=Point(516,311)# Define the size of the area which needs to be redactedsample_size=Size(170,35)# Define the color of the redaction boxcolor=Color.from_argb(255,220,20,60)# Specify the redaction optionsrepl_opt=RegionReplacementOptions(color,sample_size)img_red=ImageAreaRedaction(sample_point,repl_opt)# Load the document to be redactedwithRedactor("./sample.docx")asredactor:# Apply the redaction to all embedded imagesresult=redactor.apply(img_red)ifresult.status!=RedactionStatus.FAILED:# By default, the redacted document is saved in PDF formatsave_options=SaveOptions()save_options.add_suffix=Truesave_options.rasterize_to_pdf=Truesave_options.redacted_file_suffix="redacted"redactor.save(save_options)if__name__=="__main__":redact_embedded_images()
sample.docx is the sample file used in this example. Click here to download it.