-
-
Save GooseNinja/6c7b88631a08da9d80fe1e3f8b01b4d6 to your computer and use it in GitHub Desktop.
This script is for generating and optimizing simple images with text in the center. I am using this to generate the thumbnail images on my website. http://goose.ninja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage () | |
{ | |
echo "This script is for generating and optimizing simple images with text in the center." | |
echo "" | |
echo "usage: sh img [-t \"Text\"] [-s image size] [-o filename.png] [-bg \"#fill color\"] [-c \"#font color\"] [-fs font_size] [-f \"Font\"] [-h | --help]" | |
echo "" | |
echo "Image Settings:" | |
echo " -t 'imagetext' Specify the text to be written on the image" | |
echo " -s imagesize specify the image size. Default: 800x333" | |
echo " -o filename.png specify the output filename. Default: image.png" | |
echo " -bg '#fillcolor' Specify the fill color in hex" | |
echo " -c '#fontcolor' Specify the font color in hex" | |
echo " -fs fontsize Specify the font size" | |
echo " -f 'fontname' Specify the font" | |
echo " -h | --help Print Script Usage" | |
echo "" | |
} | |
text="Default Text" | |
image_size='800x333' | |
image_name='image.png' | |
bg_color='#34495E' | |
font_color='#ffffff' | |
font_size=72 | |
font='Montserrat' | |
while [ "$1" != "" ]; do | |
case $1 in | |
-t ) | |
shift | |
text=$1 | |
;; | |
-s ) | |
shift | |
image_size=$1 | |
;; | |
-o ) | |
shift | |
image_name=$1 | |
;; | |
-bg ) | |
shift | |
bg_color=$1 | |
;; | |
-c ) | |
shift | |
font_color=$1 | |
;; | |
-fs ) | |
shift | |
font_size=$1 | |
;; | |
-f ) | |
shift | |
font=$1 | |
;; | |
-h | --help ) | |
usage | |
exit 0 | |
;; | |
* ) | |
usage | |
exit 1 | |
esac | |
shift | |
done | |
# Using ImageMagic to generate the blog post image | |
convert -size $image_size \ | |
-background $bg_color \ | |
-fill $font_color \ | |
-font $font \ | |
-gravity center \ | |
-pointsize $font_size \ | |
caption:"${text}" \ | |
$image_name | |
# Using pngquant to optimize the image | |
pngquant $image_name --ext=.png --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment