I'm trying to do a gif of liquid rescales with Wand, but when the gif is saved into a file the filesize is obscene huge, I mean, from a JPG image of 1539x2048 and 242 KB it yields a gif of 55 MB. Besides, when calling image.make_blob()
it takes a lot of time to generate the blob.
from wand.image import Image
def gifynize(image: str, level: int = 50) -> bytes:
with Image() as gif:
with Image(filename=image) as source:
width, height = source.width, source.height
target_witdh = width * (100 - level) // 100
target_height = height * (100 - level) // 100
width_steps = (width - target_x) // (10 * 3)
height_steps = (height - target_y) // (10 * 3)
with source.clone() as clone:
gif.sequence.append(clone)
for _width, _height in zip(
range(width, target_width, -width_steps), range(heigth, target_heigth, -heigth_steps)
):
source.liquid_rescale(_width, height)
with source.clone() as clone:
clone.resize(width, height) # Bring back to the original size
gif.sequence.append(clone)
gif.format = "gif"
return gif.make_blob()
I have tried gif.type = "optimize"
, gif.optimize_layers()
and gif.optimize_transparency()
but the final gif filesize doesn't change. Also, when using heavy images (2 MB), it throws a segmentation fault when calling img.make_blob()
.
Any help is welcome.