|
2 | 2 | A Python module and command-line tool that generates a |
3 | 3 | [Get Stick Bugged Lol](https://knowyourmeme.com/memes/get-stick-bugged-lol) video from any image. |
4 | 4 |
|
5 | | - |
| 5 | +## Example |
| 6 | +```commandline |
| 7 | +gsbl python.jpg python.mp4 -r 760 475 -s 0.7 |
| 8 | +``` |
| 9 | + |
6 | 10 |
|
7 | | -[Example video with sound](https://github.com/n0spaces/get-stick-bugged-lol/raw/master/examples/python.mp4) |
| 11 | +[Example video with sound](examples/python.mp4) |
8 | 12 |
|
9 | 13 | This script uses [pylsd-nova](https://github.com/AndranikSargsyan/pylsd-nova) to detect line segments in the image, |
10 | 14 | Pillow to draw the lines as they move to form the stick bug, and MoviePy to create the video. |
11 | 15 |
|
| 16 | +## Requirements |
| 17 | +* Python 3.6 or later (any OS) |
| 18 | + |
12 | 19 | ## Installation |
13 | 20 | This package can be installed using pip: |
14 | | -``` |
| 21 | +```commandline |
15 | 22 | pip install get-stick-bugged-lol |
16 | 23 | ``` |
17 | 24 |
|
18 | 25 | ## Usage |
19 | | -#### In the terminal |
| 26 | +### In the terminal |
20 | 27 | Installing the package will register the `gsbl` command in the terminal (or you can use `python -m gsbl`). To use the |
21 | 28 | image `input.png` to generate the video `output.mp4`: |
22 | | -``` |
| 29 | +```commandline |
23 | 30 | gsbl input.png output.mp4 |
24 | 31 | ``` |
25 | 32 | Optional arguments: |
26 | | -* `-h, --help` Display the help message and exit |
27 | | -* `--line-color R G B` RGB color to use for line segments (default: 255 255 211) |
28 | | -* `--bg-color R G B` RGB color to use for background after image disappears (default: 125 115 119) |
29 | | - |
30 | | -More options will be added in later releases. |
| 33 | +* `-h, --help` show this help message and exit |
| 34 | +* `-r --resolution WIDTH HEIGHT` width and height of the video (default: 720 720) |
| 35 | +* `--img-bg-color R G B` RGB background color while the image is visible (default: 0 0 0) |
| 36 | +* `--line-color R G B` RGB color of line segments (default: 255 255 211) |
| 37 | +* `--line-bg-color R G B` RGB background color after image disappears (default: 125 115 119) |
| 38 | +* `-s --scale SCALE` the image scale passed to the line segment detector. Slightly lowering this may improve results in |
| 39 | +large images. This does not affect the image scale in the video (try --resolution instead). (default: 0.8) |
31 | 40 |
|
32 | | -#### In a Python script |
| 41 | +### In a Python script |
33 | 42 |
|
34 | 43 | ```python |
35 | | -import gsbl |
| 44 | +from PIL import Image |
| 45 | +from gsbl.stick_bug import StickBug |
36 | 46 |
|
37 | | -# generate the video from input.png |
38 | | -video = gsbl.generate_stick_bug('input.png') |
| 47 | +# Create the StickBug object |
| 48 | +sb = StickBug(Image.open('example.png')) # parameter can also just be a filepath |
39 | 49 |
|
40 | | -# save the video as output.mp4 |
41 | | -gsbl.save_video(video, 'output.mp4') |
| 50 | +# Change some properties if you want |
| 51 | +sb.video_resolution = (1280, 720) |
| 52 | +sb.lsd_scale = 0.5 |
| 53 | + |
| 54 | +# That's it! The video will be generated the first time you access it |
| 55 | +video = sb.video # MoviePy VideoClip |
| 56 | + |
| 57 | +# Or you can just save it |
| 58 | +sb.save_video('example.mp4') |
| 59 | + |
| 60 | +# If any settings were changed, the video will be regenerated the next time you access it. |
| 61 | +sb.line_color = (128, 0, 255) |
| 62 | +video_purple = sb.video |
42 | 63 | ``` |
43 | 64 |
|
44 | | -## TODO |
45 | | -* Rewrite to be more object-oriented and easier to maintain |
46 | | -* Add more customization options, especially with the line detection and video resolution |
47 | | -* Make a GUI |
| 65 | +#### `StickBug` properties |
| 66 | +* `image` the source PIL Image. You can set this when initializing `StickBug`, or at any time by accessing the property. |
| 67 | +If you want, you can leave this parameter empty while initializing. |
| 68 | +* `segments` a numpy array of the 9 line segments detected. If the line segment detector hasn't run yet, that's done the |
| 69 | +first time this is accessed. The line segment detector will run again if any other properties have changed. This can |
| 70 | +also be set manually if you want. Each row of the array must contain the values `[x1, y1, x2, y2, width]`. |
| 71 | +* `video` (readonly) the MoviePy VideoClip generated by the script. If the video hasn't been generated yet, that's |
| 72 | +done the first time this is accessed. The video will be regenerated if any other properties have changed. |
| 73 | + |
| 74 | +* `video_resolution` the resolution of the video as a tuple |
| 75 | +* `lsd_scale` the image scale passed to the line segment detector. Slightly lowering this may improve results in large |
| 76 | +images. This does not affect the image scale in the video. |
| 77 | +* `img_bg_color` the background color of the video while the image is visible |
| 78 | +* `line_color` the color of the line segments in the video |
| 79 | +* `line_bg_color` the background color of the video after the image disappears |
48 | 80 |
|
49 | 81 | ## License |
50 | 82 | This package is available under the MIT License. See [LICENSE](LICENSE) for more info. |
|
0 commit comments