Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5947955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:02:19+00:00 2026-05-22T17:02:19+00:00

When trying to read data in Node.js from an ImageMagick child process, it comes

  • 0

When trying to read data in Node.js from an ImageMagick child process, it comes out corrupted.

A simple test case would be the following:

var fs = require('fs');
var exec = require('child_process').exec;

var cmd = 'convert ./test.jpg -';
exec(cmd, {encoding: 'binary', maxBuffer: 5000*1024}, function(error, stdout) {
  fs.writeFileSync('test2.jpg', stdout);
});

I would expect that to be the equivalent of the command line convert ./test.jpg - > test2.jpg that does write the binary file correctly.

Originally there was a problem with the maxBuffer option being too small and resulting in a truncated file. After increasing that, the file now appears slightly larger than expected and still corrupted.
The data from stdout is required to send over HTTP.

What would be the correct way to read this data from the ImageMagick stdout?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:02:20+00:00Added an answer on May 22, 2026 at 5:02 pm

    There were two problems with the initial approach.

    1. The maxBuffer needs to be high enough to handle the whole response from the child process.

    2. Binary encoding needs to be properly set everywhere.

    A full working example would be the following:

    var fs = require('fs');
    var exec = require('child_process').exec;
    
    var cmd = 'convert ./test.jpg -';
    exec(cmd, {encoding: 'binary', maxBuffer: 5000*1024}, function(error, stdout) {
      fs.writeFileSync('test2.jpg', stdout, 'binary');
    });
    

    Another example, sending the data in an HTTP response using the Express web framework, would like this:

    var express = require('express');
    var app = express.createServer();
    
    app.get('/myfile', function(req, res) {
      var cmd = 'convert ./test.jpg -';
      exec(cmd, {encoding: 'binary', maxBuffer: 5000*1024}, function(error, stdout) {
         res.send(new Buffer(stdout, 'binary'));
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple map reduce job that would read in data from the
I'm trying to read data from a.csv file to ouput it on a webpage
I am trying to read data from excel files using datatable. The command select
I'm trying to read data from SQL Server database using Perl and the DBI
I am trying to read data from an RS-232 port. Does anyone have an
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I am trying to read data from a bluetooth barcode scanner (KDC300) using C.
I'm trying to read the data in a Win32 ListView owned by another process.
I'm trying to read binary data from a specific offset. I write the data
I'm trying to read EXIF data from pictures taken with the apple camera's application,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.