0

У меня есть код, который возвращает ресурс изображения видом imagepng($this->image).

Мне нужно каким-то образом сделать из изображения путь к изображению, базируясь на этом мануале: https://core.telegram.org/bots/api#sendphoto

В общем, мне нужно обработать ресурс и отправить фото в Телеграм, но я никак не пойму как и что делать с этим ресурсом

1 ответ 1

2

Сохрани изображение в файл передав имя файла вторым параметром в imagepng, и отправь файл через curl по Telegram Bot API:

$tmpfilename = tempnam("/tmp", "img");
imagepng($this->image, $tmpfilename);

$bot_url    = "https://api.telegram.org/bot<bot_id>/";
$url        = $bot_url . "sendPhoto?chat_id=" . $chat_id ;

$post_fields = array(
    'chat_id'   => $chat_id,
    'photo'     => new CURLFile($tmpfilename)
);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type:multipart/form-data"
));
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
$output = curl_exec($ch);

unlink($tmpfilename);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.