<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\DI;
use Friendica\Model\Photo;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
+use Friendica\Object\Image;
/**
* Image utilities
/**
* Gets info array from given URL, cached data has priority
*
- * @param string $url URL
+ * @param string $url
* @return array Info
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
/**
* Gets info from URL uncached
*
- * @param string $url URL
+ * @param string $url
* @return array Info array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
}
if (empty($img_str)) {
- $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
+ try {
+ $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
+ } catch (\Exception $exception) {
+ Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]);
+ return [];
+ }
}
if (!$img_str) {
}
if ($data) {
+ $image = new Image($img_str);
+
+ if ($image->isValid()) {
+ $data['blurhash'] = $image->getBlurHash();
+ }
+
$data['size'] = $filesize;
}
- return $data ?? [];
+ return is_array($data) ? $data : [];
}
/**