Skip to content

Is it possible to use vips_arrayjoin from sharp? #1580

Closed

Description

@NDevTK

I would like to create an image from an array of image buffers with x number of images per row.

Activity

  1. lovell commented on Feb 17, 2019

    @lovell
    Owner

    Hello, this isn't supported at the moment, but could make a future possible enhancement.

    👇 PROPOSED API, NOT YET AVAILABLE

    const twoByTwo = await sharp([image1, image2, image3, image4], {
      join: {
        across: 2,
        background: '#fff',
        halign: 'centre',
        valign: 'centre',
        shim: 10,
      }
    })
      .png()
      .toBuffer();
    
    const animatedGif = await sharp([image1, image2, image3, image4], {
      join: {
        animated: true
      }
    })
      .gif()
      .toBuffer();

    ☝️ PROPOSED API, NOT YET AVAILABLE

    ...where image1 are either filenames or Buffer objects (no Streams). When animated is used, ensure array produces "toilet-roll" image and set page height etc.

  2. NDevTK commented on Feb 17, 2019

    @NDevTK
    Author

    Is there a way to use the bundled libvips from the child process? #1175 (comment)

  3. NDevTK commented on Feb 17, 2019

    @NDevTK
    Author

    for .join() would it be possible to pass a 2d array that gets split up if there’s a across parameter. I think vips_arrayjoin() already has an across parameter

  4. lovell commented on Feb 18, 2019

    @lovell
    Owner

    Is there a way to use the bundled libvips from the child process?

    Only shared libraries are included, no executable files.

  5. NDevTK commented on Feb 22, 2019

    @NDevTK
    Author

    How do you use a child process

    const { execFileSync  } = require('child_process');
    function combine(images){
        const child = execFileSync('vips', ['arrayjoin', images, '--across 8', 'output.jpg']);
    }
    

    images is "img-0.jpg img-1.jpg img-2.jpg img-3.jpg img-4.jpg img-5.jpg img-6.jpg img-7.jpg img-8.jpg img-9.jpg img-10.jpg img-11.jpg img-12.jpg img-13.jpg img-14.jpg img-15.jpg img-16.jpg img-17.jpg img-18.jpg img-19.jpg img-20.jpg img-21.jpg img-22.jpg img-23.jpg img-24.jpg img-25.jpg img-26.jpg img-27.jpg img-28.jpg img-29.jpg img-30.jpg img-31.jpg img-32.jpg img-33.jpg img-34.jpg img-35.jpg img-36.jpg img-37.jpg img-38.jpg img-39.jpg img-40.jpg img-41.jpg img-42.jpg img-43.jpg img-44.jpg img-45.jpg img-46.jpg img-47.jpg"
    But when I run it i get Unknown option --across 8 however if I run vips arrayjoin "img-0.jpg img-1.jpg img-2.jpg img-3.jpg img-4.jpg img-5.jpg img-6.jpg img-7.jpg img-8.jpg img-9.jpg img-10.jpg img-11.jpg img-12.jpg img-13.jpg img-14.jpg img-15.jpg img-16.jpg img-17.jpg img-18.jpg img-19.jpg img-20.jpg img-21.jpg img-22.jpg img-23.jpg img-24.jpg img-25.jpg img-26.jpg img-27.jpg img-28.jpg img-29.jpg img-30.jpg img-31.jpg img-32.jpg img-33.jpg img-34.jpg img-35.jpg img-36.jpg img-37.jpg img-38.jpg img-39.jpg img-40.jpg img-41.jpg img-42.jpg img-43.jpg img-44.jpg img-45.jpg img-46.jpg img-47.jpg" --across 8 output.jpg from the project directory in cmd it works and creates the output.jpg file

  6. lovell commented on Feb 22, 2019

    @lovell
    Owner

    I think you need to specify --across and 8 as separate arguments. This is a Node thing unrelated to sharp or libvips.

  7. willemmulder commented on Aug 27, 2020

    @willemmulder

    @lovell Is this still planned? Would be very useful!

  8. lovell commented on Aug 28, 2020

    @lovell
    Owner

    @willemmulder PRs are always welcome, if you're able.

  9. willemmulder commented on Aug 28, 2020

    @willemmulder

    @lovell Not just yet, unfortunately. I'm just getting started, and looking for a way to stitch together a bunch of smaller images. I previously implemented things in jimp but now started to look into Sharp because jimp was so memory-hungry (using >2GB for stitching 196 small images).

  10. willemmulder commented on Sep 3, 2020

    @willemmulder

    @lovell Is there a way in Sharp to make raw calls to libvips? So I could call the arrayjoin function through Sharp?

  11. ddmy commented on Dec 2, 2021

    @ddmy

    请问一下,多张图片合成一张gif或webp动图这个功能支持的进度怎么样了? @lovell

  12. lovell commented on Mar 15, 2022

    @lovell
    Owner

    For those who haven't yet rolled their own composite() based approach to this, it's been pointed out in #3137 (comment) that there's a similar solution in the form of https://github.com/ccpu/join-images that provides most of the logic for you whilst you wait for this feature.

  13. uriesk commented on Jun 22, 2022

    @uriesk

    Maybe this join() could instead be part of the constructor? So it could be used for further manipulation.
    i.e.:

    const image = sharp([
        [image1, image2],
        [image3, image4]
      ], {
      join: {
        background: '#fff',
        halign: 'centre',
        shim: 10
      },
      raw: {
        width: 128,
        height: 128,
        channels: 3
      }
    }).resize(256).png().toFile(filename);

    I tried for hours to get the best solution (combining a 4x4 grid and resizing) and anything based on composite() was very slow.
    Reading all tiles into seperate raw buffers and combining them in node into a large Uint32Array and resizing and saving the result with sharp was more than twice as fast as the best composite() test i did.

    I might try to fork it and hack together something that works for my usecase, but my c++ is rusty and i doubt that i can make a good contribution.

  14. lublak commented on Sep 27, 2022

    @lublak

    I don't know if it fits here but I am interested in it. Joining several frames as a gif :)

  15. mayeaux commented on Oct 24, 2022

    @mayeaux

    I like the API offered here: https://github.com/ccpu/join-images#readme

    Except using this join-images module is kind of annoying so I would hope that we can just do it natively with sharp someday. In the meantime though I will continue to use join-images as a separate module 😕

  16. Sanjotarm commented on Nov 2, 2022

    @Sanjotarm

    But the join-images module supports only single page files/images merge (stitches the images), but If I use it for multipage tiff files merge, it didn't work. It would be great if we could get native sharp API to merge multi-page tiff files (each file can have multiple pages) into a single file.

  17. willemmulder commented on Mar 7, 2024

    @willemmulder

    The https://github.com/ccpu/join-images repo is deprecated these days. Is there any update on this feature in sharp natively? Thanks :-)

  18. added this to the v0.34.0 milestone on Feb 4, 2025
  19. lovell commented on Feb 7, 2025

    @lovell
    Owner

    Commit 5ab9168 adds the ability to join an array of input images to the work-in-progress hat branch.

    I've updated my original comment at #1580 (comment) to reflect the API as it has been implemented.

    This will be part of the future v0.34.0 release.

    Here's an example of what will be possible, in this case creating an animated GIF and PNG grid from emoji text.

    const emoji = ['😀', '😛', '😘', '😉'];
    
    const images = emoji.map((text) => ({
      text: { text, width: 128, height: 128, channels: 4, rgba: true }
    }));
    sharp(images, { join: { animated: true } })
      .gif({ delay: Array(images.length).fill(1000) })
      .toFile('out.gif');

    GIF

    sharp(images, { join: { across: 2 } })
      .toFile('out.png');

    PNG

  20. Jeanno commented on Feb 8, 2025

    @Jeanno

    @lovell Love it. Until now I have been using v0.29 to create animated images from long toilet paper roll of frames. Cheers

  21. ivanbarlog commented on Mar 6, 2025

    @ivanbarlog

    Hi @lovell we've been struggling with @deftomat with animated images for quite some time. We've figured that we need to pass pageHeight to the raw function and then read it from baton because it is not possible to set pageHeight in gif anymore.

    We were thinking where to put the setting and we wanted to create pull request but then we noticed your comment from a month ago.

    This new API looks great and is possibly exactly what we need.

    Can you provide any information regarding releasing v0.34.0?

    Could you possibly release some alpha/beta so we can test it?

    Thank you for your response in advance!

  22. lovell commented on Mar 7, 2025

    @lovell
    Owner

    @ivanbarlog Please subscribe to #4248 for updates about v0.34.0.

  23. lovell commented on Apr 4, 2025

    @lovell
    Owner

    v0.34.0 now available, thanks to those who helped test this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions