Skip to content

Instantly share code, notes, and snippets.

@stachibana
Created October 14, 2017 05:33
Show Gist options
  • Save stachibana/adfa9c455008272f36619a99ea2a0ee3 to your computer and use it in GitHub Desktop.
Save stachibana/adfa9c455008272f36619a99ea2a0ee3 to your computer and use it in GitHub Desktop.
$response = $bot->getMessageContent($event->getMessageId());
$rawBody = $response->getRawBody();
.
.
.
function uploadImageToCloudinaryThenGetResult($rawBody) {
\Cloudinary::config(array(
"cloud_name" => getenv('CLOUDINARY_NAME'),
"api_key" => getenv('CLOUDINARY_KEY'),
"api_secret" => getenv('CLOUDINARY_SECRET')
));
$im = imagecreatefromstring($rawBody);
$resultString = "";
if ($im !== false) {
$filename = uniqid();
$directory_path = "tmp";
if(!file_exists($directory_path)) {
if(mkdir($directory_path, 0777, true)) {
chmod($directory_path, 0777);
}
}
imagejpeg($im, $directory_path. "/" . $filename . ".jpg", 75);
} else {
$resultString = "upload failed";
}
$path = dirname(__FILE__) . '/' . $directory_path. "/" . $filename . ".jpg";
$result = \Cloudinary\Uploader::upload($path);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment