A PHP GD + TwitterOAuth demo to dynamically generate Twitter header images and upload them via the API.

Related tags

Imagery dynacover
Overview

dynacover

A PHP GD + TwitterOAuth demo to dynamically generate Twitter header images and upload them via the API. This enables you to build cool little tricks, like showing your latest followers or sponsors, latest content creted, a qrcode to something, a progress bar for some goal, and whathever you can think of.

The demo is explained in detail in this guide: How to Dynamically Update Twitter Cover Image to Show Latest Followers Using PHP GD and TwitterOAuth.

Requirements

  • PHP (cli only) 7.4+
  • GD / PHP-GD
  • Curl
  • Composer

You also need to register an application within the Twitter Developers Portal and obtain 4 tokens:

  • Consumer / App Token
  • Consumer / App Secret
  • User / Access Token
  • User / Access Token Secret

Additionally, you can set up a Personal GitHub API key to fetch your sponsors, in case you are enrolled in the GitHub Sponsors program ,and you want to use the included cover_sponsors.json template. This is optional.

Installation

Installation is done in a few steps: clone, install dependencies, set up credentials, and you are ready to go.

1. Clone this repository

Start by cloning this repository to your local PHP dev environment or remote PHP server:

git clone https://github.com/erikaheidi/dynacover.git
cd dynacover

2. Install Composer Dependencies

composer install

This will install a few dependencies and generate a credentials.php file in the root folder of your application.

3. Set Up Twitter Credentials

Open the generated credentials.php file and set up your credentials:

#credentials.php

return [
    'twitter_consumer_key' => 'APP_CONSUMER_KEY',
    'twitter_consumer_secret' => 'APP_CONSUMER_SECRET',
    'twitter_user_token' => 'USER_ACCESS_TOKEN',
    'twitter_token_secret' => 'USER_ACCESS_TOKEN_SECRET',

    'github_api_bearer' => 'GITHUB_API_BEARER_TOKEN'
];

The github_api_bearer token is optional, only in case you want to use the GitHub API to fetch Sponsors.

Replace the keys accordingly and save the file.

4. Test Twitter Connection

To test that your credentials are valid, you can list your latest followers with:

php dynacover fetch followers

If everything is set up correctly, you will see a list with your 10 latest followers.

5. Choose a Template and Preview your Cover

To preview your cover without uploading it to Twitter, run:

php dynacover generate twitter

This will use the default cover_basic.json template. You can specify a template with the template=template_path parameter:

php dynacover generate twitter template=app/Resources/templates/cover_neon.json

Built-in templates are located in the app/Resources/templates directory. You can also create your own templates in any preferred location and pass the template json path as parameter, relative to the application root folder. Check the included templates to see how it works. Ideally, you should choose a default template and set it up within the dynacover script configuration.

Covers are generated in the root of the application folder, with the name latest_header.png. Check the generated image before uploading it to Twitter to confirm it has your latest followers, and it looks like you expect.

Available Templates

cover_basic.json

The default template shows latest 5 Twitter followers.

cover_colorful.json

Similar to the basic cover, but with a more colorful background. Shows latest 5 Twitter followers.

cover_neon.json

This template shows your latest 5 Twitter followers in smaller size, in a blue-neon style header.

cover_sponsors.json

This template uses the Github image source to obtain sponsors and include them in the banner. Make sure you have set up your GH token on the credentials.php file.

6. Upload to Twitter

To upload the latest generated cover to twitter, run:

php dynacover cover upload

To generate and update your cover using the template that is configured as default in the app config, run:

php dynacover cover update

7. Set Up Crontab (Optional)

For this to be completely dynamic and update frequently, you'll need to include the script to your Crontab or equivalent. First make sure you set up the default_template config parameter in the dynacover script to your preferred template. By default, this is app/Resources/templates/cover_basic.json.

To open the current user's crontab, run:

crontab -e

This will open up a text editor. You should include the full paths to both the php executable and the dynacover script, like in this example which will update the cover every 5 minutes:

