mirror of
https://github.com/friendica/friendica
synced 2024-12-22 23:20:16 +00:00
Merge pull request #14592 from annando/fix-14591
Fix PR 14591 - improve blurhash creation
This commit is contained in:
commit
69345432e1
6 changed files with 20 additions and 19 deletions
|
@ -83,7 +83,7 @@ class Avatar
|
||||||
$filename = self::getFilename($contact['url']);
|
$filename = self::getFilename($contact['url']);
|
||||||
$timestamp = time();
|
$timestamp = time();
|
||||||
|
|
||||||
$fields['blurhash'] = $image->getBlurHash();
|
$fields['blurhash'] = $image->getBlurHash($img_str);
|
||||||
|
|
||||||
$fields['photo'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_SMALL, $timestamp);
|
$fields['photo'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_SMALL, $timestamp);
|
||||||
$fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB, $timestamp);
|
$fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB, $timestamp);
|
||||||
|
|
|
@ -2320,7 +2320,7 @@ class Contact
|
||||||
if ($fetchResult->isSuccess() && !empty($img_str)) {
|
if ($fetchResult->isSuccess() && !empty($img_str)) {
|
||||||
$image = new Image($img_str, $fetchResult->getContentType(), $avatar);
|
$image = new Image($img_str, $fetchResult->getContentType(), $avatar);
|
||||||
if ($image->isValid()) {
|
if ($image->isValid()) {
|
||||||
$update_fields['blurhash'] = $image->getBlurHash();
|
$update_fields['blurhash'] = $image->getBlurHash($img_str);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,6 +434,7 @@ class Photo
|
||||||
$data = '';
|
$data = '';
|
||||||
$backend_ref = '';
|
$backend_ref = '';
|
||||||
$storage = '';
|
$storage = '';
|
||||||
|
$img_str = $image->asString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (DBA::isResult($existing_photo)) {
|
if (DBA::isResult($existing_photo)) {
|
||||||
|
@ -442,9 +443,9 @@ class Photo
|
||||||
} else {
|
} else {
|
||||||
$storage = DI::storage();
|
$storage = DI::storage();
|
||||||
}
|
}
|
||||||
$backend_ref = $storage->put($image->asString(), $backend_ref);
|
$backend_ref = $storage->put($img_str, $backend_ref);
|
||||||
} catch (InvalidClassStorageException $storageException) {
|
} catch (InvalidClassStorageException $storageException) {
|
||||||
$data = $image->asString();
|
$data = $img_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = [
|
$fields = [
|
||||||
|
@ -452,7 +453,7 @@ class Photo
|
||||||
'contact-id' => $cid,
|
'contact-id' => $cid,
|
||||||
'guid' => $guid,
|
'guid' => $guid,
|
||||||
'resource-id' => $rid,
|
'resource-id' => $rid,
|
||||||
'hash' => md5($image->asString()),
|
'hash' => md5($img_str),
|
||||||
'created' => $created,
|
'created' => $created,
|
||||||
'edited' => DateTimeFormat::utcNow(),
|
'edited' => DateTimeFormat::utcNow(),
|
||||||
'filename' => basename($filename),
|
'filename' => basename($filename),
|
||||||
|
@ -460,8 +461,8 @@ class Photo
|
||||||
'album' => $album,
|
'album' => $album,
|
||||||
'height' => $image->getHeight(),
|
'height' => $image->getHeight(),
|
||||||
'width' => $image->getWidth(),
|
'width' => $image->getWidth(),
|
||||||
'datasize' => strlen($image->asString()),
|
'datasize' => strlen($img_str),
|
||||||
'blurhash' => $image->getBlurHash(),
|
'blurhash' => $image->getBlurHash($img_str),
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'scale' => $scale,
|
'scale' => $scale,
|
||||||
'photo-type' => $type,
|
'photo-type' => $type,
|
||||||
|
|
|
@ -130,12 +130,12 @@ class Link
|
||||||
|
|
||||||
if (Images::isSupportedMimeType($fields['mimetype'])) {
|
if (Images::isSupportedMimeType($fields['mimetype'])) {
|
||||||
$img_str = $curlResult->getBodyString();
|
$img_str = $curlResult->getBodyString();
|
||||||
$image = new Image($img_str, $fields['mimetype'], $url);
|
$image = new Image($img_str, $fields['mimetype'], $url, false);
|
||||||
if ($image->isValid()) {
|
if ($image->isValid()) {
|
||||||
$fields['mimetype'] = $image->getType();
|
$fields['mimetype'] = $image->getType();
|
||||||
$fields['width'] = $image->getWidth();
|
$fields['width'] = $image->getWidth();
|
||||||
$fields['height'] = $image->getHeight();
|
$fields['height'] = $image->getHeight();
|
||||||
$fields['blurhash'] = $image->getBlurHash();
|
$fields['blurhash'] = $image->getBlurHash($img_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,8 @@ class Image
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private function isAnimatedWebP(string $data) {
|
private function isAnimatedWebP(string $data)
|
||||||
|
{
|
||||||
$header_format = 'A4Riff/I1Filesize/A4Webp/A4Vp/A74Chunk';
|
$header_format = 'A4Riff/I1Filesize/A4Webp/A4Vp/A74Chunk';
|
||||||
$header = @unpack($header_format, $data);
|
$header = @unpack($header_format, $data);
|
||||||
|
|
||||||
|
@ -356,7 +357,6 @@ class Image
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -526,7 +526,7 @@ class Image
|
||||||
$width = $this->getWidth();
|
$width = $this->getWidth();
|
||||||
$height = $this->getHeight();
|
$height = $this->getHeight();
|
||||||
|
|
||||||
if ((!$width)|| (!$height)) {
|
if ((!$width) || (!$height)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,7 +733,7 @@ class Image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream = fopen('php://memory','r+');
|
$stream = fopen('php://memory', 'r+');
|
||||||
|
|
||||||
switch ($this->getImageType()) {
|
switch ($this->getImageType()) {
|
||||||
case IMAGETYPE_PNG:
|
case IMAGETYPE_PNG:
|
||||||
|
@ -768,9 +768,9 @@ class Image
|
||||||
* @param string $img_str
|
* @param string $img_str
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBlurHash(): string
|
public function getBlurHash(string $img_str = ''): string
|
||||||
{
|
{
|
||||||
$image = clone($this);
|
$image = new Image($img_str ?: $this->asString(), $this->getType(), $this->filename, false);
|
||||||
if (empty($image) || !$this->isValid()) {
|
if (empty($image) || !$this->isValid()) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,10 +366,10 @@ class Images
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$image = new Image($img_str, '', $url);
|
$image = new Image($img_str, '', $url, false);
|
||||||
|
|
||||||
if ($image->isValid()) {
|
if ($image->isValid()) {
|
||||||
$data['blurhash'] = $image->getBlurHash();
|
$data['blurhash'] = $image->getBlurHash($img_str);
|
||||||
|
|
||||||
if ($ocr) {
|
if ($ocr) {
|
||||||
$media = ['img_str' => $img_str];
|
$media = ['img_str' => $img_str];
|
||||||
|
@ -454,7 +454,7 @@ class Images
|
||||||
{
|
{
|
||||||
return self::getBBCodeByUrl(
|
return self::getBBCodeByUrl(
|
||||||
DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id,
|
DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id,
|
||||||
DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview. $ext,
|
DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview . $ext,
|
||||||
$description
|
$description
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue