Skip to content

Commit f4b598b

Browse files
committed
Update readme and examples
1 parent 6ab9263 commit f4b598b

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

README.md

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,81 @@
22
A Python module and command-line tool that generates a
33
[Get Stick Bugged Lol](https://knowyourmeme.com/memes/get-stick-bugged-lol) video from any image.
44

5-
![Example](examples/python.gif)
5+
## Example
6+
```commandline
7+
gsbl python.jpg python.mp4 -r 760 475 -s 0.7
8+
```
9+
![Example GIF](examples/python.gif)
610

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)
812

913
This script uses [pylsd-nova](https://github.com/AndranikSargsyan/pylsd-nova) to detect line segments in the image,
1014
Pillow to draw the lines as they move to form the stick bug, and MoviePy to create the video.
1115

16+
## Requirements
17+
* Python 3.6 or later (any OS)
18+
1219
## Installation
1320
This package can be installed using pip:
14-
```
21+
```commandline
1522
pip install get-stick-bugged-lol
1623
```
1724

1825
## Usage
19-
#### In the terminal
26+
### In the terminal
2027
Installing the package will register the `gsbl` command in the terminal (or you can use `python -m gsbl`). To use the
2128
image `input.png` to generate the video `output.mp4`:
22-
```
29+
```commandline
2330
gsbl input.png output.mp4
2431
```
2532
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)
3140

32-
#### In a Python script
41+
### In a Python script
3342

3443
```python
35-
import gsbl
44+
from PIL import Image
45+
from gsbl.stick_bug import StickBug
3646

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
3949

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
4263
```
4364

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
4880

4981
## License
5082
This package is available under the MIT License. See [LICENSE](LICENSE) for more info.

examples/python.gif

2.26 MB
Loading

examples/python.mp4

-515 KB
Binary file not shown.

gsbl/__main__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,13 @@ def main():
1717
metavar=('R', 'G', 'B'),
1818
help='RGB background color after image disappears (default: 125 115 119)')
1919
parser.add_argument('-s --scale', dest='lsd_scale', type=float, default=0.8, metavar='SCALE',
20-
help='the image scale passed to the line segment detector. Slightly lowering this may improve'
20+
help='the image scale passed to the line segment detector. Slightly lowering this may improve '
2121
'results in large images. This does not affect the image scale in the video (try '
2222
'--resolution instead). (default: 0.8)')
2323

2424
args = parser.parse_args()
2525

26-
try:
27-
from gsbl.stick_bug import StickBug
28-
except ImportError:
29-
# if running this file directly while the package isn't installed
30-
# noinspection PyUnresolvedReferences
31-
from stick_bug import StickBug
26+
from gsbl.stick_bug import StickBug
3227

3328
sb = StickBug(img=args.input, video_resolution=args.resolution, lsd_scale=args.lsd_scale,
3429
img_bg_color=args.img_bg_color, line_color=args.line_color, line_bg_color=args.line_bg_color)

0 commit comments

Comments
 (0)