Skip to content

Instantly share code, notes, and snippets.

View prateekjoshi565's full-sized avatar
🎯
Focusing

Prateek Joshi prateekjoshi565

🎯
Focusing
View GitHub Profile
# Resize the foreground image to 960x720 pixels
plot_img = plot_img.resize((960, 720))
# Paste the foreground image again onto the background image at a different position (60, 1000)
combined_image.paste(plot_img, (60, 1000))
# display combined image
plt.figure(figsize= (12, 8))
plt.imshow(combined_image);
# create a sample data
x = [5, 7, 3, 6, 9]
y = [7, 3, 5, 8, 2]
# create a scatter plot
plt.scatter(x, y)
plt.title("My Plot")
# convert the matplotlib plot to an image
buf = io.BytesIO()
# Draw the text on the image
text_draw.text(text_position, text_message, fill=text_color, font= text_font)
# Combine the background image and text image
combined_image = Image.alpha_composite(background_image.convert("RGBA"), text_image)
# display combined image
plt.imshow(combined_image);
# Create a new image to draw the text on
# The size of this image is same as that of the background image
text_image = Image.new("RGBA", background_image.size, (0, 0, 0, 0))
# Set up the text drawing parameters
text_draw = ImageDraw.Draw(text_image)
text_color = (255, 255, 255)
text_position = (120, 600)
text_message = "Hello World"
text_font = ImageFont.truetype("arial.ttf", 144)
# Paste the foreground image again onto the background image at a different position (660, 250)
background_image.paste(foreground_image, (660, 250))
# display image
plt.imshow(background_image);
# Paste the foreground image onto the background image at position (120, 250)
background_image.paste(foreground_image, (120, 250))
# display image
plt.imshow(background_image);
# Resize the foreground image to 300x300 pixels
foreground_image = foreground_image.resize((300, 300))
plt.imshow(foreground_image);
# load the background image
background_image = Image.open("bg_image.jpg")
# load the foreground image
foreground_image = Image.open("logo.png")
# dislay background image
plt.imshow(background_image);
from PIL import Image, ImageDraw, ImageFont
import matplotlib.pyplot as plt
import io
# generate video
create_video_from_images("/images", "out.mp4")