You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

<?php
use Abraham\TwitterOAuth\TwitterOAuth;
use Abraham\TwitterOAuth\TwitterOAuthException;
use Shikiryu\WebGobbler\Assembler\Superpose;
use Shikiryu\WebGobbler\Config;
use Shikiryu\WebGobbler\Pool;
include 'vendor/autoload.php';
$twitter_config = require 'twitter-config.php';
try {
// generate picture
$config = new Config('./config.json');
$pool = new Pool($config);
$upload_image_name = uniqid('superpose_', true);
$image = new Superpose($pool, $config);
$image->saveTo(sprintf('./render/%s.jpg', $upload_image_name));
// send picture to twitter
$connection = new TwitterOAuth(
$twitter_config['api_key'],
$twitter_config['api_secret'],
$twitter_config['access_token'],
$twitter_config['access_secret']
);
$connection->setTimeouts(5, 60000);
$collage = $connection->upload('media/upload', ['media' => realpath(sprintf('./render/%s.jpg', $upload_image_name))]);
$parameters = [
'status' => 'Nouveau collage',
'media_ids' => $collage->media_id_string,
];
$result = $connection->post('statuses/update', $parameters);
} catch (TwitterOAuthException | Exception $exception) {
echo $exception->getMessage();
}