Skip to content

Commit c91f416

Browse files
committed
display original image when thumbnail is missing
1 parent bbfe642 commit c91f416

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

src/controllers/UploadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function proceedSingleUpload($file)
5454

5555
event(new ImageIsUploading($new_file_path));
5656
try {
57-
if (parent::fileIsImage($file) && parent::isImageToThumb($file)) {
57+
if (parent::fileIsImage($file) && !parent::imageShouldNotHaveThumb($file)) {
5858
Image::make($file->getRealPath())
5959
->orientate() //Apply orientation from exif data
6060
->save($new_file_path, 90);

src/traits/LfmHelpers.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ public function objectPresenter($item)
288288

289289
$thumb_path = $this->getThumbPath($item_name);
290290
$file_path = $this->getCurrentPath($item_name);
291-
if (File::exists($thumb_path)) {
292-
$thumb_url = $this->getThumbUrl($item_name) . '?timestamp=' . filemtime($thumb_path);
293-
} elseif ($this->isValidImageType($file_path)) {
291+
if ($this->imageShouldNotHaveThumb($file_path)) {
294292
$thumb_url = $this->getFileUrl($item_name) . '?timestamp=' . filemtime($file_path);
293+
} elseif (File::exists($thumb_path)) {
294+
$thumb_url = $this->getThumbUrl($item_name) . '?timestamp=' . filemtime($thumb_path);
295295
} else {
296-
$thumb_url = null;
296+
$thumb_url = $this->getFileUrl($item_name) . '?timestamp=' . filemtime($file_path);
297297
}
298298
} else {
299299
$extension = strtolower(File::extension($item_name));
@@ -335,28 +335,12 @@ public function fileIsImage($file)
335335
return starts_with($mime_type, 'image');
336336
}
337337

338-
public function isImageToThumb($file)
338+
public function imageShouldNotHaveThumb($file)
339339
{
340340
$mine_type = $this->getFileType($file);
341341
$noThumbType = ['image/gif', 'image/svg+xml'];
342342

343-
if (in_array($mine_type, $noThumbType)) {
344-
return false;
345-
}
346-
347-
return true;
348-
}
349-
350-
public function isValidImageType($file)
351-
{
352-
$mine_type = $this->getFileType($file);
353-
$valid_image_mimetypes = config('lfm.valid_image_mimetypes');
354-
355-
if (in_array($mine_type, $valid_image_mimetypes)) {
356-
return true;
357-
}
358-
359-
return false;
343+
return in_array($mine_type, $noThumbType);
360344
}
361345

362346
public function getFileType($file)

0 commit comments

Comments
 (0)