Skip to content

Commit 0ea2fd1

Browse files
committed
[fix]: Fix outputFilePath with basePath; config publishes
1 parent 47866b3 commit 0ea2fd1

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The default behavior is to create the resized image versions in the same path as
6464
$multiSizeImage->processImage($filePath, $outputPath, $basePath);
6565
```
6666

67-
The `basePath` optional parameter can be used to keep the original file path as of the basePath.
67+
The `basePath` optional parameter can be used to keep the original file path as of this path.
6868

6969
**2.3. Resizing**
7070

src/MultiSizeImage.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ private function resizeImage(
145145
} else {
146146
$fileName = $fileName . ".{$img->extension}";
147147
}
148-
148+
149149
if ($outputPath) {
150-
// Get image dir relative to basePath
151-
$fileDir = ltrim($img->dirname, $basePath);
152-
$fileDir = $fileDir ? $fileDir . '/' : '';
150+
if ($basePath) {
151+
// Get image dir relative to basePath
152+
$fileDir = ltrim($img->dirname, $basePath);
153153

154-
// Set output file path based on specified path
155-
$outputFilePath = "{$outputPath}/{$fileDir}{$fileName}";
154+
// Set output file path based on specified path and base path
155+
$outputFilePath = "{$outputPath}/{$fileDir}/{$fileName}";
156+
} else {
157+
// Set output file path based on specified path
158+
$outputFilePath = "{$outputPath}/{$fileName}";
159+
}
156160

157161
// Create folder if it does not already exists
158162
$this->createFolderIfNotExists(pathinfo($outputFilePath, PATHINFO_DIRNAME));

src/MultiSizeImageServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class MultiSizeImageServiceProvider extends ServiceProvider {
1313
*/
1414
public function boot()
1515
{
16-
//
16+
$this->publishes([
17+
__DIR__ . '/../config/multiSizeImage.php' => config_path('multiSizeImage.php'),
18+
]);
1719
}
1820

1921
/**

0 commit comments

Comments
 (0)