Открыть gif в python

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

GIF decoder/encoder in pure Python

License

qalle2/pygif

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Читайте также:  Python com port send

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

GIF utilities in Python. Not to be confused with the other pygif.

A GIF decoder in pure Python. Notes:

  • supports interlaced images
  • only extracts the first image from a file
  • uses a lot of RAM
usage: gifdec.py [-h] [-v] input_file output_file Convert a GIF file into a raw RGB image file. positional arguments: input_file GIF file to read. Only the first image will be read. output_file Raw RGB image file to write. Format: 3 bytes (red, green, blue) per pixel; order of pixels: first right, then down; file extension '.data' in GIMP. options: -h, --help show this help message and exit -v, --verbose Print more info. 

A GIF encoder in pure Python. Notes:

  • doesn’t support interlaced images
  • always one image per file
  • uses a lot of RAM
usage: gifenc.py [-h] [-r] [-v] input_file width output_file Convert a raw RGB image file into a GIF file. positional arguments: input_file Raw RGB image file to read. Format: 3 bytes (red, green, blue) per pixel; order of pixels: first right, then down; file extension '.data' in GIMP. 256 unique colors or less. width Width of input_file in pixels. output_file GIF file to write. options: -h, --help show this help message and exit -r, --no-dict-reset Don't reset the LZW dictionary when it fills up. May compress highly repetitive images better. -v, --verbose Print more info. 

Print the high-level structure of a GIF file. Argument: file to read.

Example (a looping animated GIF with two frames and a comment):

$ python3 gifstruct.py test-in/anim.gif Header: file offset: 0 version: 89a Logical Screen Descriptor: file offset: 6 width: 29 height: 9 original color resolution in bits per RGB channel: 3 pixel aspect ratio in 1/64ths: unknown has Global Color Table: yes Global Color Table: file offset: 13 colors: 4 sorted: no background color index: 2 Extension: file offset: 25 type: Application identifier: NETSCAPE authentication code: 2.0 Extension: file offset: 44 type: Comment data: two frames with the words 'first' and 'second' Extension: file offset: 94 type: Graphic Control delay time in 1/100ths of a second: 100 wait for user input: no transparent color index: none disposal method: unspecified Image Descriptor: file offset: 102 x position: 0 y position: 0 width: 29 height: 9 interlaced: no has Local Color Table: no LZW data: file offset: 112 palette bit depth: 2 data size: 40 Extension: file offset: 155 type: Graphic Control delay time in 1/100ths of a second: 100 wait for user input: no transparent color index: 2 disposal method: unspecified Image Descriptor: file offset: 163 x position: 0 y position: 0 width: 29 height: 9 interlaced: no has Local Color Table: no LZW data: file offset: 173 palette bit depth: 2 data size: 46 Trailer: file offset: 222 
  • test-in/*.gif : test images for the decoder; encoded with GIMP (some images are from Wolfenstein 3D and Doom by id Software)
  • test-out/raw-md5.txt : MD5 hashes for correctly-decoded test images
  • test-dec.sh : test the decoder using the test images
  • test-enc.sh : test the encoder using the images created by test-dec.sh

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to open gif file in python 3, anybody knows a perfect method, please do a favour on me #3292

How to open gif file in python 3, anybody knows a perfect method, please do a favour on me #3292

Comments

What did you do?

What did you expect to happen?

What actually happened?

What versions of Pillow and Python are you using?

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.

The text was updated successfully, but these errors were encountered:

Источник

How to show a GIF animation image in Tkinter – Python

In this blog, we will see how we can insert a GIF into a GUI using Python.
We will be using the Tkinter library for this purpose.
Tkinter library is the de-facto library of Python for GUI creation.
The use of GIF makes our content more eye-catching and creative.

Python program to show GIF image animation in Tkinter

#importing library from tkinter import * #creating window window = Tk() #Title window.title('Grand Canyon') #display attributes canvas = Canvas(window, width = 500, height = 500) canvas.pack() #GIF in my_image variable #Give the entire file address along with the file name and gif extension #Use \\ in the address #The image given by me is C:\\UserAdmin\\Device\\Desktop2\\canyon.gif my_image = PhotoImage(file='FIle Location\\Filename.gif') canvas.create_image(0, 0, anchor = NW, image-my_image)

Code Explained

After importing the library Tkiner which we intend to use, we create a window and give a title to it.
The window and title commands are a part of the Tkinter library which is meant for GUI creation.
Then the code orients the display and formatting of size and structure are done.
A variable is chosen and a GIF is loaded onto it using the PhotoImage function. This is done by proving the complete path to the image along with the name and extension.
\\ are used as per Python format.

Output

How to show a GIF animation image in Tkinter - Python

The above is the screenshot only. So it is not showing the animation output.

Background

GIF stands for Graphics Interchange Format.
It was developed in mid-1987.
Once the use of GIF was considered unprofessional and not of much use.
Today it is widely used in creating a lot of moving images in the world of graphic content creation.
This is because the quickly catch the eye and are easily sharable.
Unlike the JPEG format, the gif format does not lose its quality. It uses lossless compression to preserve the image quality and keep it intact.
It is usually used when there are larger areas of uniform color and the total color number is lesser than the figure of 256.
They can be played by a mere click on them.

Источник

PyQt show gif

PyQt can display (animated) Gifs using QMovie. In this article we will show you how to do that.

It is straightforward how to do that and you can display a multiple of gifs if you want to.

Animated gif with PyQt

Import a GIF file using QMovie and display it on a label. QMovie is a class for playing movies, but it can also play (animated) gifs.

The program below displays an animated gif (earth.gif).
Screenshot is a frozen shot, but gif is animated and plays in the window.

pyqt animated gif

You can add the full path to the gif or have it in the same directory as your program.

from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QMovie import sys class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(250, 250) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") # create label self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(25, 25, 200, 200)) self.label.setMinimumSize(QtCore.QSize(200, 200)) self.label.setMaximumSize(QtCore.QSize(200, 200)) self.label.setObjectName("label") # add label to main window MainWindow.setCentralWidget(self.centralwidget) # set qmovie as label self.movie = QMovie("earth.gif") self.label.setMovie(self.movie) self.movie.start() if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(window) window.show() sys.exit(app.exec_())

Code Analysis

Load the required modules

from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QMovie

Set up your Python PyQt window

MainWindow.setObjectName("MainWindow") MainWindow.resize(250, 250) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget")

Create a label for the gif to be displayed in

# create label self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(25, 25, 200, 200)) self.label.setMinimumSize(QtCore.QSize(200, 200)) self.label.setMaximumSize(QtCore.QSize(200, 200)) self.label.setObjectName("label")

Add the label you created to the window

# add label to main window MainWindow.setCentralWidget(self.centralwidget)

Then load the gif, add it to the label and play it

# set qmovie as label self.movie = QMovie("earth.gif") self.label.setMovie(self.movie) self.movie.start()

Источник

Оцените статью