This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import pandas as pd | |
import bs4 | |
import requests | |
import spacy | |
from spacy import displacy | |
nlp = spacy.load('en_core_web_sm') | |
from spacy.matcher import Matcher | |
from spacy.tokens import Span |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to read raw text file | |
def read_text(filename): | |
# open the file | |
file = open(filename, mode='rt', encoding='utf-8') | |
# read all text | |
text = file.read() | |
file.close() | |
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Resize the foreground image to 300x300 pixels | |
foreground_image = foreground_image.resize((300, 300)) | |
plt.imshow(foreground_image); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
NewerOlder