Dieser Artikel wurde archiviert, da er - oder Teile daraus - nur noch unter einer älteren Ubuntu-Version nutzbar ist. Diese Anleitung wird vom Wiki-Team weder auf Richtigkeit überprüft noch anderweitig gepflegt. Zusätzlich wurde der Artikel für weitere Änderungen gesperrt.
Ein kleines Modul, das die Verwendung von ImageMagick in Python ermöglicht.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #!/usr/bin/env python # -*- coding: utf-8 -*- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from popen2 import popen2 class image: def __init__(self, image): self.img = image def output(self): return self.img def execute(self, cmd): r,w = popen2(cmd) w.write(self.img) w.close() self.img = r.read() def resize(self, width, height="auto"): if height != "auto": scale = str(width)+"x"+str(height)+"\!" else: scale = str(width) self.execute("convert - -resize "+scale+" -") def rotate(self, angle): self.execute("convert - -rotate "+str(angle)+" -") def contrast(self, value): self.execute("convert - -contrast "+str(value)+" -") def mirror(self, vertical): if vertical: op = "-flip" else: op = "-flop" self.execute("convert - "+op+" -") def raisedborder(self, width): scale = str(width)+"x"+str(width) self.execute("convert - -raise "+scale+" -") def loweredborder(self, width): scale = str(width)+"x"+str(width) self.execute("convert - +raise "+scale+" -") def colorborder(self, width, color): scale = str(width)+"x"+str(width) self.execute("convert - -bordercolor \#"+color+" -border "+scale+" -") def roll(self, x, y): self.execute("convert - -roll "+str(x)+"x"+str(y)+" -") def gaussianblur(self, radius=2): self.execute("convert - -gaussian "+str(radius)+" -") def radialblur(self, angle): self.execute("convert - -radial-blur "+str(angle)+" -") def charcoal(self, factor): self.execute("convert - -charcoal "+str(factor)+" -") def colorize(self, value): self.execute("convert - -colorize "+str(value)+" -") def implode(self, factor): self.execute("convert - -implode "+str(factor)+" -") def solarize(self, factor): self.execute("convert - -solarize "+str(factor)+" -") def spread(self, size): self.execute("convert - -spread "+str(size)+" -") def emboss(self, radius): self.execute("convert - -emboss "+str(radius)+" -") def edge(self, radius): self.execute("convert - -edge "+str(radius)+" -") def noise(self, factor): self.execute("convert - -noise "+str(factor)+" -") def painting(self, factor): self.execute("convert - -paint "+str(factor)+" -") def swirl(self, deg): self.execute("convert - -swirl "+str(deg)+" -") def monochrome(self): self.execute("convert - -monochrome -") def negate(self): self.execute("convert - -negate -") def normalize(self): self.execute("convert - -normalize -") def overlay(self, color): self.execute("convert - -opaque \#"+color+" -") def maketrans(self, color): self.execute("convert - -transparent \#"+color+" -") def shade(self, azimuth, elevation): args = str(azimuth)+"x"+str(elevation) self.execute("convert - -shade "+args+" -") ################################################################################ #Kleines Beispiel, das die Datei test.jpg bearbeitet ################################################################################ if __name__ == "__main__": bild = image(file("test.jpg").read()) bild.resize(600) bild.spread(2) bild.gaussianblur(4) bild.swirl(-50) bild.spread(2) bild.swirl(50) bild.spread(2) bild.radialblur(4) bild.gaussianblur(4) file("test2.jpg","w").write(bild.output()) |
Diese Revision wurde am 28. Februar 2010 21:04 von noisefloor erstellt.