Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Python script to add caption bubble and text to images via CLI.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
EXAMPLES are in demo.sh file. I built this on OS X Mavericks. It may not work on anything else. I used brew to install libjpeg and pip to install PIL #brew install libjpeg #<stuff happens> #pip install PIL once you've got all that, you should be able to run 'python addcap.py -h' to get the list below. If you run 'sh demo.sh' it will tun the program a bunch of times and create a series of captioned images in the 'demo' folder that it creates. As it stands in the demo, the newly created images will OVERWRITE any 'created' pictures. This is by design, or really, lack of care for the 'created' pictures since they can be re-created easily. If you pass the same -o file prefix and -f folder, it will overwrite the images there, it will not check and create a unique filename. Some basics. The upper left corner of the image is (x,y) (0,0). From that coordinate, moving right increases (x). Moving down increases (y) If you have an image that is 1600x1200, the middle coordinate is (800,600). If you set your startX and startY to (800,600), you then need to tell the script which corner this is. The options are UPPER_LEFT LOWER_LEFT LOWER_RIGHT UPPER_RIGHT This tells the script which direction to draw the bubble. If your start corner is UPPER_LEFT, the script does the math to draw the box down and to the right. If your start corner is LOWER_RIGHT, the script does the math to figure out where UPPER_LEFT is, then draws the box from there. The PIL drawing methods all start in UPPER_LEFT, go down to LOWER_LEFT, go over to LOWER_RIGHT, then up to UPPER_RIGHT, then back to the starting UPPER_LEFT. python addcap.py -h usage: addcap.py [-h] [-i IMG] [-sx STARTX] [-sy STARTY] [-tw TEXTWRAPWIDTH] [-fs FONTSIZE] [-cc CHARACTERCOUNT] [-sc STARTINGCORNER] [-ca CALLOUTARROW] [-f FOLDER] [-o OUTFILE] [-qf QUOTEFILE] [-q QUOTE [QUOTE ...]] optional arguments: -h, --help show this help message and exit -i IMG, --img IMG Image to add a caption to. -sx STARTX, --startX STARTX Starting X Coordinate for caption bubble. -sy STARTY, --startY STARTY Starting Y Coordinate for caption bubble. -tw TEXTWRAPWIDTH, --textWrapWidth TEXTWRAPWIDTH How many characters before a line wrap in the bubble? -fs FONTSIZE, --fontSize FONTSIZE Font size -cc CHARACTERCOUNT, --characterCount CHARACTERCOUNT Character count. limited to 140 by default. -sc STARTINGCORNER, --startingCorner STARTINGCORNER The corner that your start coordinates create. Values are Values are UPPER_LEFT, LOWER_LEFT, LOWER_RIGHT, UPPER_RIGHT -ca CALLOUTARROW, --calloutArrow CALLOUTARROW Which call out arrow do you want, starting at 11oclock, going counter clockwise. Just put the number, like 6 -f FOLDER, --folder FOLDER If defined, create a folder and store addcap images there. Otherwise defaults to current folder. -o OUTFILE, --outfile OUTFILE The outfile prefix name. Will append a number and JPG to the end. -qf QUOTEFILE, --quoteFile QUOTEFILE A file with 1 quote per line. Quotes should not exceed 140 characters. -q QUOTE [QUOTE ...], --quote QUOTE [QUOTE ...] One or more quotes in the form "This is a quote.", "This is another quote", "This is yet another quote". Individual quotes should not exceed 140 characters.