|
| 1 | +Getting Started |
| 2 | +=============== |
| 3 | + |
| 4 | +This tutorial walks you through installing memeplotlib and creating your |
| 5 | +first memes. |
| 6 | + |
| 7 | +Installation |
| 8 | +------------ |
| 9 | + |
| 10 | +Install memeplotlib from PyPI: |
| 11 | + |
| 12 | +.. code-block:: bash |
| 13 | +
|
| 14 | + pip install memeplotlib |
| 15 | +
|
| 16 | +To build the documentation locally, also install Sphinx and its dependencies: |
| 17 | + |
| 18 | +.. code-block:: bash |
| 19 | +
|
| 20 | + pip install memeplotlib[docs] |
| 21 | +
|
| 22 | +Your First Meme |
| 23 | +---------------- |
| 24 | + |
| 25 | +The simplest way to create a meme is with the :func:`~memeplotlib.meme` |
| 26 | +function: |
| 27 | + |
| 28 | +.. code-block:: python |
| 29 | +
|
| 30 | + import memeplotlib as memes |
| 31 | +
|
| 32 | + memes.meme("buzz", "memes", "memes everywhere") |
| 33 | +
|
| 34 | +This fetches the "Buzz Lightyear" template from the `memegen API |
| 35 | +<https://api.memegen.link>`_, renders "MEMES" at the top and |
| 36 | +"MEMES EVERYWHERE" at the bottom, and displays the result with |
| 37 | +``matplotlib.pyplot.show()``. |
| 38 | + |
| 39 | +The first positional argument is the template identifier, and subsequent |
| 40 | +positional arguments are text lines placed at the template's text positions |
| 41 | +(typically top and bottom). |
| 42 | + |
| 43 | +Saving to a File |
| 44 | +----------------- |
| 45 | + |
| 46 | +Pass ``savefig`` to write the meme to disk. Set ``show=False`` if you do not |
| 47 | +want an interactive window: |
| 48 | + |
| 49 | +.. code-block:: python |
| 50 | +
|
| 51 | + memes.meme("doge", "such code", "very bug", |
| 52 | + savefig="meme.png", show=False) |
| 53 | +
|
| 54 | +The output file format is determined by the file extension (PNG, JPEG, PDF, |
| 55 | +SVG, etc.), following matplotlib's conventions. |
| 56 | + |
| 57 | +Customizing Text |
| 58 | +----------------- |
| 59 | + |
| 60 | +Control font, color, and style: |
| 61 | + |
| 62 | +.. code-block:: python |
| 63 | +
|
| 64 | + memes.meme("drake", "writing tests", "shipping to prod", |
| 65 | + font="impact", color="yellow", style="upper") |
| 66 | +
|
| 67 | +Available ``style`` values: |
| 68 | + |
| 69 | +- ``"upper"`` (default) -- converts text to UPPERCASE. |
| 70 | +- ``"lower"`` -- converts text to lowercase. |
| 71 | +- ``"none"`` -- preserves original casing. |
| 72 | + |
| 73 | +Available ``font`` shortcuts: ``"impact"``, ``"arial"``, ``"comic"``, |
| 74 | +``"times"``, ``"courier"``. You can also pass any font family name installed |
| 75 | +on your system. |
| 76 | + |
| 77 | +Controlling Outline |
| 78 | +~~~~~~~~~~~~~~~~~~~~ |
| 79 | + |
| 80 | +The classic meme look uses white text with a black outline. You can customize |
| 81 | +both: |
| 82 | + |
| 83 | +.. code-block:: python |
| 84 | +
|
| 85 | + memes.meme("buzz", "white on black", "the classic", |
| 86 | + color="white", outline_color="black", outline_width=3.0, |
| 87 | + show=False) |
| 88 | +
|
| 89 | +Using Local Images |
| 90 | +------------------- |
| 91 | + |
| 92 | +You can pass a file path instead of a memegen template ID: |
| 93 | + |
| 94 | +.. code-block:: python |
| 95 | +
|
| 96 | + memes.meme("/path/to/image.jpg", "top text", "bottom text") |
| 97 | +
|
| 98 | +HTTP/HTTPS URLs also work: |
| 99 | + |
| 100 | +.. code-block:: python |
| 101 | +
|
| 102 | + memes.meme("https://example.com/image.png", "hello", "world") |
| 103 | +
|
| 104 | +Getting the Figure Back |
| 105 | +------------------------ |
| 106 | + |
| 107 | +:func:`~memeplotlib.meme` returns a ``(Figure, Axes)`` tuple, so you can |
| 108 | +continue to modify the plot before saving or showing: |
| 109 | + |
| 110 | +.. code-block:: python |
| 111 | +
|
| 112 | + fig, ax = memes.meme("buzz", "memes", "memes everywhere", show=False) |
| 113 | + fig.savefig("custom_meme.png", dpi=300) |
| 114 | +
|
| 115 | +Next Steps |
| 116 | +---------- |
| 117 | + |
| 118 | +- See the :doc:`user_guide` for the object-oriented API, memify workflow, |
| 119 | + global configuration, and template discovery. |
| 120 | +- See the :doc:`api` for the complete API reference. |
0 commit comments