pygame: full image support images - python

I want to use .png images in pygame but it requires full image support. How do I do this?
Also, what are some image formats that I can use in pygame that doesn't need full image support?

The Pygame documentation for images explicitly says
The image module is a required dependency of Pygame, but it only optionally supports any extended file formats. By default it can only load uncompressed BMP images.
So, I suppose you should run
pygame.image.get_extended() # returns a bool
to check if you can load images of other extensions. If not, I suppose you will need Python imaging libraries to be installed to get extended file formats to be supported by Pygame.
OR, you could always convert the images to BMP to avoid the hassle.

Related

How to show PIL Images as a movie?

I get continuously PIL Images, using while True loop, and want to show them as a movie.
I can show an image by img.show(), but this code inside the loop makes multiple windows.
Would you tell me the way to display them as a movie?
I think the easiest way is to use ImageMagick in the command line to great a .gif file with the following command, assuming your image files are named something like image-1.png, image-2.png:
sudo apt-get install imagemagick
convert -delay 20 -loop 0 image-*.png my_movie.gif
This will create a my_movie.gif in the same directory where your images are located.
Another way to create a movie from frames is to use Blender, an open source program based on Python. I don't think Pillow supports creating gifs or movie files directly; every solution I have seen involves some other library, so I think the best way is to go with a simple command line tool.

How to create thumbnail from videos using Python

My video formats are jpeg,yuy2 etc.Need to convert into thumbnails. Is there a default size for thumbnail.
You can use ffmpeg to work with videos (converting, thumbnail creation, ...). There is a good package to work with ffpmeg in python named python-video-converter. You can have control over each parameter using ffmpeg. Also using great Pillow package on python, you can manipulate images easily.

Combine images as frames to make a video with Python

I'm looking for a Python library that can combine images into a video.
A library that just allows you to create an empty video and feed images into it as frames is ideal.
Preferably with support for MPEG compression of the video file as well.
If you run linux then you can use ffmpeg to do this from the command line there is a python wrapper called pyFFmpeg that you can use - there is also pymedia but it doesn't look to be maintained.
BTW there are a number of projects that provide builds of ffmpeg for windows.
gstreamer is the tool you are looking for. you'll probably need an appsrc or something like that.

Is there a way to manipulate a icon file with Python?

Ok, so I have Python 2.5 with Windows XP. I want to create a program that will create and/or manipulate an icon (.ico) file. Is there any module that can do this? Thanks.
EDIT:
I will need to save the image back into a .ico file.
Try the Python Image Library or PIL for short. Also, take a look at this plug in for PIL that makes it handle images correctly on windows: http://code.google.com/p/casadebender/wiki/Win32IconImagePlugin
There is also this: pythonMagick

Converting a PDF to a series of images with Python

I'm attempting to use Python to convert a multi-page PDF into a series of JPEGs. I can split the PDF up into individual pages easily enough with available tools, but I haven't been able to find anything that can covert PDFs to images.
PIL does not work, as it can't read PDFs. The two options I've found are using either GhostScript or ImageMagick through the shell. This is not a viable option for me, since this program needs to be cross-platform, and I can't be sure either of those programs will be available on the machines it will be installed and used on.
Are there any Python libraries out there that can do this?
ImageMagick has Python bindings.
Here's whats worked for me using the python ghostscript module (installed by '$ pip install ghostscript'):
import ghostscript
def pdf2jpeg(pdf_input_path, jpeg_output_path):
args = ["pdf2jpeg", # actual value doesn't matter
"-dNOPAUSE",
"-sDEVICE=jpeg",
"-r144",
"-sOutputFile=" + jpeg_output_path,
pdf_input_path]
ghostscript.Ghostscript(*args)
I also installed Ghostscript 9.18 on my computer and it probably wouldn't have worked otherwise.
You can't avoid the Ghostscript dependency. Even Imagemagick relies on Ghostscript for its PDF reading functions. The reason for this is the complexity of the PDF format: a PDF doesn't just contain bitmap information, but mostly vector shapes, transparencies etc.
Furthermore it is quite complex to figure out which of these objects appear on which page.
So the correct rendering of a PDF Page is clearly out of scope for a pure Python library.
The good news is that Ghostscript is pre-installed on many windows and Linux systems, because it is also needed by all those PDF Printers (except Adobe Acrobat).
If you're using linux some versions come with a command line utility called 'pdftopbm' out of the box. Check out netpbm
Perhaps relevant: http://www.swftools.org/gfx_tutorial.html

Categories