The is not perfect so feel free to fork and improve it. It is using the thumbnail method of Pillow rather than the resize method as I found the resize method did not work. Using BigglesZX's script, I have created a new script which resizes a GIF using Pillow. When I open the gif file from my computer, the entire gif lasts about 1.5 seconds. Imgur made it slower (and converted it to mp4). Gif after processing ( out.gif) (I could not add it to Stack Overflow ). ![]() The gif speed is increased and the gif does not loop. I am not sure that the resize method works, as out.gif is still 7.5MB. The new gif is now saved and works, but there is 2 main problems : I've been saving all the frames together: img.save("out.gif", save_all=True, optimize=True). ![]() I have been resicing each frame individually: frame.resize((frame.size // 2, frame.size // 2), Image.ANTIALIAS) Running 2to3 -w gifextract.py makes that script compatible with Python 3. It is useful to note that this is a Python 2 script, and my project is written in Python 3 (I did mention that detail initially, but it was edited out by the Stack Overflow Community). I am using BigglesZX's script to extract all frames. Would you know how I can use Pillow to decrease the size of my GIF while keeping all of its frames?įollowing Old Bear's response, I have done the following changes: I've been thinking about calling resize() on im.seek() or im.tell() but neither of these methods return an Image object, and therefore I cannot call resize() on their output. im = im.resize((im.size // 2, im.size // 2), Image.ANTIALIAS) # should decrease its size If I add the following line, then only the first frame of the GIF is saved, instead of all of its frame. Im.save("out.gif", save_all=True, optimize=True, quality=10) # should decrease its quality Im.seek(im.tell() + 1) # loads all frames The following piece of code even makes the out.gif bigger than the initial gif: im = Image.open("my_gif.gif") With a GIF, though, it does not seem to work. Im.save("out.jpg", optimize=True, quality=85) # decreases its quality Im = im.resize((im.size // 2, im.size // 2), Image.ANTIALIAS) # decreases width and height of the image With JPEG, the following piece of code is usually enough so that large image drastically decrease in size. Resize it so its height / width is smaller Again I am aware of the resize method but it is Image classes method.I have a gif that I would like to resize with pillow so that its size decreases. If an image comes sized bigger than that I want to shrink it to my window.Is there a possible way to do that? Have been looking for docs for a time but all I saw was about Image class not ImageTk. ![]() I don't get errors from this code but like I said I want my window size stay 500x500. # I have tried all of the comment rows above in this for loop but could notįoto_label= tk.Label(fotoframe,image=img)įoto_id(row=0,column=0,columnspan=3) ![]() Img.append(imobject)# record is definitely binary data I'm looking for. #base64_encoded= base64.b64encode(record) Records=cursor.execute(sql_fetch_blob_query) Sql_fetch_blob_query = """SELECT * from foto """ Here is the code: mydb= nnect('customers.db') So the question is how to resize an ImageTk.PhotoImage object to desired size so that I can display every image without thinking how big they are. So far so good but when it comes a large sized image I have to resize the window all the time. When user click that button it displays an image which stored in db file as binary-BLOB. In it there is a button that says show photos. I'm making a GUI with Tkinter and Sqlite.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |