Add Mastodon

This commit is contained in:
2021-03-03 21:07:23 +01:00
parent de4c345913
commit 4b79173585
4 changed files with 97 additions and 1 deletions

40
mastodon.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
use Shikiryu\WebGobbler\Assembler\Superpose;
use Shikiryu\WebGobbler\Config;
use Shikiryu\WebGobbler\Pool;
include 'vendor/autoload.php';
include 'Mastodon/Mastodon.php';
$mastodon_config = require 'mastodon-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_path = sprintf('./render/%s.jpg', $upload_image_name);
$image->saveTo($image_path);
// send picture to mastodon
$app = new MastodonAPI($mastodon_config['access_token'], $mastodon_config['domain']);
$curl_file = curl_file_create(realpath($image_path));
$body = ['file' => $curl_file];
$response = $app->uploadMedia($body);
$file_id = $response->id;
$statusText = 'Nouveau collage';
$status_data = [
'status' => $statusText,
'visibility' => 'public',
'language' => 'fr',
'media_ids[]' => $file_id,
];
$app->postStatus($status_data);
} catch (Exception $exception) {
echo $exception->getMessage();
}