Skip to content

Commit

Permalink
[fix]: Fix outputFilePath with basePath; config publishes
Browse files Browse the repository at this point in the history
  • Loading branch information
guizoxxv committed Aug 31, 2020
1 parent 47866b3 commit 0ea2fd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The default behavior is to create the resized image versions in the same path as
$multiSizeImage->processImage($filePath, $outputPath, $basePath);
```

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

**2.3. Resizing**

Expand Down
16 changes: 10 additions & 6 deletions src/MultiSizeImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,18 @@ private function resizeImage(
} else {
$fileName = $fileName . ".{$img->extension}";
}

if ($outputPath) {
// Get image dir relative to basePath
$fileDir = ltrim($img->dirname, $basePath);
$fileDir = $fileDir ? $fileDir . '/' : '';
if ($basePath) {
// Get image dir relative to basePath
$fileDir = ltrim($img->dirname, $basePath);

// Set output file path based on specified path
$outputFilePath = "{$outputPath}/{$fileDir}{$fileName}";
// Set output file path based on specified path and base path
$outputFilePath = "{$outputPath}/{$fileDir}/{$fileName}";
} else {
// Set output file path based on specified path
$outputFilePath = "{$outputPath}/{$fileName}";
}

// Create folder if it does not already exists
$this->createFolderIfNotExists(pathinfo($outputFilePath, PATHINFO_DIRNAME));
Expand Down
4 changes: 3 additions & 1 deletion src/MultiSizeImageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class MultiSizeImageServiceProvider extends ServiceProvider {
*/
public function boot()
{
//
$this->publishes([
__DIR__ . '/../config/multiSizeImage.php' => config_path('multiSizeImage.php'),
]);
}

/**
Expand Down

0 comments on commit 0ea2fd1

Please sign in to comment.