Resize GIF animation, pil/imagemagick, python - python

I want to change size of GIF animation image using python and PIL or PythonMagick. I can't find solution. PIL and thumbnail method works for jpg and png but not for gif. ImageMagick has command mogrify/convert -resize '1280x1024>' but i can't find documentation and i don't know how to do it with pythonmagick.
Anyone knows solution?
In the worst case i use os/subprocess and convert ;-S
Thanks.

You can use PIL and images2gif, a short PIL based module linked to on this blog page, and available here. Code used to process this rose.gif is below. I set the images2gif.readGif 'read as numpy array' property to false in order to get a list of PIL images so as I could use the PIL thumbnail function.
Orignial: Processed:
import Image
import images2gif
frames = images2gif.readGif("rose.gif",False)
for frame in frames:
frame.thumbnail((100,100), Image.ANTIALIAS)
images2gif.writeGif('rose99.gif', frames)
I'm not sure how to preserve transparency, my attempts to do so have failed (so far).

Some amazing person made an updated version of images2gif.py that accounts for transparency:
https://bitbucket.org/bench/images2gif.py/overview
There are still some artifacts, but it's way better than the original!

Related

How can I achieve a photoshop "bevel / emboss" like depth effect using Python?

I want to place an image on top of a background-image and apply a "bevel/emboss" effect on the image using Python. I made an attempt using the PIL library but suggestions for other libraries are welcome too.
This is what it should look like:
I have the following code:
from PIL import Image
from PIL import ImageFilter
img = Image.open('./image.jpeg', 'r')
# this doesn't do what I want...
img = img .filter(ImageFilter.EMBOSS)
background = Image.open('./bg.png', 'r')
background.paste(img)
I used Affinity Photo for the example image. Should be pretty much the same in Photoshop. Here are the settings I used:
I still don't know how I can do this in python but I found a way around it using a combination of the the batch job and the macro functionality in Affinity Photo.
record a macro that applies the desired effect to an image
place all images that need the effect in a folder
start a batch job and apply the macro to all images
How to start a batch job is described here: http://www.millermattson.com/blog/batch-processing-with-affinity-photo/

Save Numpy array graphs and images as images

I cannot find a way to save my graphs and images. I have tried from
from PIL import Image
im = Image.fromarray()
im.save("your_file.jpeg")
but doesn't work!
Please format your code correctly, it is important for readability and python is intend-sensitive. Also, there is already a post for this problem:
How can I save an image with PIL?

Resize Image To Size of Other Image Python PIL

I have one image, and I have another image that I would like to resize to the size of the first image in python. I've attempted this in many different ways, all resulting in failure. How can I do this?
Some failed methods:
.thumbnail(), only works for a PIL image, which means it can't interact with SimpleCV images later on in the program
.resize(), when I used the arguments, it resulted in the error.
Alternate Solution:
Setting camera resolution, though I have no idea how to do this.
As the camera was the only object with an unknown size, I was able to set it like the following:
cam = camera(prop_set ={'width':width, height:'height'})

How to find the last modified png file using python or django

I want to find which file is last modified.
I am modifying or updating the 'png' image on each request.
For example: piechart.png is an image; I am modifying this same image to create a new image (having same image name 'piechart.png'). I will be saving & modifying 5 images: (piechart1.png,piechart2.png,... ,piechart5.png).
How can I find which image was modified last ?
Well, this doesn't really answer your question, but it come close.
What you can do, is first download the PIL module, or the Python Imaging Library.
After that, get it installed, and then do the following:
from PIL import Image
Jpeg = Image.open("Yourfile.jpg")
print(Jpeg.info, Jpeg.format, Jpeg.mode, Jpeg.size)
This gives you some of the properties of the photo.
The same thing you can do for PNG images.
For more information about using the PIL module and getting your desired results you can go here:
http://python.developpez.com/cours/pilhandbook/php/image.php
Hope this helps!

Resize animated GIF with PythonMagick

I'm using PythonMagick 0.9.3 (cannot switch to PIL) to resize images. It works fine for everything except for animated GIFs.
This is the way how I resize the images at the moment:
orig_image = Image('path/to/animated.gif')
orig_image.resize('..resize string..')
orig_image.write('path/to/thumbnail.gif')
Currently it only resizes the first image of the sequence so the image is no longer animated afterwards.
Does anyone have a workaround for my problem?
Thank you!
I suppose you have to iterate on all the images that compose the animation, resize them, and recompose the animation after like this (with example for PHP language)

Categories

Resources