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

Tiff doesn't support buffer #103

Open
dungvt opened this issue Nov 16, 2017 · 11 comments
Open

Tiff doesn't support buffer #103

dungvt opened this issue Nov 16, 2017 · 11 comments
Assignees
Milestone

Comments

@dungvt
Copy link

dungvt commented Nov 16, 2017

Hi all,
I can see some previous issued, and i know, tiff image was suppot from buffer.
But, to day, i get error, that say: "Tiff doesn't support buffer" when try to get dimenstion of a tiff image.
I'm using newest version (0.6.1) from npm https://i.imgur.com/vSqORFQ.png

My code:
var dimensions = sizeOf(response.Body);

response.Body is buffer of tiff image, i get it from amazon s3

What is wrong in here?
Can you help me on this case?

@netroy netroy self-assigned this Nov 29, 2017
@netroy netroy added this to the 1.0.0 milestone Dec 16, 2017
@Neijin
Copy link

Neijin commented Sep 24, 2018

Same here !

@c060604
Copy link

c060604 commented Dec 12, 2018

I use a dng file, it also throw out the same error.

@netroy
Copy link
Member

netroy commented Dec 12, 2018

@c060604 dng are raw files. I've created a separate issue for that #136

@geogeim
Copy link

geogeim commented May 25, 2021

same issue here
i think the library is designed to work with partial data in buffer mode (i.e. get the size of the picture by reading a few bytes) which is not supported because the tiff code needs the size of the file. but in my case i know that my buffer is complete so it would be nice to find a way of working with tiff files without dropping them to disk. it would probably need to change the api interface somehow and that sucks

@netroy
Copy link
Member

netroy commented May 27, 2021

@geogeim it's the other way around. Tiff isn't supported when using the async api for files. but if you already have an entire tiff file in buffer, you can pass the buffer to imageSize function, and it'll work.
Dumping the buffer to disk is not going to help, as this library doesn't want to load entire files into buffer itself.
Loading full tiff files in a buffer, and passing that buffer, is the only way tiff files are supported.

@wildansupernova
Copy link

@geogeim it's the other way around. Tiff isn't supported when using the async api for files. but if you already have an entire tiff file in buffer, you can pass the buffer to imageSize function, and it'll work. Dumping the buffer to disk is not going to help, as this library doesn't want to load entire files into buffer itself. Loading full tiff files in a buffer, and passing that buffer, is the only way tiff files are supported.

hi @netroy , I already try using imageSize instead of getImageSize, the error still happen, is there any workaround for this?

@netroy
Copy link
Member

netroy commented Nov 3, 2021

@wildansupernova can you please share the code with us?

@wildansupernova
Copy link

wildansupernova commented Nov 3, 2021

@wildansupernova can you please share the code with us?

thanks for replying @netroy

here the example repo https://github.com/wildansupernova/image-size-test-tiff-error , you can try the error

import * as fs from 'fs';
import { imageSize } from "image-size";
function streamToBuffer(stream): Promise<Buffer> {
    return new Promise<Buffer>((resolve, reject) => {
      const bufferArray: Uint8Array[] = [];
      stream
        .on("data", (chunk) => {
          bufferArray.push(chunk);
        })
        .on("error", (error) => {
          reject(error);
        })
        .on("end", () => {
          const content = Buffer.concat(bufferArray);
          resolve(content);
        });
    });
  }

const runExample = async () => {
    const result = fs.createReadStream("0d63278b-ec67-41d9-b156-88e65d4edacb.tiff");
    const buffer = await streamToBuffer(result)
    const dimensions = imageSize(buffer)
    console.log(dimensions);
}

runExample()

my error
image

let me know your though about this

@netroy
Copy link
Member

netroy commented Nov 3, 2021

@wildansupernova TIFF don't support streams or buffers (yet).
please try something this instead:

import { promisify } from "util"
import { imageSize } from "image-size"
const sizeOf = promisify(imageSize)

const runExample = async () => {
  const dimensions = await sizeOf("0d63278b-ec67-41d9-b156-88e65d4edacb.tiff")
  console.log(dimensions)
}

runExample()

@wildansupernova
Copy link

@netroy ok, thanks for the clarification

@ryanhugh
Copy link

Any update with this? Would love to be able to support TIFF images from a buffer.

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

No branches or pull requests

7 participants