def _resize_using_pg(self, image, width, height, mode, sbd_id): """ Resize using image mode. """ blob = pg.Blob(image) blob_out = pg.Blob() img = pg.Image(blob) img.filterType(pg.FilterTypes.LanczosFilter) img = process_image_with_mode(img, width, height, mode) if sbd_id in ["4398", "2456", "1976", "616", "536"]: layer = Image('/home/ubuntu/{}.png'.format(sbd_id)) else: layer = Image('/home/ubuntu/DEFAULT.png') layer = process_image_with_mode(layer, width, height, mode) img.composite(layer, 0, 0, co.OverCompositeOp) # Image should be repaged after a crop/resize img.page(pg.Geometry(0, 0, 0, 0)) if settings.IMAGE_QUALITY is not None: # May be handled by custom mode img.quality(settings.IMAGE_QUALITY) img.write(blob_out, 'JPEG') return blob_out.data, img.size().width(), img.size().height()
def _resize_using_pg(self, image, width, height, mode): """ Resize using image mode. """ blob = pg.Blob(image) blob_out = pg.Blob() img = pg.Image(blob) img.filterType(pg.FilterTypes.LanczosFilter) img = process_image_with_mode(img, width, height, mode) # Image should be repaged after a crop/resize img.page(pg.Geometry(0, 0, 0, 0)) img.quality(90) # minimise artifacts but keep size down img.write(blob_out, 'JPEG') return blob_out.data, img.size().width(), img.size().height()
def _resize_using_pg(self, image, width, height, mode): """ Resize using image mode. """ blob = pg.Blob(image) blob_out = pg.Blob() img = pg.Image(blob) img.filterType(pg.FilterTypes.LanczosFilter) img = process_image_with_mode(img, width, height, mode) # Image should be repaged after a crop/resize img.page(pg.Geometry(0, 0, 0, 0)) if settings.IMAGE_QUALITY is not None: # May be handled by custom mode img.quality(settings.IMAGE_QUALITY) img.write(blob_out, 'JPEG') return blob_out.data, img.size().width(), img.size().height()