$filename = self::getFilename($contact['url']);
$timestamp = time();
- $fields['blurhash'] = $image->getBlurHash();
+ $fields['blurhash'] = $image->getBlurHash($img_str);
$fields['photo'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_SMALL, $timestamp);
$fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB, $timestamp);
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;
}
$data = '';
$backend_ref = '';
$storage = '';
+ $img_str = $image->asString();
try {
if (DBA::isResult($existing_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 = [
'contact-id' => $cid,
'guid' => $guid,
'resource-id' => $rid,
- 'hash' => md5($image->asString()),
+ 'hash' => md5($img_str),
'created' => $created,
'edited' => DateTimeFormat::utcNow(),
'filename' => basename($filename),
'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,
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);
}
}
* @param string $data
* @return boolean
*/
- private function isAnimatedWebP(string $data) {
+ private function isAnimatedWebP(string $data)
+ {
$header_format = 'A4Riff/I1Filesize/A4Webp/A4Vp/A74Chunk';
$header = @unpack($header_format, $data);
} else {
return false;
}
-
}
/**
$width = $this->getWidth();
$height = $this->getHeight();
- if ((!$width)|| (!$height)) {
+ if ((!$width) || (!$height)) {
return false;
}
}
}
- $stream = fopen('php://memory','r+');
+ $stream = fopen('php://memory', 'r+');
switch ($this->getImageType()) {
case IMAGETYPE_PNG:
* @param string $img_str
* @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()) {
return '';
}
return [];
}
- $image = new Image($img_str, '', $url);
+ $image = new Image($img_str, '', $url, false);
if ($image->isValid()) {
- $data['blurhash'] = $image->getBlurHash();
-
+ $data['blurhash'] = $image->getBlurHash($img_str);
+
if ($ocr) {
$media = ['img_str' => $img_str];
Hook::callAll('ocr-detection', $media);
{
return self::getBBCodeByUrl(
DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id,
- DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview. $ext,
+ DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview . $ext,
$description
);
}