0

I am using imagemagick DLL (Refer: http://www.imagemagick.org) for the resize image,
But when I re-sized animated GIF image then it going screw.

I using below code for re-size image ( image type are png, gif, jpg, bmp, tif ...)

ImageMagickObject.MagickImage imgLarge = new ImageMagickObject.MagickImage();
 object[] o = new object[] { strOrig, "-resize", size, "-gravity", "center", "-colorspace", "RGB", "-extent", "1024x768", strDestNw };
imgLarge.Convert(ref o);

How can I fixed it. see the result image enter image description here

Abhishek B.
  • 5,112
  • 14
  • 51
  • 90

1 Answers1

3

I think you have to extract every single frame from the gif first, resize every single frame and then put it back together.

Edit: like this? Not tested nor builded...

int maxFrames=32;
ImageMagickObject.MagickImage imgLarge = new ImageMagickObject.MagickImage();  

// first extract all frames from gif to single png files
for(int frame=0; frame<maxFrames;frame++)
{
   object[] o = new object[] { String.Format(strOrig+"[{0}]", frame)
       ,  String.Format("tmp{0}.png", frame) };
   imgLarge.Convert(ref o);    
}
// resize every single png files
// add resized filenames to stringbuilder
StringBuilder filenames = new StringBuilder();
for(int frame=0; frame<maxFrames;frame++)
{
   object[] o = new object[] { String.Format("tmp{0}.png", frame)
                , "-resize"
                , size 
                , "-gravity"
                , "center"
                , "-colorspace"
                , "RGB"
                , "-extent"
                , "1024x768"
                , String.Format("tmp-resized{0}.png", frame) };
   filenames.Append(String.Format("tmp-resized{0}.png", frame));
   filenames.Append(Environment.NewLine);
   imgLarge.Convert(ref o);    
}
// write resized filenames to file
File.WriteAllText("tmp-resized-files.txt", filenames);
// create resize animated gif based on filenames in the tmp-resized-files.txt
   object[] o = new object[] { "@tmp-resized-files.txt"
       ,  strDestNw };
   imgLarge.Convert(ref o);    
rene
  • 41,474
  • 78
  • 114
  • 152
  • How can I do? with collect every single frame and merge it.. have you any code? – Abhishek B. Feb 09 '11 at 04:50
  • I'm not sure how to do it, I only scanned the commandline reference to figure if it would be possibke at all. From the commandline this can be done: check your link. If it is available on the .Net dll i'm not sure. – rene Feb 09 '11 at 11:32
  • @Abhisek your pushing it :-) I updated my answer, beaware that I didn't test it (nor did I build it/compile it) so there might be a few glitches but I leave that to you. – rene Feb 09 '11 at 13:59