Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fde2130eab | |||
| ee52f44eb3 | |||
| 9baf2a59db | |||
| bb265c0a2c | |||
| fc2dc0e4ed | |||
| b47a395b47 | |||
| 839aff11f7 | |||
| e4e61f866d | |||
| d6503b9209 | |||
| 801edb3e20 | |||
| 534837d1d1 | |||
| 84b6fd6ad2 | |||
| 0ef694fbc9 | |||
| 84da593397 | |||
| 2070307c9d | |||
| dca12b5d32 | |||
| 79ec20f0a4 | |||
| 642338b69d | |||
| 1aa26c06ef | |||
| 6444a6e58d | |||
| 62afce22a6 | |||
| 6748073048 | |||
| 6cfd623685 | |||
| 28cd3f59d9 | |||
| b2749898a5 | |||
| 6f38686513 | |||
| 59a8530cbe | |||
| 671f6fd595 | |||
| 7c076b896f | |||
| 7c0e292c91 | |||
| f44e32fbf8 | |||
| 9f46e8b8f9 | |||
| f99bfff3ed | |||
| f83ae349d6 | |||
| 01afa3f16d | |||
| 8caa7efb94 | |||
| b6d063e1e5 | |||
| 08c938719a | |||
| a7610c2f01 | |||
| dffdf656dc | |||
| 27b1d422a6 | |||
| 208a10c61e | |||
| 462ec21a53 | |||
| 9e2d2fcce7 | |||
| 7e269c1ab5 |
@@ -0,0 +1,34 @@
|
||||
name: Docker
|
||||
|
||||
on: ["push", "pull_request"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: /tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildx-
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
push: false
|
||||
cache-from: type=local,src=/tmp/.buildx-cache
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||
- name: Move cache
|
||||
run: |
|
||||
rm -rf /tmp/.buildx-cache
|
||||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||
- name: Image digest
|
||||
run: echo ${{ steps.docker_build.outputs.digest }}
|
||||
@@ -0,0 +1,13 @@
|
||||
FROM python
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY requirements.* ./
|
||||
|
||||
RUN pip install -r requirements.txt && pip install -r requirements.bot.txt
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
|
||||
CMD [ "sh", "-c", "python -m discord_bot" ]
|
||||
@@ -45,6 +45,14 @@ You can invite the bot on your server with [this link](https://discordapp.com/ap
|
||||
|
||||
## History
|
||||
|
||||
* 1.3
|
||||
* **Complex memes syntax**
|
||||
* Examples in docs
|
||||
* "Reaction" templates
|
||||
* Reworked CLI arguments
|
||||
* More unit testing
|
||||
* More docs
|
||||
* Bug fix
|
||||
* 1.2
|
||||
* Reworked text fitting
|
||||
* Unit testing
|
||||
|
||||
@@ -3,7 +3,7 @@ import traceback
|
||||
import logging
|
||||
import discord
|
||||
import re
|
||||
import tempfile
|
||||
from io import BytesIO
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv
|
||||
@@ -116,28 +116,32 @@ async def on_message(message: discord.Message):
|
||||
if len(args) > 1 and message.author.display_name is not None:
|
||||
left_wmark_text = f"By {message.author.display_name}"
|
||||
logging.info(args[0])
|
||||
meme_id = re.sub(r'[^A-Za-z0-9 _]', "", args[0]).strip()
|
||||
args[0] = meme_id
|
||||
img = meme_otron.compute(*args, left_wmark_text=left_wmark_text)
|
||||
if img is None:
|
||||
if len(meme_id) == 0:
|
||||
response = f":warning: Template not found\n"
|
||||
else:
|
||||
hint = meme_db.find_nearest(meme_id)
|
||||
response = f":warning: Template `{meme_id}` not found\n"
|
||||
if hint is not None:
|
||||
response += f"Did you mean `{hint}`?\n"
|
||||
response += f"You can find a more detailed help and a list of templates at:\n" \
|
||||
|
||||
input_data = None
|
||||
if len(message.attachments) > 0:
|
||||
input_data = await message.attachments[0].read()
|
||||
|
||||
img, errors = meme_otron.compute(*args, left_wmark_text=left_wmark_text,
|
||||
input_data=input_data, max_file_size=8 * 1024 * 1024)
|
||||
if len(errors) > 0:
|
||||
response = ":warning:"
|
||||
for err in errors:
|
||||
response += "\n" + err.replace("'", "`").replace("`` ", "")
|
||||
response += f"\nYou can find a more detailed help and a list of templates at:\n" \
|
||||
f"<{DOC_URL}>"
|
||||
if len(response) >= 2000:
|
||||
await message.channel.send(f"{message.author.mention} ... really?")
|
||||
else:
|
||||
await message.channel.send(response)
|
||||
else:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as output:
|
||||
img.save(output, format="JPEG")
|
||||
with BytesIO() as output_file:
|
||||
img.save(output_file, format="JPEG")
|
||||
output_file.flush()
|
||||
output_file.seek(0)
|
||||
|
||||
response = None
|
||||
if len(args) == 1:
|
||||
meme_id = utils.sanitize_input(args[0])
|
||||
if len(args) == 1 and meme_id not in ["image", "text"]:
|
||||
meme = meme_db.get_meme(meme_id)
|
||||
response = f"Template `{meme.id}`:"
|
||||
if len(meme.aliases) > 0:
|
||||
@@ -152,13 +156,8 @@ async def on_message(message: discord.Message):
|
||||
response = f"A meme by {message.author.mention}:"
|
||||
if message_id not in SENT:
|
||||
SENT[message_id] = []
|
||||
response = await message.channel.send(response,
|
||||
file=discord.File(filename="meme.jpg", fp=output.name))
|
||||
response = await message.channel.send(response, file=discord.File(output_file, "meme.jpg"))
|
||||
SENT[message_id] += [response]
|
||||
try:
|
||||
os.remove(output.name)
|
||||
except PermissionError:
|
||||
pass
|
||||
if not is_direct:
|
||||
await delete(message)
|
||||
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
# Meme-Otron guide
|
||||
|
||||
* [Commands](#commands)
|
||||
* [Simple use](#simple-use)
|
||||
* [Advanced use](#advanced-use)
|
||||
* [Discord features](#discord-features)
|
||||
* [CLI features](#cli-features)
|
||||
* [List of templates](#list-of-templates)
|
||||
* [Standard Templates](#standard-templates)
|
||||
* [Reactions (no text)](#reactions-no-text)
|
||||
* [Examples](#examples)
|
||||
* [Example 1: Simple template](#example-1-simple-template)
|
||||
* [Example 2: Use of empty texts](#example-2-use-of-empty-texts)
|
||||
* [Example 3: Text + Template](#example-3-text--template)
|
||||
* [Example 4: Complex composition](#example-4-complex-composition)
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
### Simple use
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
You can generate memes by using the following arguments:
|
||||
|
||||
```
|
||||
[meme id] "text1" "text2" ...
|
||||
```
|
||||
|
||||
Depending of the number of `"text"` arguments, several behavior occurs:
|
||||
* **None**: you get the template that gives you the locations of texts. (see below)
|
||||
* **Less than the template's**: the remaining texts are blank on the output
|
||||
* **More than the template's**: the extra arguments are ignored
|
||||
|
||||
> Notes
|
||||
> * You don't have to use all texts shown on the templates
|
||||
> * You can use an empty text argument ( `""` ) to skip a text and keep it blank
|
||||
|
||||
See [Examples](#examples) to get an idea of how to use it.
|
||||
|
||||
### Advanced use
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
Since version 1.3, Meme-Otron allows you to "pipe" parts in order to compose more advanced memes. The syntax is as follows:
|
||||
|
||||
```
|
||||
[part1] - [part2] - ...
|
||||
```
|
||||
|
||||
Each `part` can be one of the following:
|
||||
|
||||
* A template: as described in [Simple use](#simple-use)
|
||||
* Texts: ```text "text 1" "text 2" ...```
|
||||
* Black Arial texts on white background
|
||||
* Each text is it's own paragraph
|
||||
* Images: ```image <URL>```
|
||||
* Takes an image from input or an URL (optional)
|
||||
* Input depends on the system:
|
||||
* the Discord bot takes the attachment
|
||||
* the CLI takes stdin or `--input` argument.
|
||||
|
||||
> Notes
|
||||
> * Input of `image` is always the same, don't expect multiple instances of `image` to get different results if you don't indicate an URL
|
||||
|
||||
See [Examples](#examples) to get an idea of how to use it.
|
||||
|
||||
### Discord features
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
Tag the bot and use the above syntax to get started. In addition, you can use the following commands:
|
||||
|
||||
* Use `help` to get a simple help message
|
||||
* Use `list` to get a list of all meme ids
|
||||
* Use `delete` to delete the last message sent by the bot (directed to you)
|
||||
|
||||
To get the template info, just send the meme id without texts.
|
||||
|
||||
> Tip : You can use `\\n` in your texts to add a line break
|
||||
|
||||
Enjoy the full experience of this bot by using direct messages to keep your server free of spam.
|
||||
|
||||
### CLI features
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
In this project directory, you can simply call:
|
||||
```
|
||||
python -m meme_otron [meme id] "text1" "text2" ... > output.jpg
|
||||
```
|
||||
Without pipe redirection with `-o [output]`:
|
||||
```
|
||||
python -m meme_otron -o output.png [meme id] "text1" "text2" ...
|
||||
```
|
||||
|
||||
You can even pipe input images like this:
|
||||
```
|
||||
python -m meme_otron [arguments] < input.jpg > output.jpg
|
||||
```
|
||||
|
||||
Available arguments:
|
||||
* `--help` / `-h`
|
||||
* Show a simple guide
|
||||
* `--output [file]` / `-o [file]`
|
||||
* Output file, you are free to choose the format
|
||||
* `--input [file]` / `-i [file]`
|
||||
* Input file used for `image`
|
||||
* `-nw` / `--no-watermark`
|
||||
* Removes the watermark
|
||||
* `-d` / `--debug`
|
||||
* Add more info to output like a box show the texts boundaries
|
||||
* `-v` / `--verbose`
|
||||
* Add more logging
|
||||
|
||||
|
||||
## List of templates
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
You can find here the full list of templates.
|
||||
Each one has extra info and an image showing how texts are placed.
|
||||
Click on an image to enlarge it.
|
||||
|
||||
### Standard Templates
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--LIST1-START-->
|
||||
|
||||
<!--LIST1-END-->
|
||||
|
||||
### Reactions (no text)
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--LIST2-START-->
|
||||
|
||||
<!--LIST2-END-->
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Simple template
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE1-START-->
|
||||
|
||||
<!--EXAMPLE1-END-->
|
||||
|
||||
### Example 2: Use of empty texts
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE2-START-->
|
||||
|
||||
<!--EXAMPLE2-END-->
|
||||
|
||||
### Example 3: Text + Template
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE3-START-->
|
||||
|
||||
<!--EXAMPLE3-END-->
|
||||
|
||||
|
||||
### Example 4: Complex composition
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE4-START-->
|
||||
|
||||
<!--EXAMPLE4-END-->
|
||||
@@ -1,5 +1,25 @@
|
||||
# Meme-Otron guide
|
||||
|
||||
* [Commands](#commands)
|
||||
* [Simple use](#simple-use)
|
||||
* [Advanced use](#advanced-use)
|
||||
* [Discord features](#discord-features)
|
||||
* [CLI features](#cli-features)
|
||||
* [List of templates](#list-of-templates)
|
||||
* [Standard Templates](#standard-templates)
|
||||
* [Reactions (no text)](#reactions-no-text)
|
||||
* [Examples](#examples)
|
||||
* [Example 1: Simple template](#example-1-simple-template)
|
||||
* [Example 2: Use of empty texts](#example-2-use-of-empty-texts)
|
||||
* [Example 3: Text + Template](#example-3-text--template)
|
||||
* [Example 4: Complex composition](#example-4-complex-composition)
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
### Simple use
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
You can generate memes by using the following arguments:
|
||||
|
||||
```
|
||||
@@ -15,7 +35,36 @@ Depending of the number of `"text"` arguments, several behavior occurs:
|
||||
> * You don't have to use all texts shown on the templates
|
||||
> * You can use an empty text argument ( `""` ) to skip a text and keep it blank
|
||||
|
||||
## Discord features
|
||||
See [Examples](#examples) to get an idea of how to use it.
|
||||
|
||||
### Advanced use
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
Since version 1.3, Meme-Otron allows you to "pipe" parts in order to compose more advanced memes. The syntax is as follows:
|
||||
|
||||
```
|
||||
[part1] - [part2] - ...
|
||||
```
|
||||
|
||||
Each `part` can be one of the following:
|
||||
|
||||
* A template: as described in [Simple use](#simple-use)
|
||||
* Texts: ```text "text 1" "text 2" ...```
|
||||
* Black Arial texts on white background
|
||||
* Each text is it's own paragraph
|
||||
* Images: ```image <URL>```
|
||||
* Takes an image from input or an URL (optional)
|
||||
* Input depends on the system:
|
||||
* the Discord bot takes the attachment
|
||||
* the CLI takes stdin or `--input` argument.
|
||||
|
||||
> Notes
|
||||
> * Input of `image` is always the same, don't expect multiple instances of `image` to get different results if you don't indicate an URL
|
||||
|
||||
See [Examples](#examples) to get an idea of how to use it.
|
||||
|
||||
### Discord features
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
Tag the bot and use the above syntax to get started. In addition, you can use the following commands:
|
||||
|
||||
@@ -29,7 +78,8 @@ To get the template info, just send the meme id without texts.
|
||||
|
||||
Enjoy the full experience of this bot by using direct messages to keep your server free of spam.
|
||||
|
||||
## CLI features
|
||||
### CLI features
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
In this project directory, you can simply call:
|
||||
```
|
||||
@@ -40,16 +90,37 @@ Without pipe redirection with `-o [output]`:
|
||||
python -m meme_otron -o output.png [meme id] "text1" "text2" ...
|
||||
```
|
||||
|
||||
> Note: with `-o`, you are free to choose the output format
|
||||
You can even pipe input images like this:
|
||||
```
|
||||
python -m meme_otron [arguments] < input.jpg > output.jpg
|
||||
```
|
||||
|
||||
Available arguments:
|
||||
* `--help` / `-h`
|
||||
* Show a simple guide
|
||||
* `--output [file]` / `-o [file]`
|
||||
* Output file, you are free to choose the format
|
||||
* `--input [file]` / `-i [file]`
|
||||
* Input file used for `image`
|
||||
* `-nw` / `--no-watermark`
|
||||
* Removes the watermark
|
||||
* `-d` / `--debug`
|
||||
* Add more info to output like a box show the texts boundaries
|
||||
* `-v` / `--verbose`
|
||||
* Add more logging
|
||||
|
||||
|
||||
## List of templates
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
You can find here the full list of templates.
|
||||
Each one has extra info and an image showing how texts are placed.
|
||||
Click on an image to enlarge it.
|
||||
|
||||
### Standard Templates
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--START-->
|
||||
<!--LIST1-START-->
|
||||
||||
|
||||
|:---:|:---:|:---:|
|
||||
|**aliens**<br><a href='https://knowyourmeme.com/memes/ancient-aliens' target='_blank'>more info</a>|**alive**<br>alt: no_brain<br><a href='https://knowyourmeme.com/memes/oh-fuck-i-forgot-to-give-you-a-brain' target='_blank'>more info</a>|**argument**<br>alt: wrestlers<br><a href='https://knowyourmeme.com/memes/american-chopper-argument' target='_blank'>more info</a>|
|
||||
@@ -66,30 +137,124 @@ Click on an image to enlarge it.
|
||||
|<a href='./templates/distracted.jpg' target='_blank'><img alt='enlarge' src='./preview/distracted.jpg'/></a>|<a href='./templates/dont_look.jpg' target='_blank'><img alt='enlarge' src='./preview/dont_look.jpg'/></a>|<a href='./templates/drake.jpg' target='_blank'><img alt='enlarge' src='./preview/drake.jpg'/></a>|
|
||||
|**drift**<br>alt: exit<br><a href='https://knowyourmeme.com/memes/left-exit-12-off-ramp' target='_blank'>more info</a>|**everywhere**<br>alt: buzz, woody<br><a href='https://knowyourmeme.com/memes/x-x-everywhere' target='_blank'>more info</a>|**everywhere2**<br>alt: angry, diapers<br><a href='https://knowyourmeme.com/memes/how-many-diapers-could-he-possibly-use' target='_blank'>more info</a>|
|
||||
|<a href='./templates/drift.jpg' target='_blank'><img alt='enlarge' src='./preview/drift.jpg'/></a>|<a href='./templates/everywhere.jpg' target='_blank'><img alt='enlarge' src='./preview/everywhere.jpg'/></a>|<a href='./templates/everywhere2.jpg' target='_blank'><img alt='enlarge' src='./preview/everywhere2.jpg'/></a>|
|
||||
|**fight**<br>alt: vaping<br><a href='https://knowyourmeme.com/memes/dabbing-dude' target='_blank'>more info</a>|**fine**<br>alt: fire, dog<br><a href='https://knowyourmeme.com/memes/this-is-fine' target='_blank'>more info</a>|**flex_tape**<br>alt: flex, tape<br><a href='https://knowyourmeme.com/memes/flex-tape' target='_blank'>more info</a>|
|
||||
|<a href='./templates/fight.jpg' target='_blank'><img alt='enlarge' src='./preview/fight.jpg'/></a>|<a href='./templates/fine.jpg' target='_blank'><img alt='enlarge' src='./preview/fine.jpg'/></a>|<a href='./templates/flex_tape.jpg' target='_blank'><img alt='enlarge' src='./preview/flex_tape.jpg'/></a>|
|
||||
|**gate**<br><a href='https://knowyourmeme.com/memes/open-the-gate' target='_blank'>more info</a>|**girl_cat**<br><a href='https://knowyourmeme.com/memes/woman-yelling-at-a-cat' target='_blank'>more info</a>|**grandma**<br><a href='https://knowyourmeme.com/memes/grandma-finds-the-internet' target='_blank'>more info</a>|
|
||||
|<a href='./templates/gate.jpg' target='_blank'><img alt='enlarge' src='./preview/gate.jpg'/></a>|<a href='./templates/girl_cat.jpg' target='_blank'><img alt='enlarge' src='./preview/girl_cat.jpg'/></a>|<a href='./templates/grandma.jpg' target='_blank'><img alt='enlarge' src='./preview/grandma.jpg'/></a>|
|
||||
|**gru**<br>alt: plan<br><a href='https://knowyourmeme.com/memes/grus-plan' target='_blank'>more info</a>|**guys**<br>alt: explain, paid<br><a href='https://knowyourmeme.com/memes/you-guys-are-getting-paid' target='_blank'>more info</a>|**handshake**<br><a href='https://knowyourmeme.com/memes/epic-handshake' target='_blank'>more info</a>|
|
||||
|<a href='./templates/gru.jpg' target='_blank'><img alt='enlarge' src='./preview/gru.jpg'/></a>|<a href='./templates/guys.jpg' target='_blank'><img alt='enlarge' src='./preview/guys.jpg'/></a>|<a href='./templates/handshake.jpg' target='_blank'><img alt='enlarge' src='./preview/handshake.jpg'/></a>|
|
||||
|**handshake2**<br>alt: scott<br><a href='https://knowyourmeme.com/memes/young-michael-scott-shaking-ed-trucks-hand' target='_blank'>more info</a>|**idea**<br>alt: gentlemen<br><a href='https://knowyourmeme.com/memes/all-right-gentlemen' target='_blank'>more info</a>|**lion**<br>alt: shadowy, king, light<br><a href='https://knowyourmeme.com/memes/simba-everything-the-light-touches-is' target='_blank'>more info</a>|
|
||||
|<a href='./templates/handshake2.jpg' target='_blank'><img alt='enlarge' src='./preview/handshake2.jpg'/></a>|<a href='./templates/idea.jpg' target='_blank'><img alt='enlarge' src='./preview/idea.jpg'/></a>|<a href='./templates/lion.jpg' target='_blank'><img alt='enlarge' src='./preview/lion.jpg'/></a>|
|
||||
|**meeting**<br>alt: boardroom, suggestion<br><a href='https://knowyourmeme.com/memes/boardroom-suggestion' target='_blank'>more info</a>|**mini**<br>alt: joker<br><a href='https://knowyourmeme.com/memes/mini-joker' target='_blank'>more info</a>|**nobody_cares**<br>alt: nobody, jurassic, park, jurassic_park<br><a href='https://knowyourmeme.com/memes/see-nobody-cares' target='_blank'>more info</a>|
|
||||
|<a href='./templates/meeting.jpg' target='_blank'><img alt='enlarge' src='./preview/meeting.jpg'/></a>|<a href='./templates/mini.jpg' target='_blank'><img alt='enlarge' src='./preview/mini.jpg'/></a>|<a href='./templates/nobody_cares.jpg' target='_blank'><img alt='enlarge' src='./preview/nobody_cares.jpg'/></a>|
|
||||
|**nope**<br><a href='https://knowyourmeme.com/memes/disappointed-black-guy' target='_blank'>more info</a>|**overconfident**<br>alt: alcohol, depressed<br><a href='https://knowyourmeme.com/memes/overconfident-alcoholic' target='_blank'>more info</a>|**patrick**<br>alt: wallet, id<br><a href='https://knowyourmeme.com/memes/patrick-stars-wallet' target='_blank'>more info</a>|
|
||||
|<a href='./templates/nope.jpg' target='_blank'><img alt='enlarge' src='./preview/nope.jpg'/></a>|<a href='./templates/overconfident.jpg' target='_blank'><img alt='enlarge' src='./preview/overconfident.jpg'/></a>|<a href='./templates/patrick.jpg' target='_blank'><img alt='enlarge' src='./preview/patrick.jpg'/></a>|
|
||||
|**pigeon**<br>alt: butterfly<br><a href='https://knowyourmeme.com/memes/is-this-a-pigeon' target='_blank'>more info</a>|**pills**<br>alt: swallow<br><a href='https://knowyourmeme.com/memes/hard-to-swallow-pills' target='_blank'>more info</a>|**pleasure3**<br>alt: satisfied3|
|
||||
|<a href='./templates/pigeon.jpg' target='_blank'><img alt='enlarge' src='./preview/pigeon.jpg'/></a>|<a href='./templates/pills.jpg' target='_blank'><img alt='enlarge' src='./preview/pills.jpg'/></a>|<a href='./templates/pleasure3.jpg' target='_blank'><img alt='enlarge' src='./preview/pleasure3.jpg'/></a>|
|
||||
|**pleasure4**<br>alt: pleasure, satisfied, satisfied4<br><a href='https://knowyourmeme.com/memes/vince-mcmahon-reaction' target='_blank'>more info</a>|**salt_bae**<br>alt: salt<br><a href='https://knowyourmeme.com/memes/salt-bae' target='_blank'>more info</a>|**scary**<br>alt: spongebob, fearless<br><a href='https://knowyourmeme.com/memes/spongebob-sees-flying-dutchman' target='_blank'>more info</a>|
|
||||
|<a href='./templates/pleasure4.jpg' target='_blank'><img alt='enlarge' src='./preview/pleasure4.jpg'/></a>|<a href='./templates/salt_bae.jpg' target='_blank'><img alt='enlarge' src='./preview/salt_bae.jpg'/></a>|<a href='./templates/scary.jpg' target='_blank'><img alt='enlarge' src='./preview/scary.jpg'/></a>|
|
||||
|**seagull2**<br>alt: seagull, screaming<br><a href='https://knowyourmeme.com/memes/inhaling-seagull' target='_blank'>more info</a>|**seagull4**|**see_that_guy**<br><a href='https://knowyourmeme.com/memes/hey-man-you-see-that-guy-over-there' target='_blank'>more info</a>|
|
||||
|<a href='./templates/seagull2.jpg' target='_blank'><img alt='enlarge' src='./preview/seagull2.jpg'/></a>|<a href='./templates/seagull4.jpg' target='_blank'><img alt='enlarge' src='./preview/seagull4.jpg'/></a>|<a href='./templates/see_that_guy.jpg' target='_blank'><img alt='enlarge' src='./preview/see_that_guy.jpg'/></a>|
|
||||
|**sleeping**<br>alt: brain<br><a href='https://knowyourmeme.com/memes/are-you-going-to-sleep' target='_blank'>more info</a>|**spiderman**<br>alt: same<br><a href='https://knowyourmeme.com/memes/spider-man-pointing-at-spider-man' target='_blank'>more info</a>|**struggle**<br>alt: choice, hero<br><a href='https://knowyourmeme.com/memes/daily-struggle' target='_blank'>more info</a>|
|
||||
|<a href='./templates/sleeping.jpg' target='_blank'><img alt='enlarge' src='./preview/sleeping.jpg'/></a>|<a href='./templates/spiderman.jpg' target='_blank'><img alt='enlarge' src='./preview/spiderman.jpg'/></a>|<a href='./templates/struggle.jpg' target='_blank'><img alt='enlarge' src='./preview/struggle.jpg'/></a>|
|
||||
|**t_pose**<br>alt: dominance, monika<br><a href='https://knowyourmeme.com/memes/monika-t-posing-over-sans' target='_blank'>more info</a>|**tom_cousins**<br>alt: cousins, backup, goons<br><a href='https://knowyourmeme.com/memes/tom-and-jerry-hired-goons' target='_blank'>more info</a>|**tough2**<br>alt: tough, fight<br><a href='https://knowyourmeme.com/memes/increasingly-buff-spongebob' target='_blank'>more info</a>|
|
||||
|<a href='./templates/t_pose.jpg' target='_blank'><img alt='enlarge' src='./preview/t_pose.jpg'/></a>|<a href='./templates/tom_cousins.jpg' target='_blank'><img alt='enlarge' src='./preview/tom_cousins.jpg'/></a>|<a href='./templates/tough2.jpg' target='_blank'><img alt='enlarge' src='./preview/tough2.jpg'/></a>|
|
||||
|**tough2bis**|**tough3**|**trump**<br>alt: law<br><a href='https://knowyourmeme.com/memes/trumps-first-order-of-business' target='_blank'>more info</a>|
|
||||
|<a href='./templates/tough2bis.jpg' target='_blank'><img alt='enlarge' src='./preview/tough2bis.jpg'/></a>|<a href='./templates/tough3.jpg' target='_blank'><img alt='enlarge' src='./preview/tough3.jpg'/></a>|<a href='./templates/trump.jpg' target='_blank'><img alt='enlarge' src='./preview/trump.jpg'/></a>|
|
||||
|**trust_nobody**<br>alt: yourself, gun<br><a href='https://knowyourmeme.com/memes/trust-nobody-not-even-yourself' target='_blank'>more info</a>|**truth**<br>alt: scroll<br><a href='https://knowyourmeme.com/memes/the-scroll-of-truth' target='_blank'>more info</a>|**winnie2**<br>alt: winnie<br><a href='https://knowyourmeme.com/memes/tuxedo-winnie-the-pooh' target='_blank'>more info</a>|
|
||||
|<a href='./templates/trust_nobody.jpg' target='_blank'><img alt='enlarge' src='./preview/trust_nobody.jpg'/></a>|<a href='./templates/truth.jpg' target='_blank'><img alt='enlarge' src='./preview/truth.jpg'/></a>|<a href='./templates/winnie2.jpg' target='_blank'><img alt='enlarge' src='./preview/winnie2.jpg'/></a>|||
|
||||
<!--END-->
|
||||
|**favorite**<br><a href='https://knowyourmeme.com/memes/this-is-my-favorite-subreddit' target='_blank'>more info</a>|**fight**<br>alt: vaping<br><a href='https://knowyourmeme.com/memes/dabbing-dude' target='_blank'>more info</a>|**fine**<br>alt: fire, dog<br><a href='https://knowyourmeme.com/memes/this-is-fine' target='_blank'>more info</a>|
|
||||
|<a href='./templates/favorite.jpg' target='_blank'><img alt='enlarge' src='./preview/favorite.jpg'/></a>|<a href='./templates/fight.jpg' target='_blank'><img alt='enlarge' src='./preview/fight.jpg'/></a>|<a href='./templates/fine.jpg' target='_blank'><img alt='enlarge' src='./preview/fine.jpg'/></a>|
|
||||
|**flex_tape**<br>alt: flex, tape<br><a href='https://knowyourmeme.com/memes/flex-tape' target='_blank'>more info</a>|**gate**<br><a href='https://knowyourmeme.com/memes/open-the-gate' target='_blank'>more info</a>|**girl_cat**<br><a href='https://knowyourmeme.com/memes/woman-yelling-at-a-cat' target='_blank'>more info</a>|
|
||||
|<a href='./templates/flex_tape.jpg' target='_blank'><img alt='enlarge' src='./preview/flex_tape.jpg'/></a>|<a href='./templates/gate.jpg' target='_blank'><img alt='enlarge' src='./preview/gate.jpg'/></a>|<a href='./templates/girl_cat.jpg' target='_blank'><img alt='enlarge' src='./preview/girl_cat.jpg'/></a>|
|
||||
|**grandma**<br><a href='https://knowyourmeme.com/memes/grandma-finds-the-internet' target='_blank'>more info</a>|**gru**<br>alt: plan<br><a href='https://knowyourmeme.com/memes/grus-plan' target='_blank'>more info</a>|**guys**<br>alt: explain, paid<br><a href='https://knowyourmeme.com/memes/you-guys-are-getting-paid' target='_blank'>more info</a>|
|
||||
|<a href='./templates/grandma.jpg' target='_blank'><img alt='enlarge' src='./preview/grandma.jpg'/></a>|<a href='./templates/gru.jpg' target='_blank'><img alt='enlarge' src='./preview/gru.jpg'/></a>|<a href='./templates/guys.jpg' target='_blank'><img alt='enlarge' src='./preview/guys.jpg'/></a>|
|
||||
|**handshake**<br><a href='https://knowyourmeme.com/memes/epic-handshake' target='_blank'>more info</a>|**handshake2**<br>alt: scott<br><a href='https://knowyourmeme.com/memes/young-michael-scott-shaking-ed-trucks-hand' target='_blank'>more info</a>|**idea**<br>alt: gentlemen<br><a href='https://knowyourmeme.com/memes/all-right-gentlemen' target='_blank'>more info</a>|
|
||||
|<a href='./templates/handshake.jpg' target='_blank'><img alt='enlarge' src='./preview/handshake.jpg'/></a>|<a href='./templates/handshake2.jpg' target='_blank'><img alt='enlarge' src='./preview/handshake2.jpg'/></a>|<a href='./templates/idea.jpg' target='_blank'><img alt='enlarge' src='./preview/idea.jpg'/></a>|
|
||||
|**lion**<br>alt: shadowy, king, light<br><a href='https://knowyourmeme.com/memes/simba-everything-the-light-touches-is' target='_blank'>more info</a>|**meeting**<br>alt: boardroom, suggestion<br><a href='https://knowyourmeme.com/memes/boardroom-suggestion' target='_blank'>more info</a>|**mini**<br>alt: joker<br><a href='https://knowyourmeme.com/memes/mini-joker' target='_blank'>more info</a>|
|
||||
|<a href='./templates/lion.jpg' target='_blank'><img alt='enlarge' src='./preview/lion.jpg'/></a>|<a href='./templates/meeting.jpg' target='_blank'><img alt='enlarge' src='./preview/meeting.jpg'/></a>|<a href='./templates/mini.jpg' target='_blank'><img alt='enlarge' src='./preview/mini.jpg'/></a>|
|
||||
|**nobody_cares**<br>alt: nobody, jurassic, park, jurassic_park<br><a href='https://knowyourmeme.com/memes/see-nobody-cares' target='_blank'>more info</a>|**nope**<br><a href='https://knowyourmeme.com/memes/disappointed-black-guy' target='_blank'>more info</a>|**overconfident**<br>alt: alcohol, depressed<br><a href='https://knowyourmeme.com/memes/overconfident-alcoholic' target='_blank'>more info</a>|
|
||||
|<a href='./templates/nobody_cares.jpg' target='_blank'><img alt='enlarge' src='./preview/nobody_cares.jpg'/></a>|<a href='./templates/nope.jpg' target='_blank'><img alt='enlarge' src='./preview/nope.jpg'/></a>|<a href='./templates/overconfident.jpg' target='_blank'><img alt='enlarge' src='./preview/overconfident.jpg'/></a>|
|
||||
|**patrick**<br>alt: wallet, id<br><a href='https://knowyourmeme.com/memes/patrick-stars-wallet' target='_blank'>more info</a>|**pigeon**<br>alt: butterfly<br><a href='https://knowyourmeme.com/memes/is-this-a-pigeon' target='_blank'>more info</a>|**pills**<br>alt: swallow<br><a href='https://knowyourmeme.com/memes/hard-to-swallow-pills' target='_blank'>more info</a>|
|
||||
|<a href='./templates/patrick.jpg' target='_blank'><img alt='enlarge' src='./preview/patrick.jpg'/></a>|<a href='./templates/pigeon.jpg' target='_blank'><img alt='enlarge' src='./preview/pigeon.jpg'/></a>|<a href='./templates/pills.jpg' target='_blank'><img alt='enlarge' src='./preview/pills.jpg'/></a>|
|
||||
|**pleasure3**<br>alt: satisfied3|**pleasure4**<br>alt: pleasure, satisfied, satisfied4<br><a href='https://knowyourmeme.com/memes/vince-mcmahon-reaction' target='_blank'>more info</a>|**quality**<br>alt: competition<br><a href='https://knowyourmeme.com/memes/king-neptune-vs-spongebob-squarepants' target='_blank'>more info</a>|
|
||||
|<a href='./templates/pleasure3.jpg' target='_blank'><img alt='enlarge' src='./preview/pleasure3.jpg'/></a>|<a href='./templates/pleasure4.jpg' target='_blank'><img alt='enlarge' src='./preview/pleasure4.jpg'/></a>|<a href='./templates/quality.jpg' target='_blank'><img alt='enlarge' src='./preview/quality.jpg'/></a>|
|
||||
|**salt_bae**<br>alt: salt<br><a href='https://knowyourmeme.com/memes/salt-bae' target='_blank'>more info</a>|**scary**<br>alt: spongebob, fearless<br><a href='https://knowyourmeme.com/memes/spongebob-sees-flying-dutchman' target='_blank'>more info</a>|**seagull2**<br>alt: seagull, screaming<br><a href='https://knowyourmeme.com/memes/inhaling-seagull' target='_blank'>more info</a>|
|
||||
|<a href='./templates/salt_bae.jpg' target='_blank'><img alt='enlarge' src='./preview/salt_bae.jpg'/></a>|<a href='./templates/scary.jpg' target='_blank'><img alt='enlarge' src='./preview/scary.jpg'/></a>|<a href='./templates/seagull2.jpg' target='_blank'><img alt='enlarge' src='./preview/seagull2.jpg'/></a>|
|
||||
|**seagull4**|**see_that_guy**<br><a href='https://knowyourmeme.com/memes/hey-man-you-see-that-guy-over-there' target='_blank'>more info</a>|**sleeping**<br>alt: brain<br><a href='https://knowyourmeme.com/memes/are-you-going-to-sleep' target='_blank'>more info</a>|
|
||||
|<a href='./templates/seagull4.jpg' target='_blank'><img alt='enlarge' src='./preview/seagull4.jpg'/></a>|<a href='./templates/see_that_guy.jpg' target='_blank'><img alt='enlarge' src='./preview/see_that_guy.jpg'/></a>|<a href='./templates/sleeping.jpg' target='_blank'><img alt='enlarge' src='./preview/sleeping.jpg'/></a>|
|
||||
|**spiderman**<br>alt: same<br><a href='https://knowyourmeme.com/memes/spider-man-pointing-at-spider-man' target='_blank'>more info</a>|**struggle**<br>alt: choice, hero<br><a href='https://knowyourmeme.com/memes/daily-struggle' target='_blank'>more info</a>|**t_pose**<br>alt: dominance, monika<br><a href='https://knowyourmeme.com/memes/monika-t-posing-over-sans' target='_blank'>more info</a>|
|
||||
|<a href='./templates/spiderman.jpg' target='_blank'><img alt='enlarge' src='./preview/spiderman.jpg'/></a>|<a href='./templates/struggle.jpg' target='_blank'><img alt='enlarge' src='./preview/struggle.jpg'/></a>|<a href='./templates/t_pose.jpg' target='_blank'><img alt='enlarge' src='./preview/t_pose.jpg'/></a>|
|
||||
|**tom_cousins**<br>alt: cousins, backup, goons<br><a href='https://knowyourmeme.com/memes/tom-and-jerry-hired-goons' target='_blank'>more info</a>|**tough2**<br>alt: tough, fight<br><a href='https://knowyourmeme.com/memes/increasingly-buff-spongebob' target='_blank'>more info</a>|**tough2bis**<br>alt: soft|
|
||||
|<a href='./templates/tom_cousins.jpg' target='_blank'><img alt='enlarge' src='./preview/tom_cousins.jpg'/></a>|<a href='./templates/tough2.jpg' target='_blank'><img alt='enlarge' src='./preview/tough2.jpg'/></a>|<a href='./templates/tough2bis.jpg' target='_blank'><img alt='enlarge' src='./preview/tough2bis.jpg'/></a>|
|
||||
|**tough3**|**trump**<br>alt: law<br><a href='https://knowyourmeme.com/memes/trumps-first-order-of-business' target='_blank'>more info</a>|**trust_nobody**<br>alt: yourself, gun<br><a href='https://knowyourmeme.com/memes/trust-nobody-not-even-yourself' target='_blank'>more info</a>|
|
||||
|<a href='./templates/tough3.jpg' target='_blank'><img alt='enlarge' src='./preview/tough3.jpg'/></a>|<a href='./templates/trump.jpg' target='_blank'><img alt='enlarge' src='./preview/trump.jpg'/></a>|<a href='./templates/trust_nobody.jpg' target='_blank'><img alt='enlarge' src='./preview/trust_nobody.jpg'/></a>|
|
||||
|**truth**<br>alt: scroll<br><a href='https://knowyourmeme.com/memes/the-scroll-of-truth' target='_blank'>more info</a>|**winnie2**<br>alt: winnie<br><a href='https://knowyourmeme.com/memes/tuxedo-winnie-the-pooh' target='_blank'>more info</a>|**winnie3**|
|
||||
|<a href='./templates/truth.jpg' target='_blank'><img alt='enlarge' src='./preview/truth.jpg'/></a>|<a href='./templates/winnie2.jpg' target='_blank'><img alt='enlarge' src='./preview/winnie2.jpg'/></a>|<a href='./templates/winnie3.jpg' target='_blank'><img alt='enlarge' src='./preview/winnie3.jpg'/></a>|
|
||||
|**worthless**<br>alt: gravity_falls, dipper<br><a href='https://knowyourmeme.com/memes/whoa-this-is-worthless' target='_blank'>more info</a>||||
|
||||
|<a href='./templates/worthless.jpg' target='_blank'><img alt='enlarge' src='./preview/worthless.jpg'/></a>||||
|
||||
<!--LIST1-END-->
|
||||
|
||||
### Reactions (no text)
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--LIST2-START-->
|
||||
||||
|
||||
|:---:|:---:|:---:|
|
||||
|**doubt**<br>alt: press_x<br><a href='https://knowyourmeme.com/memes/la-noire-doubt-press-x-to-doubt' target='_blank'>more info</a>|**head_out**<br>alt: ight<br><a href='https://knowyourmeme.com/memes/ight-imma-head-out' target='_blank'>more info</a>|**holup**<br>alt: hold_up<br><a href='https://knowyourmeme.com/memes/vault-boy-hold-up' target='_blank'>more info</a>|
|
||||
|<a href='../templates/doubt.jpg' target='_blank'><img alt='enlarge' src='./preview/doubt.jpg'/></a>|<a href='../templates/head_out.jpg' target='_blank'><img alt='enlarge' src='./preview/head_out.jpg'/></a>|<a href='../templates/holup.jpg' target='_blank'><img alt='enlarge' src='./preview/holup.jpg'/></a>|
|
||||
|**listen**<br>alt: chicken, little_shit<br><a href='https://knowyourmeme.com/memes/listen-here-you-little-shit' target='_blank'>more info</a>|**money**<br>alt: fry<br><a href='https://knowyourmeme.com/memes/shut-up-and-take-my-money' target='_blank'>more info</a>|**pasta**<br>alt: vista, italian<br><a href='https://knowyourmeme.com/photos/1272835-how-italians-do-things' target='_blank'>more info</a>|
|
||||
|<a href='../templates/listen.jpg' target='_blank'><img alt='enlarge' src='./preview/listen.jpg'/></a>|<a href='../templates/money.jpg' target='_blank'><img alt='enlarge' src='./preview/money.jpg'/></a>|<a href='../templates/pasta.jpg' target='_blank'><img alt='enlarge' src='./preview/pasta.jpg'/></a>|
|
||||
|**stonks**<br><a href='https://knowyourmeme.com/memes/stonks' target='_blank'>more info</a>|**white**<br>alt: magazine<br><a href='https://knowyourmeme.com/memes/dave-chappelle-reading-white-people-magazine' target='_blank'>more info</a>|**wtf**<br>alt: excuse_me<br><a href='https://knowyourmeme.com/memes/excuse-me-what-the-fuck' target='_blank'>more info</a>||
|
||||
|<a href='../templates/stonks.jpg' target='_blank'><img alt='enlarge' src='./preview/stonks.jpg'/></a>|<a href='../templates/white.jpg' target='_blank'><img alt='enlarge' src='./preview/white.jpg'/></a>|<a href='../templates/wtf.jpg' target='_blank'><img alt='enlarge' src='./preview/wtf.jpg'/></a>||
|
||||
<!--LIST2-END-->
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Simple template
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE1-START-->
|
||||
>
|
||||
|
||||
```
|
||||
brain3
|
||||
"Making memes using an image editor"
|
||||
"Making memes using a Python script"
|
||||
"Making memes using a Discord bot"
|
||||
```
|
||||
|
||||

|
||||
<!--EXAMPLE1-END-->
|
||||
|
||||
### Example 2: Use of empty texts
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE2-START-->
|
||||
> The 5th text is not set and the 3rd is explicitly set to empty
|
||||
|
||||
```
|
||||
see_that_guy
|
||||
"See that guy over there?"
|
||||
"He uses an image editor to make memes"
|
||||
""
|
||||
"meme-otron's dev"
|
||||
```
|
||||
|
||||

|
||||
<!--EXAMPLE2-END-->
|
||||
|
||||
### Example 3: Text + Template
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE3-START-->
|
||||
> Note how texts make paragraphs
|
||||
|
||||
```
|
||||
text
|
||||
"*Meme has a 'made with meme-otron' watermark*"
|
||||
"reddit: ..."
|
||||
"9gag: ..."
|
||||
"meme-otron's dev:"
|
||||
-
|
||||
culture
|
||||
"meme otron"
|
||||
```
|
||||
|
||||

|
||||
<!--EXAMPLE3-END-->
|
||||
|
||||
|
||||
### Example 4: Complex composition
|
||||
<sub><sup>[↑ back to top](#meme-otron-guide)</sup></sub>
|
||||
|
||||
<!--EXAMPLE4-START-->
|
||||
>
|
||||
|
||||
```
|
||||
image
|
||||
https://i.imgur.com/DNLFUuK.png
|
||||
-
|
||||
text
|
||||
"meme-otron's dev close to finishing the idea"
|
||||
-
|
||||
holup
|
||||
```
|
||||
|
||||

|
||||
<!--EXAMPLE4-END-->
|
||||
@@ -1,10 +1,12 @@
|
||||
import os
|
||||
import logging
|
||||
from typing import List
|
||||
import PIL
|
||||
from os import path
|
||||
from meme_otron import img_factory
|
||||
from meme_otron import meme_db
|
||||
from meme_otron import utils
|
||||
from meme_otron import meme_otron
|
||||
|
||||
logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.WARNING)
|
||||
|
||||
@@ -13,12 +15,66 @@ meme_db.load_memes()
|
||||
|
||||
templates_dir = utils.relative_path(__file__, "templates")
|
||||
preview_dir = utils.relative_path(__file__, "preview")
|
||||
doc_template_file = utils.relative_path(__file__, "README-template.md")
|
||||
doc_file = utils.relative_path(__file__, "README.md")
|
||||
|
||||
COLUMNS = 3
|
||||
IMG_HEIGHT = 400
|
||||
|
||||
|
||||
def main():
|
||||
make_empty(templates_dir)
|
||||
make_empty(preview_dir)
|
||||
|
||||
with open(doc_template_file, mode='r') as f:
|
||||
content = "".join(f.readlines())
|
||||
|
||||
full_list = sorted(meme_db.LIST)
|
||||
template_list = [meme_id for meme_id in full_list if len(meme_db.get_meme(meme_id).texts) > 0]
|
||||
reaction_list = [meme_id for meme_id in full_list if meme_id not in template_list]
|
||||
|
||||
content = produce_template_list(content, "LIST1", template_list)
|
||||
content = produce_template_list(content, "LIST2", reaction_list)
|
||||
|
||||
content = produce_example(content, "EXAMPLE1", "example1.jpg", "",
|
||||
"brain3",
|
||||
"Making memes using an image editor",
|
||||
"Making memes using a Python script",
|
||||
"Making memes using a Discord bot")
|
||||
|
||||
content = produce_example(content, "EXAMPLE2", "example2.jpg",
|
||||
"The 5th text is not set and the 3rd is explicitly set to empty",
|
||||
"see_that_guy",
|
||||
"See that guy over there?",
|
||||
"He uses an image editor to make memes",
|
||||
"",
|
||||
"meme-otron's dev")
|
||||
|
||||
content = produce_example(content, "EXAMPLE3", "example3.jpg",
|
||||
"Note how texts make paragraphs",
|
||||
"text",
|
||||
"*Meme has a 'made with meme-otron' watermark*",
|
||||
"reddit: ...",
|
||||
"9gag: ...",
|
||||
"meme-otron's dev:",
|
||||
"-",
|
||||
"culture",
|
||||
"meme otron")
|
||||
|
||||
content = produce_example(content, "EXAMPLE4", "example4.jpg",
|
||||
"",
|
||||
"image",
|
||||
"https://i.imgur.com/DNLFUuK.png",
|
||||
"-",
|
||||
"text",
|
||||
"meme-otron's dev close to finishing the idea",
|
||||
"-",
|
||||
"holup")
|
||||
|
||||
with open(doc_file, mode='w') as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
def make_empty(target_dir: str):
|
||||
if path.exists(target_dir):
|
||||
for file in os.listdir(target_dir):
|
||||
@@ -28,54 +84,69 @@ def make_empty(target_dir: str):
|
||||
os.mkdir(target_dir)
|
||||
|
||||
|
||||
make_empty(templates_dir)
|
||||
make_empty(preview_dir)
|
||||
def produce_template_list(content: str, tag: str, id_list: List[str]):
|
||||
if len(id_list) == 0:
|
||||
return content
|
||||
doc_content = "|" * (COLUMNS + 1) \
|
||||
+ "\n|" + ":---:|" * COLUMNS
|
||||
info_line = None
|
||||
img_line = None
|
||||
i = None
|
||||
for i, meme_id in enumerate(id_list):
|
||||
meme = meme_db.get_meme(meme_id)
|
||||
img = img_factory.build_from_template(meme.template, meme.texts, debug=True)
|
||||
if img is not None:
|
||||
base = True
|
||||
if len(meme.texts) > 0:
|
||||
base = False
|
||||
image_path = path.join(templates_dir, meme.template)
|
||||
img.save(image_path)
|
||||
size = (round(img.size[0] * IMG_HEIGHT / img.size[1]), IMG_HEIGHT)
|
||||
img2 = img.resize(size, resample=PIL.Image.LANCZOS)
|
||||
img2.save(path.join(preview_dir, meme.template))
|
||||
if i % COLUMNS == 0:
|
||||
if info_line is not None and img_line is not None:
|
||||
doc_content += info_line + img_line
|
||||
info_line = "\n|"
|
||||
img_line = "\n|"
|
||||
info_line += f"**{meme_id}**"
|
||||
if len(meme.aliases) > 0:
|
||||
info_line += f"<br>alt: {', '.join(meme.aliases)}"
|
||||
if meme.info is not None:
|
||||
info_line += f"<br><a href='{meme.info}' target='_blank'>more info</a>"
|
||||
info_line += "|"
|
||||
if base:
|
||||
img_line += f"<a href='../templates/{meme.template}' target='_blank'>"
|
||||
else:
|
||||
img_line += f"<a href='./templates/{meme.template}' target='_blank'>"
|
||||
img_line += f"<img alt='enlarge' src='./preview/{meme.template}'/>" \
|
||||
f"</a>|"
|
||||
print(i, meme_id)
|
||||
info_line += "|" * (COLUMNS - (i % COLUMNS))
|
||||
img_line += "|" * (COLUMNS - (i % COLUMNS))
|
||||
doc_content += info_line + img_line
|
||||
return inject_content(doc_content, content, tag)
|
||||
|
||||
id_list = sorted(meme_db.LIST)
|
||||
|
||||
doc_content = "|" * (COLUMNS + 1) \
|
||||
+ "\n|" + ":---:|" * COLUMNS
|
||||
|
||||
info_line = None
|
||||
img_line = None
|
||||
|
||||
i = None
|
||||
for i, meme_id in enumerate(id_list):
|
||||
meme = meme_db.get_meme(meme_id)
|
||||
img = img_factory.build_image(meme.template, meme.texts, debug=True)
|
||||
def produce_example(content: str, tag: str, file_name: str, note: str, *args: str):
|
||||
doc_content = f"> {note}\n\n" \
|
||||
"```\n" + \
|
||||
" \n".join(['"' + a + '"' if ' ' in a or len(a) == 0 else a for a in args]) + \
|
||||
"\n```\n\n" \
|
||||
f""
|
||||
img, err = meme_otron.compute(*args)
|
||||
if img is not None:
|
||||
img.save(path.join(templates_dir, meme.template))
|
||||
size = (round(img.size[0] * IMG_HEIGHT / img.size[1]), IMG_HEIGHT)
|
||||
img2 = img.resize(size, resample=PIL.Image.LANCZOS)
|
||||
img2.save(path.join(preview_dir, meme.template))
|
||||
if i % COLUMNS == 0:
|
||||
if info_line is not None and img_line is not None:
|
||||
doc_content += info_line + img_line
|
||||
info_line = "\n|"
|
||||
img_line = "\n|"
|
||||
info_line += f"**{meme_id}**"
|
||||
if len(meme.aliases) > 0:
|
||||
info_line += f"<br>alt: {', '.join(meme.aliases)}"
|
||||
if meme.info is not None:
|
||||
info_line += f"<br><a href='{meme.info}' target='_blank'>more info</a>"
|
||||
info_line += "|"
|
||||
img_line += f"" \
|
||||
f"<a href='./templates/{meme.template}' target='_blank'>" \
|
||||
f"<img alt='enlarge' src='./preview/{meme.template}'/>" \
|
||||
f"</a>|"
|
||||
print(i, meme_id)
|
||||
img.save(utils.relative_path(__file__, file_name))
|
||||
return inject_content(doc_content, content, tag)
|
||||
|
||||
doc_content += "|" * (COLUMNS - (i % COLUMNS))
|
||||
|
||||
with open(doc_file, mode='r') as f:
|
||||
content = "".join(f.readlines())
|
||||
def inject_content(new_content, content, tag):
|
||||
start_str = f"<!--{tag}-START-->"
|
||||
end_str = f"<!--{tag}-END-->"
|
||||
i0 = content.index(start_str)
|
||||
i1 = content.index(end_str) + len(end_str)
|
||||
return content[:i0] + start_str + "\n" + new_content + "\n" + end_str + content[i1:]
|
||||
|
||||
i0 = content.index("<!--START-->")
|
||||
i1 = content.index("<!--END-->") + len("<!--END-->")
|
||||
|
||||
with open(doc_file, mode='w') as f:
|
||||
f.write(content[:i0])
|
||||
f.write("<!--START-->\n")
|
||||
f.write(doc_content)
|
||||
f.write("\n<!--END-->")
|
||||
f.write(content[i1:])
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 153 KiB After Width: | Height: | Size: 217 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |