Skip to content

Instantly share code, notes, and snippets.

@arifsuhan
Created January 6, 2023 17:41
Show Gist options
  • Save arifsuhan/09b99fe87d431782707961d322d3e3b6 to your computer and use it in GitHub Desktop.
Save arifsuhan/09b99fe87d431782707961d322d3e3b6 to your computer and use it in GitHub Desktop.
View Img, Gif, Video in Colab
file1="https://wallpaperaccess.com/full/1371433.jpg"
file2="https://i.giphy.com/media/KztT2c4u8mYYUiMKdJ/giphy.gif"
file3="https://i.giphy.com/media/UVk5yzljef0kGiayL1/giphy.mp4"

VMedia(file1).img()
VMedia(file2).gif()
VMedia(file3).video()
import requests
from PIL import Image
from io import BytesIO
from IPython.display import HTML
from IPython.display import Image as IPyImg
class VMedia:
def __init__(self,path):
self.path = path
def img(self):
resize_ratio = 0.5
response = requests.get(self.path)
img = Image.open(BytesIO(response.content))
width = int(img.size[0] * resize_ratio)
height = int(img.size[0] * resize_ratio)
img = img.resize((width,height), Image.ANTIALIAS)
return img
def gif(self):
return IPyImg(url=self.path)
def video(self):
return HTML(""" <video width=400 controls> <source src="%s" type="video/mp4"> </video> """ % self.path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment