Please find, below, some custom code that you guys helped provide a while back. Given the path to an image, this processes the image so it can be used as a post cover. As of this beta, this code is now breaking.
Specifically, this code is throwing an error:
I suspect you've made a breaking change. Could you please advise?
Specifically, this code is throwing an error:
// Read the external image file
$connector = EB::connector();
I suspect you've made a breaking change. Could you please advise?
public static function downloadImage(string $url, $post): ?stdClass
{
$config = EB::config();
if (!$config) {
return null;
}
// Store the image on a temporary location
$temporaryPath = JPATH_ROOT . '/tmp/' . md5($url);
// Read the external image file
$connector = EB::connector();
$connector->addUrl($url);
$connector->execute();
$contents = $connector->getResult($url);
// Save the image to a temporary location
JFile::write($temporaryPath, $contents);
// Prepare the image data
$file = getimagesize($temporaryPath);
$file['name'] = basename($url);
$file['tmp_name'] = $temporaryPath;
$file['type'] = $file['mime'];
$media = EB::mediamanager();
$uri = 'user:' . $post->created_by;
$adapter = $media->getAdapter($uri);
$result = $adapter->upload($file);
// Delete the temporary file
JFile::delete($temporaryPath);
if (!isset($result->type)) {
return null;
}
$path = $config->get('main_image_path');
$path = rtrim($path, '/');
$relative = $path . '/' . $post->created_by;
$relativeImagePath = $relative . '/' . $file['name'];
$result->html = '<img src="' . $relativeImagePath . '" />';
return $result;
}