def default(self): self.ids.image.source = "colors.png" self.im = Image.open("colors.png").convert( "RGB" ) # Always convert to RGB for compatibility with other modifications self.image = Ima(source="colors.png") self.route = "colors.png"
def halftone(self, value): if value: sample = 30 channel = self.im.split()[2] # New, single 8-bit channel image for halftoning halftoned = Image.new('L', (channel.width, channel.height)) # sets the draw command draw = ImageDraw.Draw(halftoned) # goes from 0 to width of image with step size of 30 (sample size -- basically in a grid of width/30) for x in range(0, channel.width, sample): for y in range(0, channel.height, sample): # makes a new box that takes a sample sized (30x30) square of the original image's B channel box = channel.crop((x, y, x + sample, y + sample)) # sets the stat command stat = ImageStat.Stat(box) # Scales diameter of the halftoning circle (0-sample=30) based on the 0-255 value of the L (only) channel which indicates pixel brightness out of 255 to make it a value from 0-1 diameter = stat.mean[0] * sample / 255 # draws a new halftoned circle with size based on the diameter of the halftoning circle draw.ellipse((x, y, x + diameter, y + diameter), fill=255) # saves new halftoned image using saver function self.saver(halftoned) # IF Halftoning is DESELECTED: return to original state else: self.ids.image.source = self.route self.im = Image.open(self.route) self.image = Ima(source=self.route) self.checkIn()
def saver(self, result): result.convert("RGB").save("result.jpg") self.im = Image.open("result.jpg") self.ids.image.source = self.route self.image = Ima(source="result.jpg") self.image.reload() self.ids.image.source = "result.jpg" self.show()
def load(self, path, filename): self.ids.image.source = filename[0] self.im = Image.open(filename[0]).convert("RGB") self.image = Ima(source=filename[0]) self.route = filename[ 0] # self.route is used when user wants to return to original image. self.image.reload() self.checkIn()
def bwConvert(self, value): if value: self.saver(self.im.convert("LA")) else: self.ids.image.source = self.route self.im = Image.open(self.route) self.image = Ima(source=self.route) self.checkIn()
def solarize(self, value): if value: self.saver(ImageOps.solarize(self.im, 95)) else: self.ids.image.source = self.route self.im = Image.open(self.route) self.image = Ima(source=self.route) self.checkIn()
def show(self): if self.ids.result.state == 'down': self.ids.image.source = self.route self.image = Ima(source="result.jpg") # it is necessary to reload an image after its modification because Kivy keeps a local cache of the image self.image.reload() self.ids.image.source = "result.jpg" else: self.ids.image.source = self.route