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

How to output a new image directly? #127

Closed
hylin opened this issue Mar 8, 2013 · 7 comments
Closed

How to output a new image directly? #127

hylin opened this issue Mar 8, 2013 · 7 comments

Comments

@hylin
Copy link

hylin commented Mar 8, 2013

I want to use gm to create a captcha and directly output to browser , that means, do not use "write" to output to disk. I tryed this(used gm buffer plugin , express):

gm(opts.width || 70, opts.height || 30, '#000')
    .font("arial", 20)
    .stroke("#fff", 2)
    .fill("#888")
    .drawText(10, 22, text)
    .buffer(function(err,buf){
      res.send(buf);
    });

but buf.length is 0.
Any suggest?

@duyleekun
Copy link

If res is input stream, this may suite you better

gm(opts.width || 70, opts.height || 30, '#000')
    .font("arial", 20)
    .stroke("#fff", 2)
    .fill("#888")
    .drawText(10, 22, text)
    .stream(function(err,stdout){
      stdout.pipe(res)
    });

@hylin
Copy link
Author

hylin commented Mar 15, 2013

@duyleekun

This is ok:

gm('./public/static/img/image.png')
      .font("arial", 20)
      .stroke("#fff", 2)
      .fill("#888")
      .drawText(10, 22, 'test')
      .stream(function(err,stdout){
        stdout.pipe(res);
      });

But this does not work:

gm(opts.width || 70, opts.height || 30, '#000')
    .font("arial", 20)
    .stroke("#fff", 2)
    .fill("#888")
    .drawText(10, 22, text)
    .stream(function(err,stdout){
      stdout.pipe(res)
    });

I tried to use gm create a new image and use "write" to save image to disk and this is ok.
Is there a bug in "gm" create a new image and output by stream?

@jonathanong
Copy link
Contributor

what happens when you do the second one?

@hylin
Copy link
Author

hylin commented Apr 9, 2013

@jonathanong nothing happened.no error occured and no image outputed.Like steam is empty.

@jonathanong
Copy link
Contributor

does the response end or does it just hang?

@hylin
Copy link
Author

hylin commented Apr 9, 2013

@jonathanong response is end,and nothing output to browser.

jonathanong added a commit that referenced this issue Apr 10, 2013
@jonathanong
Copy link
Contributor

no issues with gm. created a test for you: https://github.com/aheckmann/gm/blob/master/test/newImage.js. let us know if you can find a reproducible case.

no idea what could be going wrong with yoru code, maybe something like content type header.

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

3 participants