python - PIL: preview image without saving -
so working on application allows users edit images. i'm using pil , python. relevant code here: https://github.com/nit-dgp/uip/blob/master/uiplib/uipimage.py
what want user able preview images on gui without saving image. save , open, seem pretty intensive , want edits happen in real time, example there blur bar , want image blur in preview user slides bar. have partial implementation wish know if library provides such feature or can build less resource intensive (right save images , open in real time).
for eg: blur slider
self.slider = scale(self, orient=horizontal, from_=0, to=30, command=self._blur_helper, label="blur", showvalue=0) the _blur_helper_method,
def _blur_helper(self, event): """helper schedule blur_image task.""" if self._job: self.appobj.root.after_cancel(self._job) self._job = self.appobj.root.after(250, self.blur_image) the blur image method:
def blur_image(self): """apply blur chosen image.""" show = self.image.blur(self.slider.get()) self.show_image(show) and image class:
import os pil import image, imagefilter class uipimage: # pragma: no cover """class holds image functions used edit it.""" def __init__(self, image_path): """initialize class.""" self.image_path = image_path self.original_path = image_path self.image = image.open(image_path) self.edited = false self._blur = false self.blur_radius = 0 def blur(self, radius): """save blur pamaters returns blurred image.""" self.edited = true self._blur = true self._blur_radius = radius return self.image.filter(imagefilter.gaussianblur( radius=float(radius))) def save(self): """save image while applying parameters used edit it.""" if self.edited: filename, ext = os.path.splitext(self.original_path) self.image_path = os.path.join(filename + '_uip' + ext) if self._blur: self.image = self.blur(self._blur_radius) self.image.save(self.image_path)
Comments
Post a Comment