Image not able to show in Google colab using PIL library - python

from PIL import Image
visa_file='/content/visa-logo-mastercard.jpg'
img_visa= Image.open(visa_file,mode='r')
img_visa.show()
I am not getting the output of the image in Google colab.
Also the output of type(img_visa) is 'PIL.JpegImagePlugin.JpegImageFile'.
So the image object has been created, but the image is not displaying. And I only want to use PIL to show Image. How to do this?

Just
img_visa
is enough. You don't need
img_visa.show()
To be more explicit, you can use
display(img_visa)

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/

Enlarge picture using Pillow package keep ratio

I am trying to use python pillow package to enlarge picture and here is my try
from PIL import Image
image = Image.open('Sample.jpg')
new_image = image.resize((1080, 1080))
new_image.save('Output.jpg')
The code is working but the output image loses completely the ratio. How can I enlarge the image without losing the quality?
What you're talking about is image upscaling, which is a more complex problem just than enlarging the image. I recommend looking into image upscaling packages. A lot of them use CNNs for this.

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?

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 GIF animation, pil/imagemagick, 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!

Categories

Resources