InterviewSolution
| 1. |
Solve : [Python] Add frame to gif image? |
|
Answer» So I have code that takes 2,000,000+/- 1,000,000 coordinates and creates images of lines between them (consecutively). I want to make these images into a gif file for easy viewing. Unfortunately, there are too many of them to load into MEMORY at once, so I am trying to create a gif with the first 2, then add on each image at the end. I've looked into creating gif's with the images2gif library. I'm running into an issue where when I write the gif, instead of adding to it, it replaces what already exists (I believe). a gif file for easy viewing.For easy viewing It has to fit on a standard monitor. How many pixels would a image of two million points take? A screen shot of this monitor takes about 64,000 bytes in 256 colors. So my question is: Why does it take so much memory to create a GIF file? Im trying to make a gif where you can watch where your mouse went. The points i mentioned are the points read in through a different script. When i said easy viewing, i ment that you cant really look at either the log file or make 2,000,000 jpg FILES, it just isnt a good way of doing it.For a simple graphic, you want to use GIF, not JPG. But even GIF has a structure that might not seem obvious. Have you seen this? Project: What's In A GIF - Bit by Byte[/url Quote A GIF file is made up of a bunch of different "blocks" of data. The following diagram shows all of the different types of blocks and where they belong in the file. The file starts at the left and works it's way right. At each branch you may go one way or the other. The large "middle" section can be repeated as many times as needed. (Technically, it may also be omitted completely but i can't imagine what good a GIF file with no image data would be.)Python is often used to create animated GIF files. There is a library for a simple GIF. http://svn.effbot.org/public/pil/Scripts/gifmaker.py Sorry I am no help with the code. Quote I'm running into an issue where when I write the gif, instead of adding to it, it replaces what already exists (I believe). The Images2Gif library takes a series of images to create a GIF out of. It does not do anything special if one of those frames is a GIF image- they are treated the same. a PIL.Image instance loaded with a GIF can be seeked and different frames read, but the Images2GIF library treats it like any other image, so it will end up creating a new GIF image that comprises of the first frame of the GIF, and whatever frame you are trying to add. Arguably I'm not even sure if Images2Gif did this it would solve your problem. If it was smart enough to see a GIF and then seek out all the frames as images to add to the new GIF, all of those frames will be in memory. I expect you would have to manage the file yourself- find the end terminator, then the last Graphics Control Extension block (for the last frame) and insert a encoded GIF Frame at that position, which is easier said than done, really. |
|