Initial commit

master
Steven Saus 5 years ago
parent 0d52d2b6e3
commit d217f3f457
  1. 45
      README.md
  2. 54
      all_fortune_image.sh
  3. 33
      fortune_image.sh
  4. BIN
      output.jpg

@ -1,2 +1,45 @@
# khalo
A selfhosted way to create images with quotations using BASH and imagemagick
A selfhosted way to create images with quotations
![Output example](https://raw.githubusercontent.com/uriel1998/khalo/master/output.jpg "Example output")
## Contents
1. [About](#1-about)
2. [License](#2-license)
3. [Prerequisites](#3-prerequisites)
4. [How to use](#4-how-to-use)
5. [TODO](#5-todo)
***
## 1. About
These programs creates an image with text upon it from either a `fortune` file or a plain text file.
## 2. License
This project is licensed under the MIT license. For the full license, see `LICENSE`.
## 3. Prerequisites
### These may already be installed on your system.
* `imagemagick` command-line tool for manipulating images. `imagemagick` can be found on major Linux distributions.
* `wget` command-line tool for downloading files. `wget` can be found on major Linux distributions.
### Optional
* `fortune` command-line tool for providing "fortunes". `fortune` can be found on major Linux distributions.
* `slugify` if you wish to have filenames that mirror the text of the quotation. I used [slugify-cli](https://github.com/sindresorhus/slugify-cli), which is a node.js program.
## 4. How to use
* If you wish to use your fortune file and get one quotation a day, use `fortune_image.sh`. As configured now, it will output one image to your `$HOME` directory.
* If you wish to specify which fortune file to use, edit `Fortune=$(/usr/games/fortune)` to read `Fortune=$(/usr/games/fortune MyFortuneFile)`
* If you wish to use a plain text file and output all of the quotations at once to your home directory, use `all_fortune_image.sh` with the text file as the first argument.
* Note that you will have to edit the sizes on lines 23 and 30 to get different output sizes.
## 5. Todo
* TBH, I'm probably not going to clean this up a lot more; there are too many variables possible for me to account for all of them.

@ -0,0 +1,54 @@
#!/bin/bash
########################################################################
# Declarations
########################################################################
declare Fortune
TempDir=$(mktemp -d)
if [ -f "$1" ];then
#fb: 1200x628
#istory: 1080x920
#iphoto: 1080x1080
#twitter: 440x220
#generic wide: 1024x512
################################################################################
# Wherein things get told to happen
################################################################################
main() {
while read -r line;do
bob=`wget https://source.unsplash.com/random/1024x512 -O $TempDir/unsplash.jpg`
convert $TempDir/unsplash.jpg -blur 0x3 $TempDir/unsplash_blur.jpg
if [[ "$line" =~ " -" ]];then
Fortune=$(echo "$line" | sed 's/ -/\n-/g' )
else
Fortune=$(echo "$line")
fi
/usr/bin/convert -background none -fill white -stroke black -strokewidth 3 -gravity Center -font Interstate -size 800x512 \
caption:"$Fortune" \
$TempDir/TextImage.png
if [ -f /usr/local/bin/slugify ];then
filename=$(/usr/local/bin/slugify "$Fortune")
else
filename=$(cat /proc/sys/kernel/random/uuid)
fi
/usr/bin/composite -gravity center $TempDir/TextImage.png $TempDir/unsplash_blur.jpg "$HOME"/"$filename".jpg
rm $TempDir/TextImage.png
rm $TempDir/unsplash_blur.jpg
rm $TempDir/unsplash.jpg
sleep 10
done < "$1"
exit 0
}
main
fi

@ -0,0 +1,33 @@
#!/bin/bash
########################################################################
# Declarations
########################################################################
declare Fortune
TempDir=$(mktemp -d)
################################################################################
# Wherein things get told to happen
################################################################################
main() {
bob=`wget https://source.unsplash.com/random/1024x512 -O $TempDir/unsplash.jpg`
convert $TempDir/unsplash.jpg -blur 0x3 $TempDir/unsplash_blur.jpg
Fortune=$(/usr/games/fortune)
/usr/bin/convert -background none -fill white -stroke black -strokewidth 3 -gravity Center -font Interstate -size 800x512 \
caption:"$Fortune" \
$TempDir/TextImage.png
/usr/bin/composite -gravity center $TempDir/TextImage.png $TempDir/unsplash_blur.jpg "$HOME"/quote.jpg
exit 0
}
main
rm $TempDir/TextImage.png
rm $TempDir/unsplash_blur.jpg
rm $TempDir/unsplash.jpg
rmdir $TempDir

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Loading…
Cancel
Save