Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use vips_arrayjoin from sharp? #1580

Open
NDevTK opened this issue Feb 16, 2019 · 17 comments
Open

Is it possible to use vips_arrayjoin from sharp? #1580

NDevTK opened this issue Feb 16, 2019 · 17 comments

Comments

@NDevTK
Copy link

NDevTK commented Feb 16, 2019

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

@lovell
Copy link
Owner

lovell commented Feb 17, 2019

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

I recommend spawning a vips child process to do this right now - see #1175 (comment)

The general use case for image stitching suggests this could be exposed via a utility function that would provide a "join" operation/pipeline only so e.g. no resizing at the same time.

👇 PROPOSED API, NOT YET IMPLEMENTED OR AVAILABLE

sharp
  .join([
    [image1, image2],
    [image3, image4]
  ], {
    background: '#fff',
    halign: 'centre',
    shim: 10,
    animated: true,
  })
  .toBuffer()
  .then( ... )

☝️ PROPOSED API, NOT YET IMPLEMENTED OR AVAILABLE

...where image1 are either filenames or Buffer objects (no Streams). Note also that a 2D array should probably be passed in (to be flattened internally to the 1D array expected by vips_arrayjoin. When animated is used, ensure array produces "toilet-roll" image and set page height etc.

@NDevTK
Copy link
Author

NDevTK commented Feb 17, 2019

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

@NDevTK
Copy link
Author

NDevTK commented Feb 17, 2019

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

@lovell
Copy link
Owner

lovell commented Feb 18, 2019

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

Only shared libraries are included, no executable files.

@NDevTK
Copy link
Author

NDevTK commented Feb 22, 2019

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

@lovell
Copy link
Owner

lovell commented Feb 22, 2019

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

@willemmulder
Copy link

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

@lovell
Copy link
Owner

lovell commented Aug 28, 2020

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

@willemmulder
Copy link

@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).

@willemmulder
Copy link

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

@ddmy
Copy link

ddmy commented Dec 2, 2021

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

@lovell
Copy link
Owner

lovell commented Mar 15, 2022

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.

@uriesk
Copy link

uriesk commented Jun 22, 2022

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.

@lublak
Copy link

lublak commented Sep 27, 2022

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

@mayeaux
Copy link

mayeaux commented Oct 24, 2022

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 😕

@Sanjotarm
Copy link

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.

@willemmulder
Copy link

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

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

No branches or pull requests

8 participants