PPTX DOCX XLSX PDF ODP
Aspose.Imaging  for Python
WMF

Use Python for WMF Images Adjustment

Create Python Apps to Adjust WMF Images and Photos via Server APIs

How to Adjust WMF Images and Photos with Python

While capturing images, mistakes can occur due to incorrect camera settings. Uncontrolled lighting can also impact the results, and even professional photographs may exhibit imperfections. However, in such scenarios, there is a method to enhance the image by utilizing software tools provided by the Python library. You have the ability to fine-tune the image’s brightness, contrast, and color balance. For instance, if a photo appears overly dim, increasing the brightness will illuminate darker regions, unveiling details that were formerly obscured in shadows. If your image exhibits undesirable color casts due to artificial lighting, you can rectify this using the color gamma adjustment feature. To execute these alterations on WMF files, you can make use of 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 Adjust WMF via Python

You need the aspose-imaging-python-net to try the following workflow in your own environment.

  • load WMF files with Image.Load method;
  • adjust image;
  • save adjusted 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.
 

Adjust WMF images - Python

from aspose.imaging import *
from aspose.imaging.fileformats.bmp import *
from aspose.imaging.fileformats.dicom import *
from aspose.imaging.fileformats.emf import *
from aspose.imaging.fileformats.jpeg import *
from aspose.imaging.fileformats.jpeg2000 import *
from aspose.imaging.fileformats.png import *
from aspose.imaging.fileformats.psd import *
from aspose.imaging.fileformats.tiff.enums import *
from aspose.imaging.imagefilters.filteroptions import *
from aspose.imaging.imageoptions import *
from aspose.imaging.masking import *
from aspose.imaging.masking.options import *
from aspose.imaging.masking.result import *
from aspose.imaging.sources import *
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 adjust_gamma_rgb():
# https://apireference.aspose.com/imaging/python-net/aspose.imaging.rasterimage/adjustgamma
filter_images(lambda image: image.adjust_gamma(5, 0.1, 0.1), "adjustgammargb")
def adjust_gamma():
filter_images(lambda image: image.adjust_gamma(3), "adjustgamma")
def adjust_contrast():
filter_images(lambda image: image.adjust_contrast(50), "adjustcontrast")
def adjust_brightness():
filter_images(lambda image: image.adjust_brightness(100), "adjustbrightness")
def filter_images(do_filter, filter_name):
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("tif")
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 = []
all_formats.extend(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"{filter_name}_{format_ext}.png")
print(format_ext)
# explicit type casting from Image to RasterImage
with as_of(Image.load(input_file), RasterImage) as image:
do_filter(image)
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:
# for loop
page_index = 0
for page in multi_page.pages:
file_name = f"{filter_name}_page{page_index}_{format_ext}.png"
page.save(os.path.join(templates_folder + file_name), PngOptions())
# delete an output file
delete_file(os.path.join(templates_folder + file_name))
page_index += 1
else:
image.save(output_file, PngOptions())
# delete an output file
delete_file(output_file)
# delete a rasterized file
if is_vector_format:
delete_file(input_file)
def delete_file(file):
if delete_output:
os.remove(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
# call one of the functions
adjust_brightness()
#adjust_contrast()
#adjust_gamma()
#adjust_gamma_rgb()
 
  • 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.

    Adjust WMF via Online App

    Adjust WMF documents by visiting our Live Demos website The live demo has the following benefits

      No need to download or setup anything
      No need to write any code
      Just upload your WMF files and hit "Adjust now" button
      Instantly get the download link for the resultant file

    WMF What is WMF File Format

    Files with WMF extension represent Microsoft Windows Metafile (WMF) for storing vector as well as bitmap-format images data. To be more accurate, WMF belongs to the vector file format category of Graphics file formats that is device independent. Windows Graphical Device Interface (GDI) uses the functions stored in a WMF file to display an image on the screen. A more enhanced version of WMF, known as Enhanced Meta Files (EMF), was published later that makes the format more feature rich. Practically, WMF are similar to SVG.

    Read More

    Other Supported Adjust Formats

    Using Python, you can easily Adjust different formats including:

    APNG (Animated Portable Network Graphics)
    BMP (Bitmap Picture)
    ICO (Windows icon)
    JPG (Joint Photographic Experts Group)
    JPEG (Joint Photographic Experts Group)
    DIB (Device Independent Bitmap)
    DICOM (Digital Imaging & Communications)
    DJVU (Graphics Format)
    DNG (Digital Camera Image)
    EMF (Enhanced Metafile Format)
    EMZ (Windows Compressed Enhanced Metafile)
    GIF (Graphical Interchange Format)
    JP2 (JPEG 2000)
    J2K (Wavelet Compressed Image)
    PNG (Portable Network Graphics)
    TIFF (Tagged Image Format)
    TIF (Tagged Image Format)
    WEBP (Raster Web Image)
    WMZ (Compressed Windows Media Player Skin)
    TGA (Targa Graphic)
    SVG (Scalable Vector Graphics)
    EPS (Encapsulated PostScript Language)
    CDR (Vector Drawing Image)
    CMX (Corel Exchange Image)
    OTG (OpenDocument Standard)
    ODG (Apache OpenOffice Draw Format)