Python 2D image generation - python

What are some of the better libraries for image generation in Python? If I were to implement a GOTCHA (for example's sake), thereby having to manipulate an image on the pixel level, what would my options be? Ideally I would like to save resulting image as a low-resolution jpeg, but this is mere wishing, I'll settle for any common image format.
Thank you for your attention.

The Python Imaging Library (PIL) is the de facto image manipulation library on Python. You can find it here, or through easy_install or pip if you have them.
Edit: PIL has not been updated in a while, but it has been forked and maintained under the name pillow. Just install it this way in a shell:
pip install Pillow
The import statements are still the same as PIL (e.g., from PIL import image) and is backward compatible.

Pillow is a fork of PIL that is still actively developed. While PIL is not dead it has been a number of years since the last release.

If you should generate text or other vector based images (and then save to .png or .jpg), you could also consider Cairo (PyCairo, in this case). I use it a lot.
Otherwise, for pixel-level manipulation, PIL is the obvious choice.

Related

Informations about adding image to a video

I'm trying to add an image to a pre-existing video in python. I haven't write any code yet, but I've done some research. Most of people seem to use OpenCV or ffmpeg to manipulate image and video.
So my questions are :
Can we add images to video with OpenCV or ffmpeg?
Can we do that without OpenCV or ffmpeg
If yes, do you have some informations on it
If no, should I use OpenCV or ffmpeg ? Maybe another ?
Which version of OpenCV should I use ? and why ?
I've read that they are a problem with OpenCV and Ubuntu, did they correct it ?
If you have some other informations or advice for me
In OpenCV you could extract all the frames from the video and then use the VideoWriter class to create a new video from the frames plus your extra images. One issue I’ve had in the past using VideoWriter is using the correct video codec, you will have to do some research on this and see what’s compatible with your particular setup.
https://docs.opencv.org/3.2.0/dd/d9e/classcv_1_1VideoWriter.html
You may be able to do something similar with PIL (Python Imaging Library) although I’m not entirely sure on that. As for ffmpeg I’m also not sure.
The latest release of OpenCV would be sufficient for this. I currently have OpenCV 3.4 with Ubuntu 16.04 LTS on a Virtual Machine and I have no problems using the VideoWriter class. Have a look at this blog post for advice on installing OpenCV on Ubuntu.
https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/

How to Scale images in Django

Background:
I have to upload images from users.
Problem:
The images need to be re-sized so that I don't end up with huge images on my disk. This re-sizing should happen just after the image is saved.
I have checked the following code
Django Snippet for image scaling
But couldn't use it directly, as the windows path of the image was giving a issue. Is there a simple way in which the scaling can be done. Are there any python or django modules which can directly be used for this ?
If yes which will be the most optimized one ?
Make use of the Python PIL library. With this library you can manipulate images and make the changes you require. There are loads of examples of using PIL over the net.
I would recommend you using the PIL library and writing your own code as it can be a lot easier than trying to get third party libraries working (personal experience).

PIL SANE interface: where can I find it?

Apparently PIL includes a SANE (Scanner Access Now Easy) interface - I'm looking at code right now that does
import sane
where sane is provided by PIL.
I've installed PIL under both OS X and Windows, but "import sane" doesn't work for me. I did a fair bit of googling to see if there's something extra I need to install but I'm not finding anything.
How do I get the SANE interface for PIL?
I'm happy with any SANE interface (doesn't have to be PIL), so if you know of an alternative that would help too.
Disclaimer: I never used SANE.
I don't think that sane is provided with the PIL library.
It seems, instead, that the package you're looking for is called pysane.

Manipulate WebP images in Python

I'm looking for something like PIL (Python Imaging Library), which sadly doesn't support WebP images.
I'd like to be able to do resizes and crops. Or at least convert to JPEG and then I can work it with PIL.
Take a look at:
http://code.google.com/p/python-webm/
I was able to walk through the test file to see how they were doing it.
imagemagick's convert tool, version 6.5.7-8 or better, can manipulate WebP images.
Also, Google provides an encoder and decoder for Linux, Windows and Mac OS X.

CImg Python 3 bindings or something at least comparable?

i'm searching a Python lib with good image processing functionalities .
I was searching for CImg (which i've already used on C++ projects) bindings, but i wasn't lucky.
I found PIL, but it lacks a lot of features that CImg has so, is there any good alternative ?
Thanks
UPDATE
PIL is good, but i need Python 3 support on a Mac OS X system.
I would suggest you to enumerate the functionality that you find desirable which is there in Cimg and not in PIL.
Discussion on SO
Image Processing, In Python?
pypi also throws up a lot of modules on image processing. Try seeing, if some of them is suitable for you.
http://pypi.python.org/pypi?:action=search&term=image+processing&submit=search

Categories

Resources