Generating date stamp image in Imagemagick

前端 未结 3 899
心在旅途
心在旅途 2021-01-24 03:16

I have a static html site where I post calendar events. I thought of using Imagemagick to generate date stamp image like this.

3条回答
  •  猫巷女王i
    2021-01-24 04:16

    I may be a couple of years late to the party, but I felt like generating iPhone (or is that iCalendar) style datestamps - and it was raining anyway...

    Here is a bash script, either call it with no parameters to get today's date, or with something like

    DateStamp 12 Jan
    

    to get a different stamp.

    #!/bin/bash
    ################################################################################
    # DateStamp
    # Mark Setchell
    #
    # Generate a date stamp like on iPhone, either using the day and month supplied
    # or, if not supplied, today's date
    #
    # Requires ImageMagick
    ################################################################################
    # Get current day and month in case none supplied
    mn=$(date +'%b')
    dn=$(date +'%d')
    
    # Pick up any day/month supplied and save in $d and $m
    d=${1:-$dn}
    m=${2:-$mn}
    
    # Convert month name to upper case
    m=$(tr [:lower:] [:upper:] <<< $m)
    
    # Set colours for month background/foreground and day background/foreground
    mbg="rgb(128,0,0)"
    mfg="white"
    dbg="rgb(240,240,240)"
    dfg="rgb(128,0,0)"
    
    # Generate stamp
    convert -stroke none -gravity center                                    \
         \( -size 128x64! -background $mbg -fill $mfg label:"$m" \)         \
         -size 128x4! xc:gray40 -append                                     \
         \( -size 128x64! -background $dbg -fill $dfg label:"$d" \) -append \
         -bordercolor white  -border 8                                      \
         -bordercolor gray70 -border 4                                      \
         -bordercolor white  -border 4 result.png
    

提交回复
热议问题