Showing countdown timer in email

Last day I received an email newsletter which contained a countdown timer in it. It was quite interesting because most of the times emails are static and we are unable to show any dynamic data. Then again, there is the GIF image format which can show animated images. From investigating the source I figured that they are doing exactly that. They are using the service from a third party provider to create “countdown” GIF images.

So, I thought why not make one for myself. And I came up with a class to accept target time (end time of countdown) and some other parameters which will return an animated GIF image resource. We can then embed that image in the email and the email body will show a nice little countdown timer. More about the class and usage is available on GitHub.

Demo: A 15 minute timer

15 minutes

Fork the class from GitHub: https://github.com/ashiqur-rony/gif-timer

There is a catch though. As the timer creates a frame for each step (one frame per second in the above demo), this method is really resource hungry.

Vultr VPS
name.com domains
Displate

Posted

in

, ,

by

Tags:

Comments

2 responses to “Showing countdown timer in email”

  1. Ming Avatar
    Ming

    Nice work, however, I give it a try, it shows error message – Notice: A non well formed numeric value encountered on line “$background = ImageColorAllocate($image, $this->bg_color[0], $this->bg_color[1], $this->bg_color[2]);”? do you have any clue? thanks!

    1. Ashiqur Rahman Avatar
      Ashiqur Rahman

      Hi Ming,
      I’m not sure what’s happening. The ImageColorAllocate (http://php.net/ImageColorAllocate) expects last three parameters to be integer values. From the notice it looks like some issue there. Can you debug and see the passed values in that function?

Leave a Reply

Your email address will not be published. Required fields are marked *