Convert jpg frames to gif

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Posts: 1
Joined: 2015-12-08T01:30:31-07:00
Authentication code: 1151

Convert jpg frames to gif

Post by TonyShkurenko » 2015-12-08T01:47:28-07:00

Sorry, if I chose wrong place, but I didn't found something for Java in ImageMagick program Interfaces (viewforum.php?f=15)
I'm trying to implement gif encoder using ImageMagick port for Android ( But there's no tutorial or even JavaDocs. Here's amount of other ports:, They are pretty old, but seems like they have same API.
I've read almost all code and found every public method trying to solve this question, but still it doesn't work. I created an issue ( ... -162647820) and an question on the StackOverflow ( ... egs-to-gif).
Any help would be appreciated. Here is my code (convert method):

Code: Select all

final List<MagickImage> frames = new ArrayList<>();

for (final String bitmapPath : bitmapPaths) {
  final MagickImage image = new MagickImage(new ImageInfo(bitmapPath));
  final QuantizeInfo quantizeInfo = new QuantizeInfo();
  quantizeInfo.setTreeDepth(4); // 8 is max

Timber.v("Frames: %s", frames.toString()); // first test log
final MagickImage[] images = frames.toArray(new MagickImage[frames.size()]);
final MagickImage finalGif = new MagickImage(images);
finalGif.setDelay(FRAME_FREQUENCY / 10);
finalGif.setIterations(1000); // temp, want to make infinity loops
Timber.d("Is animated: %b", finalGif.isAnimatedImage());
Timber.d("Has frames: %b, number of frames: %d", finalGif.hasFrames(),
final ImageInfo resultInfo = new ImageInfo(path);
Timber.d("Result path: %s", resultInfo.getFileName());
//finalGif.writeImage(resultInfo); // it doesn't write to the file
final byte[] img = finalGif.imageToBlob(resultInfo);
Timber.d("Image bytes count: %d", img.length);, path);

Post Reply