def __init__(self, size=None, img=None, unit=1): self.unit = t2(unit) if img is not None: iw, ih = img.size ux, uy = self.unit assert iw % ux == 0, 'image width is not divisible by unit' assert ih % uy == 0, 'image height is not divisible by unit' self.size = (iw // ux, ih // uy) self._img = img else: px_size = tuple(u * s for u, s in zip(self.unit, size)) self.size = size self._img = img or CachedImage.blank(px_size) self.px_size = self._img.size
def __init__(self, size=None, img=None, unit=1): self.unit = t2(unit) if img is not None: iw, ih = img.size ux, uy = self.unit assert iw % ux == 0, 'image width is not divisible by unit' assert ih % uy == 0, 'image height is not divisible by unit' self.size = (iw // ux, ih // uy) self._img = img else: px_size = tuple(u * s for u,s in zip(self.unit, size)) self.size = size self._img = img or CachedImage.blank(px_size) self.px_size = self._img.size
def _load_image(full_path, unit): if full_path not in LOAD_CACHE: LOAD_CACHE[full_path] = Image(img=CachedImage.open(full_path), unit=unit or 1) return LOAD_CACHE[full_path]
def sheet(img_offsets, size=None, unit=1): img_offsets = [(i.raw(), off) for i,off in img_offsets] new_img = CachedImage.sheet(img_offsets, size) return Image(img=new_img, unit=unit)
def open(path): return Image(img=CachedImage.from_raw(PIL.Image.open(path)))
def from_raw(img): return Image(img=CachedImage.from_raw(img))
def flatten(self): w, h = self.px_size new_img = CachedImage.sheet( [(self._frames[i].raw(), (i * w, 0)) for i in range(self.length)], (self.length * w, h)) return Image(img=new_img, unit=self.unit)