Page 1 of 1

unable to convert to tif using stdout to BufferedImage

Posted: 2011-02-11T11:17:11-07:00
by gjones99
I'm trying to convert a png to a tif file in memory (without writing the file to the file system) and am getting the "unable to write blob" error. Thinking that it has something to do with not deleting tmp files.

Windows 7 Enterprise
Version ImageMagick-6.6.7-Q16

You can duplicate the error message at the command line in image magick by trying to convert the .png file to a tif in stdout. (Probably not a great test, but if you try doing the same thing as a .jpg, it streams the output to the screen)

02/10/2011 02:58 PM 3,711 ScanCompressedThumbNailImage.png

C:\EVO\E360\E360Batch\src\test\resources\images>convert ScanCompressedFullPageImage.png "tif:-"
Magick: unable to write blob `-': Not enough space @ error/blob.c/ImageToFile/1662.


I'm using im4java and this is where I initially received the error message. Here is my java code: Note if I try writing the image to the file system by uncommenting the code below, the file is written to the os with no problems.

Code: Select all

     public  byte[] convertPngToTifImage(byte[] fullPagePNGImage) throws IOException, InterruptedException, IM4JavaException {
   	File output = new File("src/test/resources/images/ScanCompressedFullPageImage.png");

        IMOperation op = new IMOperation();
        op.addImage(); //place holder for input file
//        op.addImage(output.getAbsoluteFile().toString()); // used to verify that a file can be written to the file system.
        op.addImage("tif:-"); // output: stdout
        
        ConvertCmd convert = new ConvertCmd();
        Stream2BufferedImage s2b = new Stream2BufferedImage();
        convert.setOutputConsumer(s2b);

        // run command and extract BufferedImage from OutputConsumer
        convert.run(op, fullPagePNGImage );
        BufferedImage img = s2b.getImage(); 
   
        return img;

Anyone seen this behavior or have a work around?

Re: unable to convert to tif using stdout to BufferedImage

Posted: 2011-02-11T13:21:53-07:00
by magick
This works for us:
  • convert logo: tif:- > logo.tif
    identify logo.tif
Does that work for you? We need to determine if the problem is specific to your image (ScanCompressedFullPageImage.png).

Re: unable to convert to tif using stdout to BufferedImage

Posted: 2011-02-11T13:54:49-07:00
by gjones99
That should work for you, it also works for me, there is not a problem with that command and my image is fine. I can convert a png to a physical tif file all day long. However, I am trying to avoid writing actual files to the file system when running the convert command.

Here is the background:
The png and tif images we are dealing with are stored in a sql database. We are reading multi-page tif files in, breaking them out into full page png images and thumbnails and display them dynamically on web pages on the fly. The user can select one or more png images and then we convert them to a multi-page tif image that is then saved directly in the database. The image is not written to the file system at that time.

So when working with these images, I'm trying to avoid writing files to the file system, as in your example. I'm using a third party java api (im4java) to call the image magick commands. That was the code that was in the previous post, but don't let that distract you. The error is coming from image magick.


Run this command and you will see the error!
convert yourImage.png "tif:-"


This command appears to be outputting the jpg to the screen .
convert ScanCompressedFullPageImage.png "jpg:-"

I know I shouldn't be running the above commands under normal circumstances, however, it is the easiest way to duplicate the error.

Re: unable to convert to tif using stdout to BufferedImage

Posted: 2013-06-02T11:39:30-07:00
by veeramarni
Was this fixed? I am having the same issue.

Re: unable to convert to tif using stdout to BufferedImage

Posted: 2013-06-02T12:45:11-07:00
by fmw42
I do not think you can do this without stuff going to the terminal

convert rose: tif:-

It is sending to std out but no place to get received but the terminal

but you can do pipe to std in and then process it further.

convert rose: tif:- | convert - rose.tif

or

convert rose: tif:- > /dev/null