Skip to content

Commit

Permalink
Add thumbnail_in_storage config, to handle thumbnails creation in /st…
Browse files Browse the repository at this point in the history
…orage dir
  • Loading branch information
dvlpp committed Oct 1, 2016
1 parent 7dce24f commit e32b3ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions resources/config/sharp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

"upload_storage_disk" => "local",
"upload_storage_base_path" => "data",
"thumbnail_in_storage" => false,
"thumbnail_relative_path" => "sharp/thumbnails",
"upload_tmp_base_path" => "tmp/sharp",
"file_queue_name" => null,

"user_login_field_name" => "login",

"categories" => []
];
24 changes: 19 additions & 5 deletions src/helpers/sharp_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ function sharp_thumbnail($source, $w, $h, $params = [], $relativeFolder=null, $i
$source = config("sharp.upload_storage_base_path") . "/" . $source;
}

$thumbnailPath = config("sharp.thumbnail_relative_path");

$sizeMin = isset($params["size_min"]) && $params["size_min"];

if ($w == 0) {
Expand All @@ -36,8 +34,20 @@ function sharp_thumbnail($source, $w, $h, $params = [], $relativeFolder=null, $i
$h = null;
}

$thumbName = "$thumbnailPath/$relativeFolder/$w-$h" . ($sizeMin ? "_min" : "") . "/" . basename($source);
$thumbFile = public_path($thumbName);
$thumbName = "$relativeFolder/$w-$h"
. ($sizeMin ? "_min" : "")
. "/" . basename($source);

$thumbnailPath = config("sharp.thumbnail_relative_path");

if(config("sharp.thumbnail_in_storage", false)) {
$thumbFile = storage_path(
"app/public/$thumbnailPath/".config('sharp.upload_storage_base_path')."/$thumbName"
);

} else {
$thumbFile = public_path("$thumbnailPath/$thumbName");
}

if (!file_exists($thumbFile)) {

Expand Down Expand Up @@ -74,7 +84,11 @@ function sharp_thumbnail($source, $w, $h, $params = [], $relativeFolder=null, $i
}
}

return url($thumbName);
if(config("sharp.thumbnail_in_storage", false)) {
return url("storage/$thumbnailPath/".config('sharp.upload_storage_base_path')."/$thumbName");
}

return url("$thumbnailPath/$thumbName");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.26
3.1.27

0 comments on commit e32b3ae

Please sign in to comment.