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)
Related
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.
I am new to python and I am using python 3.4.3 and Pillow for reading text from image. Image has white background with text in black.
The problem is when I am re-sizing image("captcha1.png") with MS Paint and using tesseract to read the text, everything works fine. But when I am re-sizing image with python(using pillow, code following), nothing happens.
im1 = Image.open("captcha1.png")
width, height = im1.size
im2 = im1.resize((int(width*5), int(height*5)), Image.ANTIALIAS)
im2.save("captcha2.png", dpi=(600.0,600.0))
I also tried
im2.save("captcha2.png", quality=95)
Using following to parse image:-
subprocess.call(['C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe', 'G:\\python\\captcha2.png', 'out', '-psm', '8'])
If I see image properties of re-sized images by Paint and python, both seem same (i.e. of 96dpi, same dimensions, sizes differ by ~2kb though).
Can someone help?
Also, I did a little bit of research and it seems 96dpi is too small for OCR, but I can't figure out why is everything working fine with image re-sized with paint?
I have an image in JPEG which contains a solid black circle on top of a solid black inverted equilateral triangle.
Upon application of Python PIL Image class, function thumbnail, resizing from 500*500 to 100*100 the shape of the image components change from (circle+triangle) to (rectangle+rectangle), almost looks like the android icon now.
Any ideas why this is happening? I'm guessing this is an algorithm issue.
Here's the code:
im = Image.open('E:/asdsa/aret/sdfssdf/media/edasdaas1d0-1.jpeg')
im.thumbnail((100,100), Image.ANTIALIAS)
im.save('E:/asdsa/aret/sdfssdf/media/11.jpeg')
Try
im.save('E:/asdsa/aret/sdfssdf/media/11.jpeg', quality=90)
Anyway, it's better to use Pillow.
Also, for solid colors jpeg format might not be the best choice. PNG is a better solution.
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!
I am trying to increase the height of an image using PIL but I don't want the image to be resized; I actually want a strip of blank pixels at the bottom of the image. Any way of doing this with PIL?
I guess one way would be to make a new image of the required size and copy the old image into it but I can't seem to find the right function to do this.
Oops, just realized you can do image.crop() and it will resize the image for you.