Reference¶
The main class¶
- class imgflip.Imgflip(username, password, session=None)¶
The main Imgflip class
- Parameters
username (
str) – your imgflip usernamepassword (
str) – your imgflip passwordsession (Optional[Union[requests.sessions.Session, aiohttp.client.ClientSession]]) – the session which will be used by the class. If it is
requests.Session, the methods of this would be sync and ifaiohttp.ClientSession, the methods would be async.
- Raises
TypeError – if the session is not
requests.Sessionoraiohttp.ClientSession
- popular_memes(limit=100, dictionary=True)¶
- This function is a coroutine if the session is
aiohttp.ClientSessionGet the most popular meme templates from imgflip based on how many times they get captioned.- Parameters
- Returns
the popular meme templates
- Return type
- make_meme(template, font='impact', max_font_size=50, top_text=None, bottom_text=None, boxes=None)¶
- This function is a coroutine if the session is
aiohttp.ClientSessionCreates a meme.- Parameters
template (Union[
int,Template]) – the template to use for the meme. You can pass the template id here.font (Literal["impact", "arial"]) – the font to use for the text. Defaults to impact.
max_font_size (Optional[
int]) – the maximum font size of the texttop_text (Optional[
str]) – the text at the top (or the text for the first box) of the memebottom_text (Optional[
str]) – the text at the bottom (or the text for the second box) of the memeboxes (Optional[List[
Box]]) – the text boxes to use in the meme
Note
if you use top_text/bottom_text and boxes together, boxes would be used in making the meme.
- Raises
ImgflipError – Something went wrong while making the meme.
- Returns
the meme which has been created in imgflip
- Return type
Objects¶
- class imgflip.Meme(template_id, url, page_url, session)¶
-
- template_id¶
the id of the meme template
- Type
int
- url¶
the image url of the meme
- Type
str
- page_url¶
the url of the imgflip page of the meme
- Type
str
- class imgflip.SyncMeme(template_id, url, page_url, session)¶
This is a subclass of
Meme. It is returned inmake_meme()when the session passed isrequests.Session- read()¶
Reads the meme and get the bytes of the image
- Returns
the image of the meme in bytes
- Return type
bytes
- save(fp)¶
Saves the meme image in a file. This returns nothing.
- Parameters
fp (
os.PathLike) – the file path to save the image to.
- class imgflip.AsyncMeme(template_id, url, page_url, session)¶
This is a subclass of
Meme. It is returned inmake_meme()when the session passed isaiohttp.ClientSession
- class imgflip.Box(text, position, size, color='#ffffff', outline_color='#000000')¶
- Represents a text box that can be used in the
boxesparameter ofmake_meme().str(box_obj)will return the text of the box.- Parameters
text (
str) – the text on the boxposition (Tuple[
int,int]) – the position of the box on the meme in the format (x, y)size (Tuple[
int,int]) – the size of the box in the format (width, height)color (Optional[
str]) – the hex color of the text on the box. Defaults to"#ffffff"outline_color (Optional[
str]) – the outline hex color of the text on the box. Defaults to"#000000"
- class imgflip.Template(id, name=None, url=None, width=None, height=None, box_count=None)¶
- Represents a meme template which can be passed into
make_meme().int(template_obj)will return the id of the template.str(template_obj)will return the name of the template.- id¶
the template id
- Type
int
- name¶
the name of the template
- Type
Optional[
str]
- url¶
the image url of the template
- Type
Optional[
str]
- width¶
the width of the template image
- Type
Optional[
int]
- height¶
the height of the template image
- Type
Optional[
int]
- box_count¶
the number of boxes in the template
- Type
Optional[
int]