How to work with GIF files in Squeak
Last updated at 9:16 pm UTC on 25 August 2016
Question: How do you store a GIF file in Squeak? What class does a GIF file belong to?
Answer: From: How to save a parts bin Sent: Wednesday, January 07, 2004 11:33 PM
A ".gif" file doesn't belongs to a class.
A String naming a GIF file can be opened as a FileStream.
The GIF data can be read from a FileStream.
The GIF data from the FileStream can be used to create a Form.
The Form can be written to a FileStream.
Question: How do you find out information about a GIF file in Squeak? Such as the date when it is produced, the author who created it.
Question: How to read it in other applications in Squeak.
Answer: To find out the answer to this and other questions in Squeak:
- Use the browser, and search for classes with gif in their names: We find AnimatedGIFReadWriter and GIFReadWriter
- Use the Message Names tool, and search for methods with gif in their names: We find exportasGIF, fromGIFFileNamed: httpGif: and httpShowGif:
- Look at the class side methods in GIFReadWriter and ImageReadWriter, its parent class.
- We see that we can say:
GIFReadWriter formFromFileNamed: 'myFile.gif'
- which returns a Form (try it in a Workspace, and then inspect the result) or
GIFReadWriter putForm: someForm onFileNamed: 'anotherFile.gif'.
- which saves a Form to a file. Now you can browse the Form class to see what you can do with them.
- One thing that I do all the time to see if things are working is to say:
- Which will make an ImageMorph with the form.
Question: I have a picture named "person.gif" in disk. Now I want to read it into Squeak and save it as an instance object of a class "Photo".
Answer:From: goran.krampe Sent: Monday, January 12, 2004 4:54 AM
First I searched for a class ("find class" in browser) with "gif" in them. Found "GIFReadWriter", then looked at the class side (to see how to create one) - not much there. Ok, let's look up the inheritance - looked in ImageReadWriter. Found method formFromFileNamed:. Ok, tested to do inspect it on this:
ImageReadWriter formFromFileNamed: 'image.gif'
Where I had 'image.gif' in the working directory. Ok, it worked and I can see an instance of a ColorForm. Ok, so the class Form and ColorForm etc are the classes for bitmap images in Squeak. This is the instance you would hold in an instvar in your "Photo" class.
Let's see how to see the darn thing on the screen. I knew that there are Morph classes for this so I quickly found SketchMorph and ImageMorph, don't remember the details on differences. Anyway, ImageMorph has a method to change the Form that it shows - so let's just create one, smack in the Form and show the morph in the world:
| aForm |
aForm := ImageReadWriter formFromFileNamed: 'BuildingSBlog.gif'.
ImageMorph new newForm: aForm; openInWorld
Question: How can export a ".gif" file for the current project interface just like that a morph can be exported a ".gif" file.
Answer: From: Ned Konz, To export, the current project:
writer _ GIFReadWriter on: (FileStream newFileNamed: Project current name, '.gif').
writer nextPutImage: Project current thumbnail; close.
How can I export an animated GIF file? (of all projects).
FAQ: How can I give my Morphic world a wallpaper?