5

I'm using GraphicsMagick (1.3.16) and im4java (1.4.0) to create thumbnails of GIFs. At the command line I can do something like:

convert original.gif -coalesce -resize 100x100 +profile * thumb.gif

and the thumbnail is created successfully, preserving the animation. But something in my app isn't translating because the seemingly identical/similar command:

- -coalesce -resize 100x100 +profile * gif:- 

creates a thumbnail capturing just a single image of the animation. Note: the input is piped in and output captured as a BufferedImage.

If it helps, here is the code block used to create the above cmd I'm using:

public static BufferedImage createThumb(byte[] imageFileData)
{
  GMOperation op = new GMOperation();
  op.addImage("-"); // input: stdin
  op.coalesce();
  op.resize(100, 100);
  op.p_profile("*");
  op.addImage("gif:-"); // output: stdout

  ConvertCmd cmd = new ConvertCmd(true); // use GraphicsMagick

  // Pipe the fileData to stdin, to avoid writing to a file first.
  ByteArrayInputStream bais = new ByteArrayInputStream(imageFileData);
  Pipe pipeIn = new Pipe(bais, null);
  cmd.setInputProvider(pipeIn);

  // Capture output from stdout into an image.
  Stream2BufferedImage s2b = new Stream2BufferedImage();
  cmd.setOutputConsumer(s2b);

  // Run the command.
  cmd.run(op);

  // Return the resulting image.
  return s2b.getImage();
}

What am I missing?!

EDIT: Interestingly, when I change

op.addImage("gif:-"); // output: stdout

to

// Save the file instead of returning the bytes
op.addImage("gif:C:\\Pictures\\thumb.gif");

the image is properly created with the animation.

Also something I discovered is the byte[] length returned from s2b.getImage() is only 4,8777 bytes (gif as a single image) whereas the successfully created gif thumb using the direct file path is 190,512 bytes which leads me to believe the problem is with certain settings of the command / stream.

Ariana A.
  • 61
  • 2

0 Answers0