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.

40 lines
1.1 KiB

<?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();
}