Running Dynacover on a PHP CLI environment - erikaheidi/dynacover GitHub Wiki

It is also possible to run Dynacover in a local PHP environment. This will require:

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

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 config.php file in the root folder of your application.

3. Set Up Twitter Credentials

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

#config.php
<?php

return [
    //Twitter API Keys
    'twitter_consumer_key' => getenv('DYNA_TWITTER_KEY') ?: 'APP_CONSUMER_KEY',
    'twitter_consumer_secret' => getenv('DYNA_TWITTER_SECRET') ?: 'APP_CONSUMER_SECRET',
    'twitter_user_token' => getenv('DYNA_TWITTER_TOKEN') ?: 'USER_ACCESS_TOKEN',
    'twitter_token_secret' => getenv('DYNA_TWITTER_TOKEN_SECRET') ?: 'USER_ACCESS_TOKEN_SECRET',

    //GitHub Personal Token (for templates using GH Sponsors)
    'github_api_bearer' => getenv('DYNA_GITHUB_TOKEN') ?: 'GITHUB_API_BEARER_TOKEN',

    //Paths
    'templates_dir' => getenv('DYNA_TEMPLATES_DIR') ?: __DIR__ . '/app/Resources/templates',
    'images_dir' => getenv('DYNA_IMAGES_DIR') ?: __DIR__ . '/app/Resources/images',
    'output_dir' => getenv('DYNA_OUTPUT_DIR') ?: __DIR__,

    //Default Template
    'default_template' => getenv('DYNA_DEFAULT_TEMPLATE') ?: 'cover_basic.json'
];

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

You need to replace the following strings with the corresponding tokens:

  • APP_CONSUMER_KEY
  • APP_CONSUMER_SECRET
  • USER_ACCESS_TOKEN
  • USER_ACCESS_TOKEN_SECRET
  • GITHUB_API_BEARER_TOKEN

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.

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