question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot get imageConvert to work

See original GitHub issue

Hi,

I’m trying to get a custom image converter working, but it does not seem to get called. I’m trying to write the image out to a file. If I also change the return src to be “dataxxxxxxxx”, the resulting output still just shows “data:”

Here is my code. Any thoughts would be appreciated.

    var options = {
        path: dir + "/sig.docx",

        convertImage: mammoth.images.inline(function(element) {
          return element.read("base64").then(function(imageBuffer) {

            fs.writeFile(dir + "/image.jpg", imageBuffer, function(err) {
                if(err) {
                    console.log(err);
                } else {
                    console.log("The file was saved!");
                }
            }); 

            return {
                src: "dataxxxxxxx:" + element.contentType + ";base64," + imageBuffer
            };
          });
        })
    };        

    mammoth.convertToHtml(options).....

Thanks Gary.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oninrosscommented, Sep 18, 2017

What was happening was that it was converting the images to base64 and doing it inline, which is great! But I believe we would like to have an option as well to save the images as a file and put it in the directory. I dont think its advisable to base64 all images of a word doc

0reactions
mwilliamsoncommented, Sep 19, 2017

You can do this using your own image converter. Take a look at the one the CLI uses for an example.

https://github.com/mwilliamson/mammoth.js/blob/eaefb859906c56e44c6a0ae4efeb407cf92a8e7d/lib/main.js#L27

On Mon, 18 Sep 2017 16:02:01 -0700 Nino Ross Rodriguez notifications@github.com wrote:

What was happening was that it was converting the images to base64 and doing it inline, which is great! But I believe we would like to have an option as well to save the images as a file and put it in the directory. I dont think its advisable to base64 all images of a word doc

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't get simple JPEG convert to work - Legacy ImageMagick ...
Can't get simple JPEG convert to work ... I have ImageMagick working on the command line (although it didn't until I added the...
Read more >
Can't get image thumbnailing to work / ImageMagick 7
Images and image uploading work fine, but we can't get image thumbnailing to work. I've installed ImageMagick 7 on the host machine ...
Read more >
Imagemagick convert: Can't get -pointsize to use a calculated ...
I've confirmed that the pointsize option itself does work when setting a static value, e.g. convert image.jpg -pointsize 30 -annotate 0 ' ...
Read more >
Can't get ImageMagick -fft to execute in Command Prompt
I downloaded ImageMagick (Windows 7 64-bit) and FFTW, and I can do simple commands but I can't use the -fft option. Commands are...
Read more >
Emacs is compiled with imagemagick and has right PATH but ...
The best "solution" I was able to find was to use the "emacs-mac" port of emacs (https://github.com/railwaycat/homebrew-emacsmacport):
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found