automeme/pillow_fight.py

69 lines
4.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from PIL import ImageOps
import requests
import io
from image_utils import ImageText
MARGIN_PERCENT = 0.2
def create_soy_vs_chad_meme(emoji1, emoji2, caption1, caption2):
left_image = get_emoji_from_rdrama(emoji1)
right_image = get_emoji_from_rdrama(emoji2)
left_size_x, left_size_y = left_image.size
right_size_x, right_size_y = right_image.size
#We want the dimensions of the smaller one.
if left_size_x > right_size_x:
base_size_x = right_size_x
base_size_y = right_size_y
#left_image = left_image.resize((base_size_x, base_size_y))
else:
base_size_x = left_size_x
base_size_y = left_size_y
#right_image = right_image.resize((base_size_x, base_size_y))
margin_size = int(MARGIN_PERCENT*base_size_x)
total_image_width = 2*base_size_x + margin_size
#left_image = ImageOps.mirror(left_image)
base = Image.new(mode="RGB", size=(total_image_width,total_image_width), color=(255,255,255))
base.paste(left_image, (0,0), left_image)
base.paste(right_image, (margin_size+base_size_x,0), right_image)
left_caption_box = ImageText((left_size_x, total_image_width-left_size_y))
left_caption_box.fill_text_box((0,0), caption1, left_size_x, total_image_width-left_size_y, font_filename="impact.ttf")
base.paste(left_caption_box.image, (0, left_size_y), left_caption_box.image)
right_caption_box = ImageText((right_size_x, total_image_width-right_size_y))
right_caption_box.fill_text_box((0,0), caption2, right_size_x, total_image_width-right_size_y, font_filename="impact.ttf")
base.paste(right_caption_box.image, (left_size_x+margin_size, right_size_y), right_caption_box.image)
return base
def wrap_text_for_font(text, region_size, font_size) -> Image:
image = Image.new(mode="RGB", size=region_size, color=(255,255,255))
imageDraw = ImageDraw.ImageDraw()
imageDraw.multiline_text()
def get_emoji_from_rdrama(emoji_name):
return get_image_file_from_url(f"https://www.rdrama.net/e/{emoji_name}.webp")
def get_image_file_from_url(url):
r = requests.get(url)
image_file = io.BytesIO(r.content)
im = Image.open(image_file)
return im
#get_emoji_from_rdrama("zoomersoy").show()
create_soy_vs_chad_meme("marseywhirlyhat", "marseyaynrand", "For twelve years, you have been asking: Who is John Galt? This is John Galt speaking. I am the man who loves his life. I am the man who does not sacrifice his love or his values. I am the man who has deprived you of victims and thus has destroyed your world, and if you wish to know why you are perishing—you who dread knowledge—I am the man who will now tell you.” The chief engineer was the only one able to move; he ran to a television set and struggled frantically with its dials. But the screen remained empty; the speaker had not chosen to be seen. Only his voice filled the airways of the country—of the world, thought the chief engineer—sounding as if he were speaking here, in this room, not to a group, but to one man; it was not the tone of addressing a meeting, but the tone of addressing a mind.", "You have heard it said that this is an age of moral crisis. You have said it yourself, half in fear, half in hope that the words had no meaning. You have cried that mans sins are destroying the world and you have cursed human nature for its unwillingness to practice the virtues you demanded. Since virtue, to you, consists of sacrifice, you have demanded more sacrifices at every successive disaster. In the name of a return to morality, you have sacrificed all those evils which you held as the cause of your plight. You have sacrificed justice to mercy. You have sacrificed independence to unity. You have sacrificed reason to faith. You have sacrificed wealth to need. You have sacrificed self-esteem to self-denial. You have sacrificed happiness to duty.").show()
# base_image = Image.new(mode="RGB", size=(1000,1000), color=(255,255,255))
# marppy_image = Image.open("marppy.webp")
# base_image.paste(marppy_image, (0,0), marppy_image)
# I1 = ImageDraw.Draw(base_image)
# font = ImageFont.truetype("impact.ttf", 65)
# I1.text((300, 0), "GO HOME GAMER GIRL", font=font, fill=(255, 0, 0))
# base_image.show()