Skip to content

Commit

Permalink
display original image when thumbnail is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Apr 28, 2017
1 parent bbfe642 commit c91f416
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function proceedSingleUpload($file)

event(new ImageIsUploading($new_file_path));
try {
if (parent::fileIsImage($file) && parent::isImageToThumb($file)) {
if (parent::fileIsImage($file) && !parent::imageShouldNotHaveThumb($file)) {
Image::make($file->getRealPath())
->orientate() //Apply orientation from exif data
->save($new_file_path, 90);
Expand Down
28 changes: 6 additions & 22 deletions src/traits/LfmHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ public function objectPresenter($item)

$thumb_path = $this->getThumbPath($item_name);
$file_path = $this->getCurrentPath($item_name);
if (File::exists($thumb_path)) {
$thumb_url = $this->getThumbUrl($item_name) . '?timestamp=' . filemtime($thumb_path);
} elseif ($this->isValidImageType($file_path)) {
if ($this->imageShouldNotHaveThumb($file_path)) {
$thumb_url = $this->getFileUrl($item_name) . '?timestamp=' . filemtime($file_path);
} elseif (File::exists($thumb_path)) {
$thumb_url = $this->getThumbUrl($item_name) . '?timestamp=' . filemtime($thumb_path);
} else {
$thumb_url = null;
$thumb_url = $this->getFileUrl($item_name) . '?timestamp=' . filemtime($file_path);
}
} else {
$extension = strtolower(File::extension($item_name));
Expand Down Expand Up @@ -335,28 +335,12 @@ public function fileIsImage($file)
return starts_with($mime_type, 'image');
}

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

if (in_array($mine_type, $noThumbType)) {
return false;
}

return true;
}

public function isValidImageType($file)
{
$mine_type = $this->getFileType($file);
$valid_image_mimetypes = config('lfm.valid_image_mimetypes');

if (in_array($mine_type, $valid_image_mimetypes)) {
return true;
}

return false;
return in_array($mine_type, $noThumbType);
}

public function getFileType($file)
Expand Down

0 comments on commit c91f416

Please sign in to comment.