*/5 * * * * /usr/bin/php /home/erika/dynacover/dynacover cover update > /dev/null 2>&1
Comments
  • PHP 8.0 generates white image

    PHP 8.0 generates white image

    Hi.

    There are no PHP requirements defined in the composer.json so I tried it out with PHP 8.0. The result was that my cover image was just white. Nothing else.

    I see no errors, so I don't know yet what the problem can be.

    I have created this issue for visibility, in case others will run into this.

    I'll take a look at this when I find some more time.

    Thanks for this really cool little "tool".

    bug 
    opened by tomasnorre 3
  • php dynacover twitter - Command

    php dynacover twitter - Command "twitter" not found

    Hi,

    It looks to me like the command suggested in section 5 with twitter is incorrect or not implemented yet. https://github.com/erikaheidi/dynacover#5-choose-a-template-and-preview-your-cover

    I get following Command "twitter" not found

    opened by tomasnorre 3
  • Suggestion: Random GitHub Sponsor

    Suggestion: Random GitHub Sponsor

    I would like to suggest having the GitHub Sponsor picked Randomly, as I read it now, they are not random.

    The ones displayed at mine isn't even in order, it's my two first and my latest, and they don't get update when updating the image. So looks like there is no random implemented yet, also not from reading the code.

    opened by tomasnorre 2
  • How to add GitHub Sponsors?

    How to add GitHub Sponsors?

    Hi,

    I have added my github_api_bearer to my credentials.php but I don't find any command or call to command for fetching GitHub sponsors. I thought at first that it was based on template selected, but switching template isn't working for me with the template= param.

    opened by tomasnorre 2
  • Give error when GitHub Bearer Token is not created with correct scope

    Give error when GitHub Bearer Token is not created with correct scope

    This is related to my problem in issue #4 , so I thought it would help to improve the error handling.

    I'm not sure if this is handle correctly. I don't know if your minicli have similar to Symfony console $output->writeln('<error>foo</error>'); So I throw a RuntimeException, but I'm up for suggestions :)

    Update: I found it (minicli output), so I added a suggestion to how it could be done, let me know what you think.

    opened by tomasnorre 1
  • Unsure what im doing wrong

    Unsure what im doing wrong

    Fatal error: Uncaught TypeError: Typed property GDaisy\Template::$width must be int, null used in /dynacover/vendor/erikaheidi/gdaisy/src/Template.php:37 Stack trace: #0 /dynacover/app/Template.php(21): GDaisy\Template->loadJson('/github/workspa...') #1 /dynacover/app/Template.php(14): App\Template->loadJson('/github/workspa...') #2 /dynacover/app/Command/Generate/TwitterController.php(34): App\Template::create('/github/workspa...') #3 /dynacover/vendor/minicli/minicli/src/Command/CommandController.php(38): App\Command\Generate\TwitterController->handle() #4 /dynacover/vendor/minicli/minicli/src/App.php(159): Minicli\Command\CommandController->run(Object(Minicli\Command\CommandCall)) #5 /dynacover/app/Command/Cover/UpdateController.php(15): Minicli\App->runCommand(Array) #6 /dynacover/vendor/minicli/minicli/src/Command/CommandController.php(38): App\Command\Cover\UpdateController->handle() #7 /dynacover/vendor/minicli/minicli/src/App.php(159): Minicli\Command\CommandController->run(Object(Minicli\Command\CommandCall)) #8 in /dynacover/vendor/erikaheidi/gdaisy/src/Template.php on line 37

    opened by PockySweet 0
  • Upgrading Dynacover to Minicli 3.2+ and PHP 8.1+

    Upgrading Dynacover to Minicli 3.2+ and PHP 8.1+

    This PR upgrades Dynacover to use Minicli 3.2+ and PHP 8.1+ as dependencies. This was necessary to improve the code and the OCI containers running Dynacover as GitHub Actions.

    opened by erikaheidi 0
  • New Interactions Banner

    New Interactions Banner

    This PR brings the interactions banner command, and updates gdaisy to use rounded / circle avatars.

    New Command

    php dynacover generate interactions [--mutuals]
    
    opened by erikaheidi 0
  • Node.js 12 actions deprecated

    Node.js 12 actions deprecated

    Hello,

    Trying to run dynacover.yml, I received this message :

    "Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: actions/checkout@v2"

    Am I the only one ?

    opened by franckfontelot 0
  • Getting this using github actions

    Getting this using github actions

    Generating new cover...
    
    Fatal error: Uncaught TypeError: Argument 2 passed to GDaisy\Placeholder\ImagePlaceholder::apply() must be of the type array, null given, called in /dynacover/app/Command/Generate/TwitterController.php on line 61 and defined in /dynacover/vendor/erikaheidi/gdaisy/src/Placeholder/ImagePlaceholder.php:35
    Stack trace:
    #0 /dynacover/app/Command/Generate/TwitterController.php(61): GDaisy\Placeholder\ImagePlaceholder->apply(Resource id #69, NULL)
    #1 /dynacover/vendor/minicli/minicli/src/Command/CommandController.php(38): App\Command\Generate\TwitterController->handle()
    #2 /dynacover/vendor/minicli/minicli/src/App.php(159): Minicli\Command\CommandController->run(Object(Minicli\Command\CommandCall))
    #3 /dynacover/app/Command/Cover/UpdateController.php(15): Minicli\App->runCommand(Array)
    #4 /dynacover/vendor/minicli/minicli/src/Command/CommandController.php(38): App\Command\Cover\UpdateController->handle()
    #5 /dynacover/vendor/minicli/minicli/src/App.php(159): Minicli\Command\CommandController->run(Object(Minicli\Command\CommandCa in /dynacover/vendor/erikaheidi/gdaisy/src/Placeholder/ImagePlaceholder.php on line 35
    
    opened by PockySweet 4
  • Im just dumb. Forget this

    Im just dumb. Forget this

    Fatal error: Uncaught TypeError: Argument 2 passed to GDaisy\Placeholder\ImagePlaceholder::apply() must be of the type array, null given, called in /home/dynacover/dynacover/app/Command/Generate/TwitterController.php on line 49 and defined in /home/dynacover/dynacover/vendor/erikaheidi/gdaisy/src/Placeholder/ImagePlaceholder.php:35 Stack trace: #0 /home/dynacover/dynacover/app/Command/Generate/TwitterController.php(49): GDaisy\Placeholder\ImagePlaceholder->apply(Resource id #78, NULL) #1 /home/dynacover/dynacover/vendor/minicli/minicli/src/Command/CommandController.php(38): App\Command\Generate\TwitterController->handle() #2 /home/dynacover/dynacover/vendor/minicli/minicli/src/App.php(159): Minicli\Command\CommandController->run(Object(Minicli\Command\CommandCall)) #3 /home/dynacover/dynacover/app/Command/Cover/UpdateController.php(15): Minicli\App->runCommand(Array) #4 /home/dynacover/dynacover/vendor/minicli/minicli/src/Command/CommandController.php(38): App\Command\Cover\UpdateController->handle() #5 /home/dynacover/dy in /home/dynacover/dynacover/vendor/erikaheidi/gdaisy/src/Placeholder/ImagePlaceholder.php on line 35

    opened by juxty 2
  • Suggestion: Update Twitter bio to be able to link to sponsors

    Suggestion: Update Twitter bio to be able to link to sponsors

    An Idea:

    Update the Twitter bio automatically.

    Have a "standard text" and a sponsored part:

    Could be highlighting one of the sponsors, or only sponsors of tier bigger than X.

    E.g. my twitter profile

    European with a Danish Passport, living in Germany. 
    PHP & TYPO3 Developer, DevOps, Golfing etc.
    
    Sponsored On GitHub By: @username and @user2
    
    enhancement 
    opened by tomasnorre 0
