GraphicsMagick(1.3.16)とim4java(1.4.0)を使用してGIFのサムネイルを作成しています。コマンドラインで、次のようなことができます。
convert original.gif -coalesce -resize 100x100 +profile * thumb.gif
サムネイルは正常に作成され、アニメーションは保持されます。しかし、一見同一/類似のコマンドであるため、私のアプリの何かが翻訳されていません:
- -coalesce -resize 100x100 +profile * gif:-
アニメーションの単一の画像のみをキャプチャするサムネイルを作成します。注:入力はパイプインされ、出力はBufferedImageとしてキャプチャされます。
それが役立つ場合は、私が使用している上記のcmdを作成するために使用されるコードブロックを次に示します。
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();
}
何が足りないの?
編集:興味深いことに、私が変更すると
op.addImage("gif:-"); // output: stdout
に
// Save the file instead of returning the bytes
op.addImage("gif:C:\\Pictures\\thumb.gif");
画像はアニメーションで適切に作成されます。
また、私が発見したのは、s2b.getImage()から返されるbyte []の長さがわずか4,8777バイト(単一の画像としてのgif)であるのに対し、直接ファイルパスを使用して正常に作成されたgifサムは190,512バイトであり、問題は、コマンド/ストリームの特定の設定にあります。