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

stream save_png to cout #175

Closed
carlinski opened this issue Dec 3, 2017 · 4 comments
Closed

stream save_png to cout #175

carlinski opened this issue Dec 3, 2017 · 4 comments

Comments

@carlinski
Copy link

I'm using the following code, which saves a CImg as png to disk, opens it, and streams it to console (fcgi).

It's working perfectly, but wondered if there was a way of doing this without saving it to disk?

img.save_png("test.png", 0);
std::ifstream image("test.png", std::ifstream::binary);

if (image)
{
    image.seekg (0, image.end);
    int length = image.tellg();
    image.seekg (0, image.beg);

    char * buffer = new char [length];
    image.read (buffer,length);
    image.close();

    for(int iPos = 0; iPos < length; iPos++)
    {
        std::cout << buffer[iPos];
    }

    delete[] buffer;
}
@dtschump
Copy link
Collaborator

dtschump commented Dec 4, 2017

You could try img.save_png("-.png"); to output the file on stdout.

@carlinski
Copy link
Author

Thanks, but it doesn't seem to to work. This is the code in CImg.h just to jog your memory. I also tried it with just a dash, and a dash dot.

const bool is_stdout = *filename=='-' && (!filename[1] || filename[1]=='.');

@dtschump
Copy link
Collaborator

dtschump commented Dec 4, 2017

Are you compiling with the support of libpng ?
Like : g++ -o out souces.cpp -lX11 -lpthread -Dcimg_use_png -lpng

If libpng is not used, CImg tries to use ImageMagick's convert as a fallback, to read png files.
Using libpng makes iI work for me.

@carlinski
Copy link
Author

OK, getting somewhere now. Yes, you were correct it needed libpng support.

Within my fcgi program, because the buffer has been captured to used std::cout whenever I write to it, it gets sent to the browser. Output from img.save_png("-.png"); is getting sent to the console. Is it using a different method of writing to the console?

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

2 participants