Use Python to Grayscale ODG Images
Create Python Apps to Grayscale ODG Images and Photos via Server APIs
How to Grayscale ODG Images and Photos with Python
Bright colors are typically associated as the essence of splendid photos. But what if the possibility of color printing isn’t an option? In such scenarios, the need arises to transition color photo into grayscale, and surprisingly, this doesn’t necessarily compromise its impact. Frequently, the conversion from full color to grayscale is an artful technique in itself, enhancing the fascination of your design. The process, coupled with the elimination of color information, can act as your accomplice, accentuating image details, bringing out the texture of surfaces, and orchestrating a visual symphony between light and shadow - thus crafting a distinctive visual effect. To convert ODG images to grayscale, we will utilize Aspose.Imaging for Python via .NET API which is a feature-rich, powerful and easy to use image manipulation and conversion API for Python platform. You may install it using the following command from your system command.
The system command line
>> pip install aspose-imaging-python-net
Steps to Grayscale ODG via Python
You need the aspose-imaging-python-net to try the following workflow in your own environment.
- load ODG files with Image.Load method;
- grayscale image;
- save grayscaled image to disc in the supported by Aspose.Imaging format.
System Requirements
Aspose.Imaging for Python is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows / Linux with .NET Core Runtime.
- Python and PyPi package manager.
Grayscale ODG images - Python
from aspose.imaging import RasterImage, Image, IMultipageImage | |
from aspose.imaging.imageoptions import PngOptions | |
from aspose.pycore import as_of, is_assignable | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
def delete_file(file): | |
if delete_output: | |
os.remove(file) | |
def grayscale_images(): | |
obj_init = [] | |
obj_init.append("jpg") | |
obj_init.append("png") | |
obj_init.append("bmp") | |
obj_init.append("apng") | |
obj_init.append("dicom") | |
obj_init.append("jp2") | |
obj_init.append("j2k") | |
obj_init.append("tga") | |
obj_init.append("webp") | |
obj_init.append("tiff") | |
obj_init.append("gif") | |
obj_init.append("ico") | |
raster_formats = obj_init | |
obj_init2 = [] | |
obj_init2.append("svg") | |
obj_init2.append("otg") | |
obj_init2.append("odg") | |
obj_init2.append("eps") | |
obj_init2.append("wmf") | |
obj_init2.append("emf") | |
obj_init2.append("wmz") | |
obj_init2.append("emz") | |
obj_init2.append("cmx") | |
obj_init2.append("cdr") | |
vector_formats = obj_init2 | |
all_formats = raster_formats | |
all_formats.extend(vector_formats) | |
for format_ext in all_formats: | |
input_file = os.path.join(templates_folder, f"template.{format_ext}") | |
if not os.path.exists(input_file): | |
continue | |
is_vector_format = format_ext in vector_formats | |
if is_vector_format: | |
input_file = rasterize_vector_image(format_ext, input_file) | |
output_file = os.path.join(templates_folder, f"grayscale_{format_ext}.png") | |
print(f"Processing {format_ext}") | |
# explicit type casting from Image to RasterImage | |
with as_of(Image.load(input_file), RasterImage) as image: | |
# Additional code examples can be found at | |
# https://apireference.aspose.com/imaging/python-net/aspose.imaging/rasterimage/methods/grayscale | |
image.grayscale() | |
multi_page = None | |
# if image implements an IMultipageImage interface | |
if is_assignable(image, IMultipageImage): | |
multi_page = as_of(image, IMultipageImage) | |
if multi_page is not None and multi_page.page_count > 1: | |
page_index = 0 | |
for page in multi_page.pages: | |
file_name = f"grayscale_page{page_index}_{format_ext}.png" | |
page.save(templates_folder + file_name, PngOptions()) | |
delete_file(templates_folder + file_name) | |
page_index += 1 | |
else: | |
image.save(output_file, PngOptions()) | |
delete_file(output_file) | |
if is_vector_format: | |
delete_file(input_file) | |
def rasterize_vector_image(format_ext, input_file): | |
output_file = os.path.join(templates_folder, f"rasterized.{format_ext}.png") | |
with Image.load(input_file) as image: | |
image.save(output_file, PngOptions()) | |
return output_file | |
grayscale_images() |
About Aspose.Imaging for Python API
Aspose.Imaging API is an image processing solution to create, modify, draw or convert images (photos) within applications. It offers: cross-platform Image processing, including but not limited to conversions between various image formats (including uniform multi-page or multi-frame image processing), modifications such as drawing, working with graphic primitives, transformations (resize, crop, flip&rotate, binarization, grayscale, adjust), advanced image manipulation features (filtering, dithering, masking, deskewing), and memory optimization strategies. It’s a standalone library and does not depend on any software for image operations. One can easily add high-performance image conversion features with native APIs within projects. These are 100% private on-premise APIs and images are processed at your servers.Grayscale ODG via Online App
Grayscale ODG documents by visiting our Live Demos website The live demo has the following benefits
ODG What is ODG File Format
The ODG file format is used by Apache OpenOffice's Draw application to store drawing elements as a vector image. It follows the XML based file format specifications outlined by Advancement of Structural Information Standards (OASIS). ODG represents drawings as vector images using points, lines and curves. Besides OpenOffice, LibreOffice and other applications also provide support for working with ODG file format. Other formats supported by OpenOffice, for example, include ODT, ODF, ODP and ODS.
Read MoreOther Supported Grayscale Formats
Using Python, you can easily grayscale different formats including: