mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Fixed #14460 - added support for avif
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
3d306aacc5
commit
3b66912742
|
@ -34,8 +34,8 @@ class ImageUploadRequest extends Request
|
||||||
{
|
{
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'image' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp',
|
'image' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,avif',
|
||||||
'avatar' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp',
|
'avatar' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,avif',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +103,13 @@ class ImageUploadRequest extends Request
|
||||||
\Log::info('File name will be: '.$file_name);
|
\Log::info('File name will be: '.$file_name);
|
||||||
\Log::debug('File extension is: '.$ext);
|
\Log::debug('File extension is: '.$ext);
|
||||||
|
|
||||||
if ($image->getMimeType() == 'image/webp') {
|
if (($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) {
|
||||||
// If the file is a webp, we need to just move it since webp support
|
// If the file is a webp, we need to just move it since webp support
|
||||||
// needs to be compiled into gd for resizing to be available
|
// needs to be compiled into gd for resizing to be available
|
||||||
|
|
||||||
\Log::debug('This is a webp, just move it');
|
|
||||||
Storage::disk('public')->put($path.'/'.$file_name, file_get_contents($image));
|
Storage::disk('public')->put($path.'/'.$file_name, file_get_contents($image));
|
||||||
|
|
||||||
} elseif($image->getMimeType() == 'image/svg+xml') {
|
} elseif($image->getMimeType() == 'image/svg+xml') {
|
||||||
// If the file is an SVG, we need to clean it and NOT encode it
|
// If the file is an SVG, we need to clean it and NOT encode it
|
||||||
\Log::debug('This is an SVG');
|
|
||||||
$sanitizer = new Sanitizer();
|
$sanitizer = new Sanitizer();
|
||||||
$dirtySVG = file_get_contents($image->getRealPath());
|
$dirtySVG = file_get_contents($image->getRealPath());
|
||||||
$cleanSVG = $sanitizer->sanitize($dirtySVG);
|
$cleanSVG = $sanitizer->sanitize($dirtySVG);
|
||||||
|
@ -123,9 +121,6 @@ class ImageUploadRequest extends Request
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
\Log::debug('Not an SVG or webp - resize');
|
|
||||||
\Log::debug('Trying to upload to: '.$path.'/'.$file_name);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$upload = Image::make($image->getRealPath())->setFileInfoFromPath($image->getRealPath())->resize(null, $w, function ($constraint) {
|
$upload = Image::make($image->getRealPath())->setFileInfoFromPath($image->getRealPath())->resize(null, $w, function ($constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
|
@ -147,10 +142,8 @@ class ImageUploadRequest extends Request
|
||||||
|
|
||||||
// Remove Current image if exists
|
// Remove Current image if exists
|
||||||
if (($item->{$form_fieldname}!='') && (Storage::disk('public')->exists($path.'/'.$item->{$db_fieldname}))) {
|
if (($item->{$form_fieldname}!='') && (Storage::disk('public')->exists($path.'/'.$item->{$db_fieldname}))) {
|
||||||
\Log::debug('A file already exists that we are replacing - we should delete the old one.');
|
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete($path.'/'.$item->{$form_fieldname});
|
Storage::disk('public')->delete($path.'/'.$item->{$form_fieldname});
|
||||||
\Log::debug('Old file '.$path.'/'.$file_name.' has been deleted.');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug('Could not delete old file. '.$path.'/'.$file_name.' does not exist?');
|
\Log::debug('Could not delete old file. '.$path.'/'.$file_name.' does not exist?');
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
<label class="btn btn-default" aria-hidden="true">
|
<label class="btn btn-default" aria-hidden="true">
|
||||||
{{ trans('button.select_file') }}
|
{{ trans('button.select_file') }}
|
||||||
<input type="file" name="{{ (isset($fieldname) ? $fieldname : 'image') }}" class="js-uploadFile" id="uploadFile" data-maxsize="{{ Helper::file_upload_max_size() }}" accept="image/gif,image/jpeg,image/webp,image/png,image/svg,image/svg+xml" style="display:none; max-width: 90%" aria-label="{{ (isset($fieldname) ? $fieldname : 'image') }}" aria-hidden="true">
|
<input type="file" name="{{ (isset($fieldname) ? $fieldname : 'image') }}" class="js-uploadFile" id="uploadFile" data-maxsize="{{ Helper::file_upload_max_size() }}" accept="image/gif,image/jpeg,image/webp,image/png,image/svg,image/svg+xml,image/avif" style="display:none; max-width: 90%" aria-label="{{ (isset($fieldname) ? $fieldname : 'image') }}" aria-hidden="true">
|
||||||
</label>
|
</label>
|
||||||
<span class='label label-default' id="uploadFile-info"></span>
|
<span class='label label-default' id="uploadFile-info"></span>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue