I'm trying to write some code to resize gif animation
it seem to me that some calculations just went wrong.
here is two cases:
first image is this:
http://img21.imageshack.us/img21/1600/polarbranme0.gif
original page size is 80x60
i resize it to 40x30 (in my code and also) using convert as follows: (without coalesce)
convert -resize 40x30 polarbranme0.gif p.gif
now I'm scnning the frames in the gif:
the second frame size for example was originaly 59x51 and its offset was originaly x=11,y=7
after resize it became size: 35x30 offset x=7,y=4. the page size is 40x30.
the values seem a little out of proportion the the change. and the animation is disformed.
if I need to guess the right values it should be: size = 29(30)x25(26) ofset x=5(6),y=3(4)
when I use coalesce the animation look good. (but I guess the size is still lose proportion)
second image is:
http://img210.imageshack.us/img210/7350/23520972.gif
original page size is: 57x108
i resize it to: 28x54
it change the page size to 31x59 (I expect it to be 28x54)
the first frame size was originaly 51x99 and became 28x54 (I expect it to be: 25x45)
the animation still look good.
but when I use coalesce (I guess because the first image is not the biggest) it getting some black frame at the right & bottom.
so, my questios are:
1. is the gif animation consider as the size only the first frame size? (not page size?)
2. sholdn't resize keep thing in proportin no matter I use coalecse or not?
3. sholdn't coalecse add to first image it own background color as the extra size instead of black (or transparent)?
4. I guess now image magick can resize gif animation properly only with coalesce and only when the first frame size is equal page size, am I right?
EDIT:
I managed to make it work for me with coalesce
here is a solution thet work for both: (but still I think something is going wrong with resize calculations...)
Code: Select all
void resize6(const char* fin, const char* fout,const char* size)
{
cout<<"resize\n";
vector<Magick::Image> mvImages;
Magick::readImages(&mvImages,fin);
Magick::Geometry newSize(size);
Magick::Geometry oPage = mvImages[0].page();
if(mvImages[0].rows() < oPage.height() || mvImages[0].columns()< oPage.width()){
cout<<"resizing first frame\n";
Magick::Color oEgdeColor = mvImages[0].pixelColor(mvImages[0].columns()-1, mvImages[0].rows()-1);
mvImages[0].extent(oPage);
mvImages[0].floodFillColor(oPage.width()-1, oPage.height()-1,oEgdeColor);
}
for_each( mvImages.begin(), mvImages.end(),Magick::filterTypeImage(Magick::CubicFilter));
Magick::coalesceImages(&mvImages,mvImages.begin(),mvImages.end());
for_each( mvImages.begin(), mvImages.end(), Magick::resizeImage( newSize ) );
Magick::writeImages(mvImages.begin(), mvImages.end(), fout);
}
Thanks in advance,
S.A.