Created
July 24, 2014 23:47
-
-
Save ereami/9fccc24a6b139ec8ac17 to your computer and use it in GitHub Desktop.
Ever needed to generate simple test images with specific labels and different sizes? My specific use case involved creating the images and verify that they were being correctly delivered as ads in mobile apps. ImageMagick and Bash to the rescue!
This file contains hidden or 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
# Usage: generate_image name widthxheight | |
# Example: generate_image desktop 1024x768 | |
generate_image() { | |
type=$1 | |
size=$2 | |
fname=ad_"$type"_"$size".png | |
echo $fname; | |
convert -size $size -font Bookman-Light -gravity center label:"VEJA.com 2.0\n$type\n$size" $fname | |
} | |
# Usage: generate_images name (widthxheight)* | |
# Example: generate_images xga 640x480 800x600 1024x768 | |
generate_images() { | |
type=$1 | |
shift 1 | |
sizes=$@ | |
for size in $sizes; do | |
generate_image $type $size; | |
done | |
} | |
AD_SPLASH="splash 320x480" | |
AD_HOME="home 137x57 320x50 320x480 320x66 320x187" | |
# This will take every environment variable with an AD_ prefix and use its value as a parameter for generate_images | |
for ad_var_name in ${!AD_*}; do | |
ad_variable=$ad_var_name; | |
generate_images ${!ad_variable}; | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment