2020년 3월 30일 월요일

[IronPython] Image Processor Example


DLL Download 




1. Image Processor Example


import clr

clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")

clr.AddReferenceToFileAndPath("ImageProcessor.dll")

import System
from System.IO.File import OpenRead
from System.IO.File import OpenWrite
from System.IO import FileStream
from System.IO import FileMode
from System.IO import FileAccess
from System.IO import FileShare

from System.Drawing import Size
from System.Drawing import Point
from System.Drawing import Rectangle
from System.Drawing import Color

import ImageProcessor
from ImageProcessor import ImageFactory
from ImageProcessor.Imaging import Formats
from ImageProcessor.Imaging import ImageLayer

class Image():
    def __init__(self):
        self.ip = ImageFactory()
    def Load(self,filename):
        self.ip.Load(filename)
    def SaveJpg(self,filename):
        fs = FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)    
        Formats.JpegFormat().Save( fs, self.ip.Image, self.ip.CurrentBitDepth )
    def SavePng(self,filename):
        fs = FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)    
        Formats.PngFormat().Save( fs, self.ip.Image, self.ip.CurrentBitDepth )
    def Quality(self,quality):
        self.ip.Quality(quality)
    def Resize(self,width,height):
        self.ip.Resize(Size(width,height))
    def Rotate(self,degree):
        self.ip.Rotate(degree)
    def Flip(self):
        self.ip.Flip()
    def Crop(self,x,y,w,h):
        self.ip.Crop(Rectangle(x,y,w,h))
    def Tint(self,color):
        self.ip.Tint(color)
    def Alpha(self,percentage):
        self.ip.Alpha(percentage)
    def Brightness(self,percentage):
        self.ip.Brightness(percentage)
    def Contrast(self,percentage):
        self.ip.Contrast(percentage)
    def BitDepth(self,depth):
        self.ip.BitDepth(depth)
    def ReplaceColor(self,target,replacement,fuzzyness=0): #0..128
        self.ip.ReplaceColor(target,replacement,fuzzyness)
    def Overlay(self,image,x=None,y=None):
        ip = ImageFactory()
        ip.Load(image)
        il = ImageLayer()
        il.Image = ip.Image
        if x and y: il.Position = Point(x,y)
        self.ip.Overlay(il)
        
if __name__ == "__main__":
    image = Image()
    image.Load("Lenna.png")
    image.Brightness(50)
    image.SaveJpg("Lenna2.jpg")

댓글 없음:

댓글 쓰기