Skip to content
Discussion options

You must be logged in to vote

The last option is porbably the best one but you can do a small optimization:

const sizes = [48, 96];
function process(image, size) {
    //image.crop(new MagickGeometry('2:1'), Gravity.Center);
    image.resize(size * 2, size);
    image.write(MagickFormat.WebP, data => {
        const base64 = `data:image/webp;base64,${ Buffer.from(data).toString('base64') }`;
        console.log(base64);
    });
}

ImageMagick.read(imageBytes, image => {
    // You only need to do this once.
    image.crop(new MagickGeometry('2:1'), Gravity.Center);
    sizes.forEach(size => {
        image.clone(clone => {
            process(clone, size);
        });
    });
});

But this can be optimized even further…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@kaya51
Comment options

@dlemstra
Comment options

Answer selected by kaya51
@kaya51
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants