Skip to content

Commit

Permalink
Merge pull request #70 from erhanask/2.6
Browse files Browse the repository at this point in the history
Edited thumbnail of deleted images and showing default image instead of 404
  • Loading branch information
RyanThompson authored Jun 7, 2023
2 parents 8692298 + 5a7c957 commit 47af0c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Binary file added resources/img/types/no-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/File/FilePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,19 @@ public function size($unit = null, $decimals = 2)
public function preview($width = 64, $height = 64)
{
if ($this->type() == 'image' && $this->object->canPreview()) {
return $this->object->image()
$output = $this->object->image()
->width($width . 'px')
->resize(
$width,
$height,
function (Constraint $constraint) {
$constraint->aspectRatio();
}
)
->output();
);
// Showing user a default image when error returns.
if (!str_contains($output->url(),'Image source not readable')) {
return $output->output();
}
}

$type = $this->dispatch(new GetType($this->object)) ?: 'document';
Expand Down
17 changes: 16 additions & 1 deletion src/Http/Controller/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,22 @@ public function read(
return $generator->generate($image->version(false), Request::get('quality', config('streams::images.quality', 80)));
}

return $reader->read($file);
// if can not read the file source, redirecting to a default image instead of 404 error.
try {

return $reader->read($file);

} catch (\Exception $exception) {

return redirect(
$image
->make('anomaly.module.files::img/types/no-image.png')
->quality(60)
->url()
);

}

}

/**
Expand Down

0 comments on commit 47af0c1

Please sign in to comment.