Fix PR 14591 - improve blurhash creation

This commit is contained in:
Michael 2024-12-09 21:24:28 +00:00
parent 9a8554e40a
commit 17c335238f
6 changed files with 20 additions and 19 deletions

View file

@ -2320,7 +2320,7 @@ class Contact
if ($fetchResult->isSuccess() && !empty($img_str)) {
$image = new Image($img_str, $fetchResult->getContentType(), $avatar);
if ($image->isValid()) {
$update_fields['blurhash'] = $image->getBlurHash();
$update_fields['blurhash'] = $image->getBlurHash($img_str);
} else {
return;
}

View file

@ -434,6 +434,7 @@ class Photo
$data = '';
$backend_ref = '';
$storage = '';
$img_str = $image->asString();
try {
if (DBA::isResult($existing_photo)) {
@ -442,9 +443,9 @@ class Photo
} else {
$storage = DI::storage();
}
$backend_ref = $storage->put($image->asString(), $backend_ref);
$backend_ref = $storage->put($img_str, $backend_ref);
} catch (InvalidClassStorageException $storageException) {
$data = $image->asString();
$data = $img_str;
}
$fields = [
@ -452,7 +453,7 @@ class Photo
'contact-id' => $cid,
'guid' => $guid,
'resource-id' => $rid,
'hash' => md5($image->asString()),
'hash' => md5($img_str),
'created' => $created,
'edited' => DateTimeFormat::utcNow(),
'filename' => basename($filename),
@ -460,8 +461,8 @@ class Photo
'album' => $album,
'height' => $image->getHeight(),
'width' => $image->getWidth(),
'datasize' => strlen($image->asString()),
'blurhash' => $image->getBlurHash(),
'datasize' => strlen($img_str),
'blurhash' => $image->getBlurHash($img_str),
'data' => $data,
'scale' => $scale,
'photo-type' => $type,

View file

@ -130,12 +130,12 @@ class Link
if (Images::isSupportedMimeType($fields['mimetype'])) {
$img_str = $curlResult->getBodyString();
$image = new Image($img_str, $fields['mimetype'], $url);
$image = new Image($img_str, $fields['mimetype'], $url, false);
if ($image->isValid()) {
$fields['mimetype'] = $image->getType();
$fields['width'] = $image->getWidth();
$fields['height'] = $image->getHeight();
$fields['blurhash'] = $image->getBlurHash();
$fields['blurhash'] = $image->getBlurHash($img_str);
}
}