Releases(1.0.1)
  • 1.0.1(Sep 28, 2022)

  • 0.4(Nov 14, 2021)

    This version introduces new configuration options to allow for image and template customization, and for extended GitHub Actions support.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Nov 14, 2021)

  • 0.3.0(Oct 14, 2021)

  • 0.2.1(Jul 2, 2021)

    This version introduces rounded / circle thumbnails via Gdaisy, and the new generate interactions command to generate a banner with your recent interactions.

    Source code(tar.gz)
    Source code(zip)
  • 0.2(Jun 26, 2021)

    Version 0.2 uses erikaheidi/gdaisy as requirement, that way we standardize the JSON template system and introduce the ability to write text on images. This version uses a slightly different template format, be aware when updating. The default JSON templates that come with the application where updated to the new format.

    Source code(tar.gz)
    Source code(zip)
  • 0.1(Jun 3, 2021)

Owner
Erika Heidi
Creative developer & content creator passionate about open source, Linux, and PHP. Senior Technical Writer @digitalocean. GitHub Star ⭐
Erika Heidi
⚡ Dynamically generated, customizable SVG that gives the appearance of typing and deleting text. Typing SVGs can be used as a bio on your Github profile readme or repository.

⚡ Dynamically generated, customizable SVG that gives the appearance of typing and deleting text. Typing SVGs can be used as a bio on your Github profile readme or repository.

