Package: aspose-imaging-python-net
Imaging Manipulation APIProduct Page|Documentation|Demos|Blog|API Reference|Search|Free Support|Temporary License|EULATry ourfree online Appsdemonstrating some of the most popular Aspose.Imaging functionality.Aspose.Imaging for Python via .NETisAnother Python Imaging Libraryoffering advanced image processing features. You could easily create, load, manipulate, convert, compress images or photos using this API. AlsoAspose.Imaginglibrary supports drawing and work with graphic primitives. Image export and conversion (including uniform multi-page image processing) is the one of API core features along with image transformations (resize, crop, flip&rotate, binarization, grayscale, adjust, etc.), advanced image manipulation features (filtering, dithering, masking, deskewing) and memory optimization strategies.Aspose.Imaging for Python via .NETis a flexible, stable and powerful API, capable of processing the most commonly used formats along with some special formats such as DjVu, DICOM, WebP & DNG. Moreover, it extends the native support for image formats & processing functions for .NET and .NET Core.Aspose.Imagingis cross-platform library, it is Windows x32/x64, Linux x64, and MacOS x64/Arm64 compatible.Aspose.Imaging for Python requires you to use python programming language. For Java and .NET languages, we recommend you get Aspose.Imaging for Java and Aspose.Imaging for .NET, respectively.Product FeaturesThe following are Aspose.Imaging’s core features:Create images (raster, vector)Read images (raster, vector)Write images (raster, vector)Draw lines, circles, ellipses, texts, complex paths, and images using the classes Graphics, SvgGraphics2D, EmfRecorderGraphics2D, WmfRecorderGraphics2DProcess images (including per-pixel modifications)Convert between different image formats as raster as vectorSupport the large images with size more than 100000x100000 pixelsMemory and performance management strategiesSupported File FormatsFile formatSupported versionsLoadSaveBMPBMP Specification v5YesYesGIFVersion 89aYesYesDICOMVersion 3.0YesYesDJVUVersion 3.0YesDNGVersion 1.0.0.0 and laterYesEMFRevision 11.0YesYesJPEGCCITT Rec. T.81 (1992 E)YesYesJPEG2000ITU-T Rec. T.800 (08/2002 E)YesYesODGVersion 1.2YesPNGVersion 1.0 and laterYesYesICOVersion 1.0 and laterYesYesAPNGYesYesPSDAdobe Photoshop 2.0 and laterYesDXFDxf 6 and laterYesSVGVersion 1.1YesYesTIFFVersion 6.0*YesYesBIG-TIFFYesYesDIBBMP Specification v5YesEPSYesWEBPYesWMFRevision 13.0YesYesCDRVersion X7, X6 (3-x5 not completely)YesCMXVersion 2.0, 32 bit precision (16 bit precision not completely)YesOTGVersion 1.2YesPDFPortable document formatYesHTML5 canvasHtml5 canvas elementYesEMZCompressed emf formatYesYesWMZCompressed wmf formatYesYesTGATruevision TGA (TARGA)YesYesSVGZCompressed svg file formatYesYesPlatform IndependenceAspose.Imaging for Python can be used to develop applications for a vast range of operating systems, such as Windows (x32/x64), Linux (x64), and MacOS (x64/arm64) where Python 3.5 or later is installed.The base .NET platform is .NET Core 6.0Do not use System.Drawing.Common but the platform-independent Aspose.Drawing.Get StartedReady to give Aspose.Imaging for Python a try?Simply runpip install aspose-imaging-python-netfrom the console to fetch the package. If you already have Aspose.Imaging for Python and want to upgrade the version, please runpip install --upgrade aspose-imaging-python-netto get the latest version.You can run the following snippets in your environment to see how Aspose.Imaging works, or check out theGitHub RepositoryorAspose.Imaging for Python Documentationfor other common use cases.Create a PNG image from scratch in Pythonfromaspose.imagingimportColor,Graphics,Penfromaspose.imaging.fileformats.pngimportPngImage# create an empty PNG imagewithPngImage(100,100)aspng:# create a canvas for drawing over the imageg=Graphics(png)# start a queue of operations which will be processed together as a batchg.begin_update()# fill the background with blue colorg.clear(Color.blue)# draw a line with light green pen with width == 2.0g.draw_line(Pen(Color.light_green,2.0),0,10,100,90)# execute all drawing operations as oneg.end_update()# save image in a filepng.save("output.png")Create and manipulate with PNG imagefromaspose.imagingimportImage,ResizeType,Graphics,Color,Pen,Rectanglefromaspose.imaging.fileformats.pngimportPngImagefromaspose.imaging.imageoptionsimportPngOptionsfromaspose.imaging.sourcesimportFileCreateSourcefromaspose.pycoreimportas_ofimportosdata_dir="~/data-dir"width=500height=300path=os.path.join(data_dir,"result.png")withPngOptions()asoptions:options.source=FileCreateSource(path,False)withas_of(Image.create(options,width,height),PngImage)asimage:graphic=Graphics(image)graphic.clear(Color.green)graphic.draw_line(Pen(Color.blue),9,9,90,90)new_width=400image.resize_width_proportionally(new_width,ResizeType.LANCZOS_RESAMPLE)area=Rectangle(10,10,200,200)image.crop(area)image.save()# save into the file set to options.sourceLoad, resize and save a raster imagefromaspose.imagingimportImagewithImage.load("any-picture.tiff")asimage:image.resize(image.width//2,image.height//2)image.save("output.jpeg")Load a raster image (PNG) and convert it into jpegfromaspose.imagingimportImage,FileFormatfromaspose.imaging.fileformats.pngimportPngImageimportaspose.pycoreaspycorewithImage.load("any-picture.png")asimage:print("format: ",FileFormat(image.file_format).name)# for accessing to a PngImage properties and methods need to cast itpng_image=pycore.as_of(image,PngImage)print("xmp_data",png_image.xmp_data)image.save("output.jpeg")Load jpeg and export it into the different formatsfromaspose.imagingimportImagefromaspose.imaging.fileformats.pdfimportPdfDocumentInfofromaspose.imaging.fileformats.tiff.enumsimport*fromaspose.imaging.imageoptionsimport*importosdata_dir="data-dir"withImage.load(os.path.join(data_dir,"template.jpg"))asimg:# convert to webpimg.save(os.path.join(data_dir,"output.webp"),WebPOptions())# convert to psdimg.save(os.path.join(data_dir,"output.psd "),PsdOptions())# convert to tiffimg.save(os.path.join(data_dir,"output.tiff"),TiffOptions(TiffExpectedFormat.DEFAULT))# convert to pdfexport_options=PdfOptions()export_options.pdf_document_info=PdfDocumentInfo()img.save(os.path.join(data_dir,"output.pdf"),export_options)Crop imagefromaspose.pycoreimportas_offromaspose.imagingimportImage,Rectangle,RasterImageimportosdata_dir="data-dir"withImage.load(os.path.join(data_dir,"template.jpg"))asimg:# casting to the RasterImage classraster_image=as_of(img,RasterImage)# croparea=Rectangle(10,10,img.width-20,img.height-20)raster_image.crop(area)image.save("cropped.jpg")Merge images into one (collage)fromaspose.imagingimportImage,Graphics,Color,RectangleFfromaspose.imaging.fileformats.pngimportPngColorTypefromaspose.imaging.imageoptionsimportPngOptionsfromaspose.imaging.sourcesimportFileCreateSourceimportosdata_dir="data-dir"images=[]# files for mergingfiles=["template.png","template.jpg"]# could be more file heremax_width=0max_height=0total_width=0total_height=0forfile_nameinfiles:image=Image.load(os.path.join(data_dir,file_name))total_width+=image.widthifimage.width>max_width:max_width=image.widthtotal_height+=image.heightifimage.height>max_height:max_height=image.heightimages.append(image)defmerge_images(direction,out_file_name):target_width=0target_height=0ifdirection==0:target_width=total_widthtarget_height=max_heightelse:target_width=max_widthtarget_height=total_heightoutput_path=os.path.join(data_dir,out_file_name+".png")withPngOptions()aspng_options:png_options.color_type=PngColorType.TRUECOLOR_WITH_ALPHAwithopen(out_file_name,"wb")asstream:png_options.source=FileCreateSource(output_path,False)withImage.create(png_options,target_width,target_height)asimage:image.background_color=Color.whitegraphics=Graphics(image)x=0y=0graphics.begin_update()forframeinimages:print("x",x,"y",y)graphics.draw_image(frame,RectangleF(x,y,frame.width,frame.height))ifdirection==0:x+=frame.widthifdirection==1:y+=frame.heightgraphics.end_update()image.save(output_path)# runmerge_images(0,"collage_horizontal")merge_images(1,"collage_vertical")forimageinimages:# to dispose the image we call __exit__()withimageas_:passProduct Page|Documentation|Demos|Blog|API Reference|Search|Free Support|Temporary License|EULA