Skip to content

Commit ccdb2f3

Browse files
authored
Merge pull request #9 from codepane/dev
Feature: Add getFileName method
2 parents 23b9979 + a0cfecf commit ccdb2f3

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ public function get()
4949
}
5050
```
5151

52+
### Get Image Name
53+
```
54+
use ImageHandler;
55+
56+
public function get()
57+
{
58+
// pass dimension as the second argument to get a specific dimension of the file name
59+
ImageHandler::getFileName('original_file_name', 'sm');
60+
}
61+
```
62+
5263
### Delete Image
5364
```
5465
use ImageHandler;

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"name": "codepane/laravel-image-handler",
33
"description": "Optimize and store images in multiple sizes easily.",
44
"type": "library",
5-
"version": "0.4",
5+
"version": "0.5",
6+
"keywords": [
7+
"image",
8+
"laravel",
9+
"image-handler"
10+
],
611
"require": {
712
"intervention/image": "^2.7"
813
},
@@ -28,5 +33,6 @@
2833
"name": "Sanjay Prajapati",
2934
"email": "sanjay14prajapati1998@gmail.com"
3035
}
31-
]
36+
],
37+
"prefer-stable": true
3238
}

src/ImageConfiguration.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,14 @@ public function makeFileName(string $imageName, int $time, string $dimension = n
9797
}
9898

9999
/**
100-
* It takes a file name, splits it into two parts, and then returns the file name with the
101-
* dimension added to it
100+
* It takes a file name, splits it into two parts, and then returns the file name with the dimension added to it
102101
*
103102
* @param string fileName The file name of the image.
104103
* @param string dimension The dimension of the image.
105104
*
106105
* @return string The file name with the dimension.
107106
*/
108-
public function getFileName(string $fileName, string $dimension)
107+
public function getImgName(string $fileName, string $dimension)
109108
{
110109
/* Getting the file extension of the file name. */
111110
$fileExt = $this->getFormat();

src/ImageHandler.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,28 @@ public function optimize(string $image, array $dimensions, string $format) : str
113113
*/
114114
public function get(string $fileName, string $dimension = 'orig')
115115
{
116-
$fileName = $this->getFileName($fileName, $dimension);
116+
if($dimension != 'orig')
117+
$fileName = $this->getImgName($fileName, $dimension);
117118

118119
return Storage::disk($this->getStorageDisk())->get($fileName);
119120
}
120121

122+
/**
123+
* It returns the file name of the image
124+
*
125+
* @param string fileName The name of the file you want to get.
126+
* @param string dimension The dimension of the image you want to get.
127+
*
128+
* @return The file name of the image.
129+
*/
130+
public function getFileName(string $fileName, string $dimension = 'orig')
131+
{
132+
if($dimension != 'orig')
133+
$fileName = $this->getImgName($fileName, $dimension);
134+
135+
return $fileName;
136+
}
137+
121138

122139
/**
123140
* It deletes the original file and all the resized versions of it
@@ -135,7 +152,7 @@ public function delete(string $fileName): void
135152
$this->removeFile($storageDisk, $fileName);
136153

137154
foreach($dimensions as $dimension => $val) {
138-
$fileName = $this->getFileName($fileName, $dimension);
155+
$fileName = $this->getImgName($fileName, $dimension);
139156

140157
$this->removeFile($storageDisk, $fileName);
141158
}

0 commit comments

Comments
 (0)