soy vs chad improvements
parent
2f027e1986
commit
904524eafd
|
@ -7,38 +7,45 @@ import io
|
||||||
from image_utils import ImageText
|
from image_utils import ImageText
|
||||||
|
|
||||||
MARGIN_PERCENT = 0.2
|
MARGIN_PERCENT = 0.2
|
||||||
|
LEFT_MARGIN_COLUMN = 20
|
||||||
|
CONTENT_COLUMN = 300
|
||||||
|
MIDDLE_MARGIN_COLUMN = 80
|
||||||
|
RIGHT_MARGIN_COLUMN = LEFT_MARGIN_COLUMN
|
||||||
|
TOP_MARGIN_ROW = 80
|
||||||
|
IMAGE_ROW = 300
|
||||||
|
MIDDLE_MARGIN_ROW = 20
|
||||||
|
TEXT_ROW = 300
|
||||||
|
BOTTOM_MARGIN_ROW = 80
|
||||||
|
|
||||||
|
total_image_size_x = 2*CONTENT_COLUMN + LEFT_MARGIN_COLUMN + RIGHT_MARGIN_COLUMN + MIDDLE_MARGIN_COLUMN
|
||||||
|
total_image_size_y = TOP_MARGIN_ROW + IMAGE_ROW + MIDDLE_MARGIN_ROW + TEXT_ROW + BOTTOM_MARGIN_ROW
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_soy_vs_chad_meme(emoji1, emoji2, caption1, caption2):
|
def create_soy_vs_chad_meme(emoji1, emoji2, caption1, caption2):
|
||||||
left_image = get_emoji_from_rdrama(emoji1)
|
left_image = get_emoji_from_rdrama(emoji1)
|
||||||
right_image = get_emoji_from_rdrama(emoji2)
|
right_image = get_emoji_from_rdrama(emoji2)
|
||||||
|
|
||||||
left_size_x, left_size_y = left_image.size
|
#Resize images
|
||||||
right_size_x, right_size_y = right_image.size
|
left_image = ImageOps.contain(left_image, (CONTENT_COLUMN, IMAGE_ROW))
|
||||||
|
right_image = ImageOps.contain(right_image, (CONTENT_COLUMN, IMAGE_ROW))
|
||||||
|
|
||||||
#We want the dimensions of the smaller one.
|
left_image = ImageOps.mirror(left_image)
|
||||||
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
|
||||||
base = Image.new(mode="RGB", size=(total_image_width,total_image_width), color=(255,255,255))
|
base = Image.new(mode="RGB", size=(total_image_size_x,total_image_size_y), 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))
|
#Add images
|
||||||
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_image, (LEFT_MARGIN_COLUMN,TOP_MARGIN_ROW), left_image)
|
||||||
base.paste(left_caption_box.image, (0, left_size_y), left_caption_box.image)
|
base.paste(right_image, (LEFT_MARGIN_COLUMN+CONTENT_COLUMN+MIDDLE_MARGIN_COLUMN,TOP_MARGIN_ROW), right_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")
|
#Text regions
|
||||||
base.paste(right_caption_box.image, (left_size_x+margin_size, right_size_y), right_caption_box.image)
|
left_caption_box = ImageText((CONTENT_COLUMN, TEXT_ROW))
|
||||||
|
left_caption_box.fill_text_box((0,0), caption1, CONTENT_COLUMN, TEXT_ROW, font_filename="arial.ttf")
|
||||||
|
base.paste(left_caption_box.image, (LEFT_MARGIN_COLUMN, TOP_MARGIN_ROW+IMAGE_ROW+MIDDLE_MARGIN_ROW), left_caption_box.image)
|
||||||
|
right_caption_box = ImageText((CONTENT_COLUMN, TEXT_ROW))
|
||||||
|
right_caption_box.fill_text_box((0,0), caption2, CONTENT_COLUMN, TEXT_ROW, font_filename="arial.ttf")
|
||||||
|
base.paste(right_caption_box.image, (LEFT_MARGIN_COLUMN+CONTENT_COLUMN+MIDDLE_MARGIN_COLUMN, TOP_MARGIN_ROW+IMAGE_ROW+MIDDLE_MARGIN_ROW), right_caption_box.image)
|
||||||
|
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
@ -48,7 +55,15 @@ def wrap_text_for_font(text, region_size, font_size) -> Image:
|
||||||
imageDraw.multiline_text()
|
imageDraw.multiline_text()
|
||||||
|
|
||||||
def get_emoji_from_rdrama(emoji_name):
|
def get_emoji_from_rdrama(emoji_name):
|
||||||
return get_image_file_from_url(f"https://www.rdrama.net/e/{emoji_name}.webp")
|
cleaned_emoji_name : str = emoji_name
|
||||||
|
should_flip = False
|
||||||
|
if '!' in emoji_name:
|
||||||
|
cleaned_emoji_name = cleaned_emoji_name.replace("!", "")
|
||||||
|
should_flip = True
|
||||||
|
image = get_image_file_from_url(f"https://www.rdrama.net/e/{cleaned_emoji_name}.webp")
|
||||||
|
if should_flip:
|
||||||
|
image = ImageOps.mirror(image)
|
||||||
|
return image
|
||||||
|
|
||||||
def get_image_file_from_url(url):
|
def get_image_file_from_url(url):
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
|
@ -58,7 +73,7 @@ def get_image_file_from_url(url):
|
||||||
|
|
||||||
#get_emoji_from_rdrama("zoomersoy").show()
|
#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 man’s 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()
|
create_soy_vs_chad_meme("!marseyrage", "marseyliathomas", "YOU RUINED MY LIFE!!!!", "I'm literally just existing").show()
|
||||||
|
|
||||||
# base_image = Image.new(mode="RGB", size=(1000,1000), color=(255,255,255))
|
# base_image = Image.new(mode="RGB", size=(1000,1000), color=(255,255,255))
|
||||||
# marppy_image = Image.open("marppy.webp")
|
# marppy_image = Image.open("marppy.webp")
|
||||||
|
|
Loading…
Reference in New Issue