GIF image is distorted when weaving

Distorted GIF

I have several images that were converted using Imagemagick and its interlaced operation. These were animated GIFs . The problem is that the images are distorted during the conversion, and I do not have the original images with me, as it was the previous developer who did a wonderful thing. GIF no longer animates, and each frame has 4 copies of the same frame with reduced sizes. I did not work on Imagemagick anymore.

Is it possible to restore the original image from a distorted version?

Used command:

convert <old-file.gif> -interlace plane <new-file.gif>

thanks

+1
source share
1 answer

interlaced GIF images are saved as 4 separate images

  • containing every eighth line of the image (1/8 of the size)
  • containing each missing fourth line of the image (1/8 of the size)
  • containing any missing even line of the image (1/4 of the size)
  • containing each odd line of the image (1/2 size)

This is done so that the image can be seen when downloading via a slow Internet connection ... an increase in detail with each new fragment ...

So, if your image looks like 4 very similar images, then the result will be OK, you simply decode it incorrectly, or GIF did not set the interlace flag.

If your file no longer contains animation frames, you are out of luck, but if they are, and not rendering, then check that the end of the GIF file is not set in place or does not check the flags that they could ruin ... you tried another GIF viewer (some of them are erroneous)

[Edit1] after decoding your gif

You have GIF89a , and you are missing interlaced flags in each frame. Thus, the image alternates correctly, but the viewer believes that it is not interwoven at all ... You need to mark the interlaced flag in each title of the frame.

 struct _img // this is image frame header { // Logical Image Descriptor BYTE Separator; /* Image Descriptor identifier 0x2C */ WORD x0; /* X position of image on the display */ WORD y0; /* Y position of image on the display */ WORD xs; /* Width of the image in pixels */ WORD ys; /* Height of the image in pixels */ BYTE Packed; /* Image and Color Table Data Information */ } img; img.Packed|=64; // this will set the interlaced flag 

To do this, you need to decode / copy the GIF, which is not as simple as it seems.

cm

Here is the result of the frames copy + deinterlace + interlaced encoding (skipping control / information / auxiliary channels ...)

corrected image

+2
source

Source: https://habr.com/ru/post/1272109/


All Articles