Generating date stamp image in Imagemagick

前端 未结 3 897
心在旅途
心在旅途 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条回答
  • 2021-01-24 04:00

    Assuming that image a.png contains the background (white rectangle with red band) you can use:

    convert a.png -gravity Center -pointsize 24 -annotate +0+0 "16" -gravity North -fill white -pointsize 18 -annotate +0+0 "FEB" output.png
    

    You'll probably have to tweak +0+0 coordinates to correctly fit your background image.
    Also note that this is a static command that generates the example you posted (with month fixed to 'FEB' and day fixed to '16').

    0 讨论(0)
  • 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
    

    0 讨论(0)
  • 2021-01-24 04:16

    Yeah Imagemagick can do that. http://www.imagemagick.org/Usage/text/ has lots of examples. It might be best to write a small python script that takes month and date and supplies the proper arguments to Imagemagick once you figure out what you want.

    0 讨论(0)
提交回复
热议问题