1

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

Date Stamp

Can it be done in ImageMagick?

nixnotwin
  • 2,343
  • 8
  • 30
  • 46

3 Answers3

2

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').

Andrea
  • 11,801
  • 17
  • 65
  • 72
2

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

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Could be useful but this is not working for me on CentOS7! Here what errors I get: I only have a straight grey line as result `convert: not authorized DEC @ error/constitute.c/ReadImage/454.` `convert: not authorized 07 @ error/constitute.c/ReadImage/454.` – Clement Dec 07 '21 at 12:47
  • This is a security limitation as described here: (You need to have root to edit those files) [link](https://stackoverflow.com/questions/42928765/convertnot-authorized-aaaa-error-constitute-c-readimage-453) – Clement Dec 07 '21 at 13:58
0

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.