What's the easiest way to generate a bitmap using Python?
Text support would be nice but not required.
(On Mac, I was trying to use Quartz through Python, but Snow Leopard seems to have broken its functionality. Therefore I've decided to look for a solid, simple, cross-platform solution that won't break each time the OS is updated.)
Use the Python Imaging Library:
"The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities."
I'm not a Mac person so I can't help with Mac specifics, but I do know it works on the Mac.
Related
For image processing I tend to use python to speed up my workflow. But what if there is missing functionality and you only find a library written in c++?
For this special case, one could write a c++ extension and import it in python. The extension relies on openCV which would be bundled into the extension. But python can already use openCV on its own. So I would end up with 2 versions of openCV in my programm. Is there a way around this?
I am not sure I understand what you mean. So you have a third library with C++ that has some functionality which is lacking in OpenCV. You then want to talk to this library in Python together with the Python API from OpenCV. The extension you linked is just a way to include python in a C++ program and does not necessarly need OpenCV. Does the third library use OpenCV as well?
In general you can say:
If you do not modify OpenCV you do not need two versions. You install one and just have to make sure that another library that uses OpenCV as well links to the version you have used in the Python API when you build it.
If you do modify OpenCV you should build it yourself with your changes and then use the Python API from this self build OpenCV to be used in your applications.
I want to import a png using tkinter. I have seen many tutorials to use PhotoImage but it does not accept the .png file format. Moreover, I cannot use Pillow as this program is for use in my school and my school only has the modules that come with python. Can someone suggest a way to do this?
Tkinter only supports 3 file formats off the bat which are GIF, PGM, and PPM. You will need to convert the files to .GIF then load them in using tkinter.
There are libraries such as Python Imaging Library (PIL), however it might not be allowed in your school to use it.
Hopefully your school allows Photoshop, GIMP or any image editing software to allow you to convert, but I am sure there are plenty of online programs.
I'm using win32com with python to generate Automated PowerPoint pptx files.
My scripts are generally ran on window based machines.
Apparently, because I'm using win32com my scripts wouldn't work on other hardware/Operating systems - Max/Linux/other.
Is this really the case? if so, is there a solution?
When you use win32com, you are communicating with Windows programs, in this case PowerPoint.
So, no, it won't work without the Windows program, which means it typically won't work without Windows, although you might be able to make it work if you install PowerPoint on WINE and then use the Windows version of Python with it. There was a question and answer about this technique here:
automating excel with win32com on linux with wine
Other options (that don't require installing PowerPoint on Linux) include automating a cross-platform package like OpenOffice/LibreOffice, or (since you're using Python) using restructuredText and S5 to create slides.
Edit: As Tris Nefzger points out above, there is a cross-platform Python package designed specifically for creating PowerPoint slides, as well.
I know this is possible to do using additional libraries such as win32com or python-pptx, but I wasn wondering if anyone knew of a way to insert an image into a powerpoint slide using the standard libraries. Lots of googling has indicated that the best solution is probably win32com, but since I can guarantee that every system this script will be deployed to will have win32com, I am looking for an implemention leveraging libraries all systems with a standard python 2.7 install will have.
It is probably possible to modify a .pptx file with the standard library without much effort: these new generation of files are meant to be zip-compressed XML + external images files, and can be handled by ziplib and standard xml parsers.
Legacy .ppt files however are a binary closed format, with little documentation, and hundrededs of corner cases. It would alwasys "be possible" to change them, since they are still just bytes, but it would take considerable effort.
That said, starting with Python 3.4, the Python installer "PIP" comes default with the language install: probably the best way to go would be to script the installation of external libraries based on the built-in PIP - that way one would not have to all external library usage.
I have this question in my head for over a year now. And I guess you guys may have the answer.
In some Python GUI app, I need to display a video stream.
I need to record some part of this stream to reread it later.
Moreover, I need to make this python application multi platform (OSX, GNU, Windows)
I am open to many solutions :
Connect the camera to a stream and read the stream with the python app. (RTP + VLC could do the trick)
Use Phonon to read the camera
Create an abstract class to define differents reader and use Quicktime, Win32 or GStreamer in function of the OS.
What is your experience, what would you use to do that ?
I've looked into this periodically as well, and it seems the complexity of the underlying task is just too high to have a simple shortcut abstraction library for your topic question. I would suggest using pyopencv for the specific task you articulate, however. It has a class for webcam input/capture which works across platforms and has a reasonable user-base, in python, posting examples. The latest is 2.3.1 and quite recent. You can get a windows version of it, compiled for you, on the unbelievably helpful site (not mine, just saying):
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Since you ask for experience with a few libraries, I'd say: gstreamer worked for me on linux but was a huge pain to setup on windows and didn't work for me. This was quite some time ago and perhaps it's working better now. vlc.py is a simple library to test and see whether vlc would work for you. It doesn't work on 64 bit windows platforms at the moment; not sure why, but it seems many have reported similar errors, so it depends on how much cross-platform support you need.
Unfortunately, this is not easy to do. I've written most of a program that does video recording/playback on the 3 major desktop OS's. The state of video playback/recording in a "out-of-the-box" way is still unsolved for cross-platform, other than HTML embedding. This has a lot to do with the fact that:
Codecs are proprietary
OS's don't support common codecs
ffmpeg and similar projects have licenses that require you to release your source code if you include them in certain ways
A lot of the video playback players that exist are each rewritten by hand to handle each frame, buffering, streaming, audio sync'ing, and the like.
So you can go with HTML, or you can suffer through the cross-platform issues with the following coding libaries:
Python mplayer
Python vlc
Python opencv
Python pyaudio
Python pyside/pyqt phonon or qtmultimedia
Once you get it working on one development machine, expect it to break when it comes to installation on the end-user machine (distribute via: pyinstaller / appdmg / apt / chocolatey / Inno Setup )
On OSX, brew still has a lot of issues with this, but macports works better (I still had to do a lot of patching)
Linux is by far the easiest.
Windows is in-between the to as far as difficulty
I'd be eager to hear how iOS / Android / Windows RT / Kindle are
The problem is not unique, as even Netflix has yet to have a cross-platform video app: https://www.quora.com/Is-Netflix-building-an-app-for-the-Mac-App-Store?share=1