1111
1212class ImageTransformUrl
1313{
14+ /**
15+ * Generate a regular URL for the image transformation.
16+ *
17+ * @param string $path The path to the image.
18+ * @param array|string $options The transformation options.
19+ * @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
20+ * @return string The generated URL.
21+ */
22+ public function make (string $ path , array |string $ options = [], ?string $ pathPrefix = null ): string
23+ {
24+ $ options = $ this ->optionsToString ($ options );
25+
26+ if (empty ($ pathPrefix )) {
27+ return URL ::route ('image.transform.default ' , ['options ' => $ options , 'path ' => $ path ]);
28+ }
29+
30+ return URL ::route ('image.transform ' , ['pathPrefix ' => $ pathPrefix , 'options ' => $ options , 'path ' => $ path ]);
31+ }
32+
33+ /**
34+ * Generate a regular URL for the image transformation.
35+ *
36+ * @param string $path The path to the image.
37+ * @param array|string $options The transformation options.
38+ * @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
39+ * @return string The generated URL.
40+ */
41+ public function url (string $ path , array |string $ options = [], ?string $ pathPrefix = null ): string
42+ {
43+ return $ this ->make ($ path , $ options , $ pathPrefix );
44+ }
45+
1446 /**
1547 * Generate a signed URL for the image transformation.
1648 *
1749 * @param string $path The path to the image.
18- * @param array $options The transformation options.
50+ * @param array|string $options The transformation options.
1951 * @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
2052 * @param DateTimeInterface|\DateInterval|int|null $expiration The expiration time for the signed URL.
2153 * @return string The signed URL.
@@ -28,11 +60,7 @@ public function signedUrl(string $path, array|string $options = [], ?string $pat
2860 throw new InvalidConfigurationException ('Signed URLs are not enabled. Please check your configuration. ' );
2961 }
3062
31- if (is_array ($ options )) {
32- $ options = collect ($ options )
33- ->map (fn ($ value , $ key ) => "$ key= $ value " )
34- ->implode (', ' );
35- }
63+ $ options = $ this ->optionsToString ($ options );
3664
3765 if (empty ($ pathPrefix )) {
3866 return URL ::signedRoute (
@@ -52,7 +80,7 @@ public function signedUrl(string $path, array|string $options = [], ?string $pat
5280 }
5381
5482 /**
55- * Create a temporary signed URL for the image transformation.
83+ * Generate a temporary signed URL for the image transformation.
5684 *
5785 * @param string $path The path to the image.
5886 * @param array|string $options The transformation options.
@@ -67,4 +95,18 @@ public function temporarySignedUrl(string $path, array|string $options, DateTime
6795 {
6896 return $ this ->signedUrl ($ path , $ options , $ pathPrefix , $ expiration , $ absolute );
6997 }
98+
99+ /**
100+ * Convert array options to a string format suitable for URL generation.
101+ */
102+ protected function optionsToString (array |string $ options ): string
103+ {
104+ if (is_array ($ options )) {
105+ return collect ($ options )
106+ ->map (fn ($ value , $ key ) => "$ key= $ value " )
107+ ->implode (', ' );
108+ }
109+
110+ return $ options ;
111+ }
70112}
0 commit comments