0

I'm writing an application to leverage this library into a general purpose image resizing utility

Have it working with local files, attempting to update it with http streams.

Looks like in theory its resize wrapper will take a srcData object, which I assume can be a Buffer object, but my app is choking.

Here's a simplified version:

im = require('imagemagick')
request = require('request')

sampleImage = "http://www.ibm.com/developerworks/data/library/techarticle/dm-0504stolze/test_1.jpg"

request.get(sampleImage, (err, res, body) ->

    taskHash = {
        srcPath: "-"
        srcData: body
        dstPath: "-"
        height: 100
    }

    callback = (err, stdout, stderr)->
        if err
            console.error(err)
            process.exit(1)
        console.log(stdout)

    im.resize(taskHash, callback)

)

This is erroring out:

{ [Error: Command failed: convert: no decode delegate for this image format `/var/tmp/magick-37627o1E7kWz7yGaf' @ error/constitute.c/ReadImage/555.
convert: no images defined `-' @ error/convert.c/ConvertImageCommand/3144.
] timedOut: false, killed: false, code: 1, signal: null }

which makes me think that it's having trouble identifying the Buffer as a a jpg object. But even if I explicitly declare the buffer as a jpg in the options hash, it still gives me the same error:

taskHash = {
    srcPath: "-"
    srcData: body
    dstPath: "-"
    format: 'jpg'
    height: 100
}

Not sure how to pass this in as a correct Buffer object.

fox
  • 5,569
  • 3
  • 16
  • 13

1 Answers1

2

The error message is saying that it doesn't know the format of the image. According to the ImageMagic docs, you can specify the format in the srcPath argument, such as gif:-.

The best way to find the format of the HTTP response is in the Content-Type header, as it may not be a part of the url.

Phssthpok
  • 1,629
  • 1
  • 14
  • 21
  • The `srcPath` prefix worked, I guess that the `format` option only designates output. – fox Sep 06 '14 at 03:37