Image handling reworked, new image formats added (#13900)
* Image handling reworked, new image formats added * Updated messages.po * The dot is now part of the file extension * Added WebP in install documentation * Handle unhandled mime types * Fixed animated picture detected
This commit is contained in:
+10
-14
@@ -363,6 +363,7 @@ class Photo
|
||||
$photo['backend-class'] = SystemResource::NAME;
|
||||
$photo['backend-ref'] = $filename;
|
||||
$photo['type'] = $mimetype;
|
||||
$photo['filename'] = basename($filename);
|
||||
$photo['cacheable'] = false;
|
||||
|
||||
return $photo;
|
||||
@@ -394,6 +395,7 @@ class Photo
|
||||
$photo['backend-class'] = ExternalResource::NAME;
|
||||
$photo['backend-ref'] = json_encode(['url' => $url, 'uid' => $uid]);
|
||||
$photo['type'] = $mimetype;
|
||||
$photo['filename'] = basename(parse_url($url, PHP_URL_PATH));
|
||||
$photo['cacheable'] = true;
|
||||
$photo['blurhash'] = $blurhash;
|
||||
$photo['width'] = $width;
|
||||
@@ -608,9 +610,7 @@ class Photo
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = Images::getMimeTypeByData($img_str, $image_url, $type);
|
||||
|
||||
$image = new Image($img_str, $type);
|
||||
$image = new Image($img_str, $type, $image_url);
|
||||
if ($image->isValid()) {
|
||||
$image->scaleToSquare(300);
|
||||
|
||||
@@ -619,9 +619,9 @@ class Photo
|
||||
|
||||
if ($maximagesize && ($filesize > $maximagesize)) {
|
||||
Logger::info('Avatar exceeds image limit', ['uid' => $uid, 'cid' => $cid, 'maximagesize' => $maximagesize, 'size' => $filesize, 'type' => $image->getType()]);
|
||||
if ($image->getType() == 'image/gif') {
|
||||
if ($image->getImageType() == IMAGETYPE_GIF) {
|
||||
$image->toStatic();
|
||||
$image = new Image($image->asString(), 'image/png');
|
||||
$image = new Image($image->asString(), image_type_to_mime_type(IMAGETYPE_PNG));
|
||||
|
||||
$filesize = strlen($image->asString());
|
||||
Logger::info('Converted gif to a static png', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $image->getType()]);
|
||||
@@ -662,9 +662,9 @@ class Photo
|
||||
|
||||
$suffix = '?ts=' . time();
|
||||
|
||||
$image_url = DI::baseUrl() . '/photo/' . $resource_id . '-4.' . $image->getExt() . $suffix;
|
||||
$thumb = DI::baseUrl() . '/photo/' . $resource_id . '-5.' . $image->getExt() . $suffix;
|
||||
$micro = DI::baseUrl() . '/photo/' . $resource_id . '-6.' . $image->getExt() . $suffix;
|
||||
$image_url = DI::baseUrl() . '/photo/' . $resource_id . '-4' . $image->getExt() . $suffix;
|
||||
$thumb = DI::baseUrl() . '/photo/' . $resource_id . '-5' . $image->getExt() . $suffix;
|
||||
$micro = DI::baseUrl() . '/photo/' . $resource_id . '-6' . $image->getExt() . $suffix;
|
||||
} else {
|
||||
$photo_failure = true;
|
||||
}
|
||||
@@ -1060,9 +1060,7 @@ class Photo
|
||||
return [];
|
||||
}
|
||||
|
||||
$type = Images::getMimeTypeByData($img_str, $image_url, $type);
|
||||
|
||||
$image = new Image($img_str, $type);
|
||||
$image = new Image($img_str, $type, $image_url);
|
||||
|
||||
$image = self::fitImageSize($image);
|
||||
if (empty($image)) {
|
||||
@@ -1132,12 +1130,10 @@ class Photo
|
||||
return [];
|
||||
}
|
||||
|
||||
$filetype = Images::getMimeTypeBySource($src, $filename, $filetype);
|
||||
|
||||
Logger::info('File upload', ['src' => $src, 'filename' => $filename, 'size' => $filesize, 'type' => $filetype]);
|
||||
|
||||
$imagedata = @file_get_contents($src);
|
||||
$image = new Image($imagedata, $filetype);
|
||||
$image = new Image($imagedata, $filetype, $filename);
|
||||
if (!$image->isValid()) {
|
||||
Logger::notice('Image is unvalid', ['files' => $files]);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user