Jonah Lawrence 2k Jan 9, 2023
The image server plugin allows you to add responsive images via config without extra elements

Grav image server plugin adds picture tag with loading, responsive, high density images

catchIT 7 Dec 30, 2022
The Tinify API allows you to compress and optimize WebP, JPEG and PNG images.

The Tinify API allows you to compress and optimize WebP, JPEG and PNG images. It is designed as a REST service. The client libraries in various languages make it very easy to interact with the Tinify API.

Devscast 10 May 13, 2022
The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API

Gregwar's Image class The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API. Installation With compos

Grégoire Passault 958 Dec 29, 2022
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

QCode.in 708 Dec 22, 2022
PHP library to resize, scale and crop images.

PHP library to resize, scale and crop images.

Gumlet 1.1k Jan 3, 2023
Simple, fast and secure archive for images

Slim Image Archive Simple*, fast and secure archive for images: Create multiple categories with multiple albums with multiple images! Manage multiple

KS 24 Oct 23, 2021
GifCreator is a PHP class that creates animated GIF from multiple images

================================ GifCreator ================================ GifCreator is a PHP class to create animated GIF from multiple images For

Clément Guillemain 320 Dec 15, 2022
Inline Images Protocol implementation for PHP.

Imgecho Echo the image on iTerm App using Inline Images Protocol. Installation Use Composer to install. composer require mileschou/imgecho Usage Use

MilesChou 4 May 30, 2022
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library

================================ ImageWorkshop class ================================ Summary and features Really flexible and easy-to-use PHP class t

Clément Guillemain 853 Dec 27, 2022
Create images with embedded text using advanced typography

Image with Text This class makes it super easy to render images with multiple, independently styled text blocks. You can control each text block's ali

New Media Campaigns 144 Sep 7, 2022
Easily convert images with Glide

Easily convert images with Glide This package provides an easy to use class to manipulate images. Under the hood it leverages Glide to perform the man

Spatie 374 Dec 30, 2022
Optimize your images on the fly with Glide for Laravel.

Glide for Laravel Optimize your images on the fly with Glide for Laravel. Support us Like our work? You can support us by purchasing one of our produc

Flowframe 53 Oct 17, 2022
Create beautiful generative background images from a string. Based on jasonlong/geo_pattern

GeoPattern This is a PHP port of jasonlong/geo_pattern. Generate beautiful tiling SVG patterns from a string. The string is converted into a SHA and a

Redeye Group 106 Aug 17, 2022
Contao extension to provide the possibility of defining alternative images to be used on different output devices.

Contao Image Alternatives This extensions expands the capabilities of using responsive images with art direction in Contao. You will have the possibil

inspiredminds 6 May 30, 2022
An easy and elegant way to generate gravatars 🖼

pH2Gravatar The simplest Gravatar PHP package An easy and elegant way to generate gravatar profile photos from email addresses ?? ⛏ Requirements PHP 7

♚ PH⑦ de Soria™♛ 6 Jul 12, 2022
Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing

Laravel ZATCA E-invoicing Introduction Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing Installation To get the la

Ayman Alaiwah 8 Aug 17, 2022
This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

This is a class of php QR Code, This library helps you generate QR codes in a jiffy.

null 59 Oct 5, 2022
A library using PHP to generate QRCode from https://www.qrcode-monkey.com free

PHP Class Generate Free QRCode ?? A library using PHP to generate QRCode from https://www.qrcode-monkey.com free ✋ NOTE: Do not generate too many QRCo

Nguyen Truong Nguyen 53 Dec 28, 2022