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

Pass mimetype when input is Buffer #174

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

elrumordelaluz
Copy link

@elrumordelaluz elrumordelaluz commented Oct 16, 2019

First, thanks for this great Library!

Working with this cool Library (congrats and thanks!) in node.js, in particular making responsimage I found that the image (input) value could be not only a path string to the image but also a Buffer, since the url argument:

It can be a relative path, an http url, a data url, or an in-memory Buffer.

And this is cool, and sound coherent when working in node.
But in this scenario I found that the second argument type is needed:

type is an optional mime type for the image (required when using a Buffer)

So made this PR to fix that part, adding the relative test. Keep in mind that I didn't include the /dist with bundled files. I added this folder to let use my repo as the packages source in the meanwhile (otherwise, some projects are broken)

Let me know in any case and thanks again for this great Library!

elrumordelaluz added a commit to elrumordelaluz/responsimage that referenced this pull request Oct 16, 2019
Since pass a Buffer into getColor() need to wait until
[this PR](lokesh/color-thief#174) will be merged
@AdamSantanielloVP
Copy link

AdamSantanielloVP commented Dec 2, 2019

Any update on when this pull request can be merged and released? This update would be immensely helpful.

@ghost
Copy link

ghost commented Apr 1, 2020

same issue (I think), I get Invalid file type (https://github.com/scijs/get-pixels/blob/b389ffc3408b1be50f63fe8bd0837f17a48f1f27/node-pixels.js#L137)

I made it working for me with the follow patch (dist only) and pass it as [buffer, type] to getColor

diff --git a/node_modules/colorthief/dist/color-thief.js b/node_modules/colorthief/dist/color-thief.js
index 2833cec..1fe5714 100644
--- a/node_modules/colorthief/dist/color-thief.js
+++ b/node_modules/colorthief/dist/color-thief.js
@@ -48,13 +48,20 @@ function validateOptions(options) {
 
 function loadImg(img) {
     return new Promise((resolve, reject) => {
-        getPixels(img, function(err, data) {
-            if(err) {
+        let params;
+        if (Array.isArray(img)) {
+            params = img;
+        } else {
+            params = [img];
+        }
+        params.push(function (err, data) {
+            if (err) {
                 reject(err)
             } else {
                 resolve(data);
             }
-        })
+        });
+        getPixels(...img)
     });
 }
 

@bjarkih
Copy link

bjarkih commented Oct 1, 2020

A vote from me. I'm having to fork the library because this is missing from the current code base.

@ghost
Copy link

ghost commented Oct 1, 2020

You could use https://www.npmjs.com/package/patch-package if you don't want to fork, like I did for my patch above

@WandersonAlves
Copy link

Bump

@m-soli
Copy link

m-soli commented Jan 13, 2021

any news when this is going to get merged ?

@ronanyeah
Copy link

Bump

@Enchiridion
Copy link

Bump. I already have the image in a Buffer after doing processing through sharp. I'd rather not write it to a temp file just so it can be read back.

@arbazsiddiqui
Copy link

Bump

2 similar comments
@Dituon
Copy link

Dituon commented Dec 17, 2022

Bump

@hroland
Copy link

hroland commented Feb 23, 2023

Bump

@ppjjzz
Copy link

ppjjzz commented Jul 7, 2023

any update?

@EvanZhouDev
Copy link

Please merge, we need this!

@YahiaBakour
Copy link

Can someone merge this damn PR

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

Successfully merging this pull request may close these issues.