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
TonyShkurenko
Posts: 1
Joined: 2015-12-08T01:30:31-07:00
Authentication code: 1151

Convert jpg frames to gif

Post by TonyShkurenko »

Hello,
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 (https://github.com/paulasiimwe/Android-ImageMagick). But there's no tutorial or even JavaDocs. Here's amount of other ports: https://github.com/lilac/Android-ImageMagick, https://github.com/puelocesar/android-lib-magick. 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 (https://github.com/paulasiimwe/Android- ... -162647820) and an question on the StackOverflow (http://stackoverflow.com/questions/3408 ... 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.setNumberColors(256);
  quantizeInfo.setTreeDepth(4); // 8 is max
  image.quantizeImage(quantizeInfo);
  frames.add(image);
}

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.setImageFormat("gif");
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(),
    finalGif.getNumFrames());
final ImageInfo resultInfo = new ImageInfo(path);
Timber.d("Result path: %s", resultInfo.getFileName());
resultInfo.setMagick("gif");
//finalGif.writeImage(resultInfo); // it doesn't write to the file
final byte[] img = finalGif.imageToBlob(resultInfo);
Timber.d("Image bytes count: %d", img.length);

FileUtils.store(img, path);
Post Reply