API Clarification
Posted: 2014-07-16T20:07:56-07:00
I'm trying to create an animated gif from a set of Magick::Image(s) that are "extracted" or cropped out from one big image.
The original "big.jpg" is 480×3200, it contains 5 frames or regions I'm interested in. After extracting/cropping the image(s) they are pushed into a vector. The vector is then used to write a gif using Magick::writeImages. The problem is that I'm ending up with a gif that is the same width/height i.e. "480×3200" which animates each extracted frame downwards. The result I was expecting was a 480x640 gif.
If I loop through the "frames" and write each image out to disk they look fine, "480x640", so each individual cropped out image is the correct size. What I'm not understanding is why the final gif is the wrong size with an odd animation.
One thing I tried that does work but feels wrong is doing another pass through all the frames, write out each image to a Blob, read it back into an Image and add it to a new "finalFrames" vector. This obviously increases memory usage.
Am I missing or not understanding the essential ImageRef concept?
Thank You in Advance.
The original "big.jpg" is 480×3200, it contains 5 frames or regions I'm interested in. After extracting/cropping the image(s) they are pushed into a vector. The vector is then used to write a gif using Magick::writeImages. The problem is that I'm ending up with a gif that is the same width/height i.e. "480×3200" which animates each extracted frame downwards. The result I was expecting was a 480x640 gif.
Code: Select all
Magick::Image originalImage ("big.jpg");
Magick::Geometry originalGeometry = originalImage.size();
vector<Magick::Image> frames;
const int frameHeight = 640;
for (int i = 0; i < originalGeometry.height(); i += frameHeight) {
Magick::Geometry geometry = Magick::Geometry (originalGeometry.width(), frameHeight, 0, i);
Magick::Image image = originalImage;
if ((int) (originalGeometry.width() - geometry.xOff()) < 1 || (int) (originalGeometry.height() - geometry.yOff()) < 1) {
continue;
}
image.crop (geometry);
frames.push_back (image);
}
Magick::writeImages (frames.begin(), frames.end(), "final.gif");
One thing I tried that does work but feels wrong is doing another pass through all the frames, write out each image to a Blob, read it back into an Image and add it to a new "finalFrames" vector. This obviously increases memory usage.
Code: Select all
vector<Magick::Image> finalFrames;
for (vector <Magick::Image>::iterator it = frames.begin(); it != frames.end(); ++it) {
Magick::Image image = *it;
Magick::Blob blob;
image.write (&blob);
Magick::Image newImage (blob);
finalFrames.push_back (newImage);
}
Magick::writeImages (finalFrames.begin(), finalFrames.end(), "final.gif");
Thank You in Advance.