Skip to content

Commit 3bfbfb7

Browse files
committed
wip
1 parent 2d4637c commit 3bfbfb7

File tree

7 files changed

+193
-4
lines changed

7 files changed

+193
-4
lines changed

View/Components/AdaptiveImage.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Workbench\App\View\Components;
4+
5+
use Closure;
6+
use Illuminate\Contracts\View\View;
7+
use Illuminate\View\Component;
8+
9+
class AdaptiveImage extends Component
10+
{
11+
/**
12+
* Create a new component instance.
13+
*/
14+
public function __construct()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Get the view / contents that represent the component.
21+
*/
22+
public function render(): View|Closure|string
23+
{
24+
return view('components.adaptive-image');
25+
}
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
WIP
3+
</div>

src/LaravelImageTransformUrlServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Spatie\LaravelPackageTools\Package;
66
use Spatie\LaravelPackageTools\PackageServiceProvider;
7+
use Workbench\App\View\Components\AdaptiveImage;
78

89
class LaravelImageTransformUrlServiceProvider extends PackageServiceProvider
910
{
@@ -17,6 +18,7 @@ public function configurePackage(Package $package): void
1718
$package
1819
->name('laravel-image-transform-url')
1920
->hasConfigFile()
20-
->hasRoute('image');
21+
->hasRoute('image')
22+
->hasViewComponent('adaptive-image', AdaptiveImage::class);
2123
}
2224
}

testbench.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ workbench:
1717
web: true
1818
api: true
1919
commands: true
20-
components: false
20+
components: true
2121
factories: true
22-
views: false
22+
views: true
23+
config: true
2324
build:
2425
- asset-publish
2526
- create-sqlite-db
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Source Directories
7+
|--------------------------------------------------------------------------
8+
|
9+
| Here you may configure the directories from which the image transformer
10+
| is allowed to serve images. For security reasons, it is recommended
11+
| to only allow directories which are already publicly accessible.
12+
|
13+
| Important: The public storage directory should be addressed directly via
14+
| storage('app/public') instead of the public_path('storage') link.
15+
|
16+
*/
17+
18+
'source_directories' => [
19+
'images' => public_path('test-data'),
20+
'storage' => storage_path('app/public/images'),
21+
],
22+
23+
/*
24+
|--------------------------------------------------------------------------
25+
| Default Source Directory
26+
|--------------------------------------------------------------------------
27+
|
28+
| Below you may configure the default source directory which is used when
29+
| no specific path prefix is provided in the URL. This should be one of
30+
| the keys from the source_directories array.
31+
|
32+
*/
33+
34+
'default_source_directory' => env('IMAGE_TRANSFORM_DEFAULT_SOURCE_DIRECTORY', 'images'),
35+
36+
/*
37+
|--------------------------------------------------------------------------
38+
| Route Prefix
39+
|--------------------------------------------------------------------------
40+
|
41+
| Here you may configure the route prefix of the image transformer.
42+
|
43+
*/
44+
45+
'route_prefix' => env('IMAGE_TRANSFORM_ROUTE_PREFIX', 'image-transform'),
46+
47+
/*
48+
|--------------------------------------------------------------------------
49+
| Enabled Options
50+
|--------------------------------------------------------------------------
51+
|
52+
| Here you may configure the options which are enabled for the image
53+
| transformer.
54+
|
55+
*/
56+
57+
'enabled_options' => env('IMAGE_TRANSFORM_ENABLED_OPTIONS', [
58+
'width',
59+
'height',
60+
'format',
61+
'quality',
62+
'flip',
63+
'contrast',
64+
'version',
65+
'background',
66+
// 'blur'
67+
]),
68+
69+
/*
70+
|--------------------------------------------------------------------------
71+
| Image Cache
72+
|--------------------------------------------------------------------------
73+
|
74+
| Here you may configure the image cache settings. The cache is used to
75+
| store the transformed images for a certain amount of time. This is
76+
| useful to prevent reprocessing the same image multiple times.
77+
| The cache is stored in the configured cache disk.
78+
|
79+
*/
80+
81+
'cache' => [
82+
'enabled' => env('IMAGE_TRANSFORM_CACHE_ENABLED', true),
83+
'lifetime' => env('IMAGE_TRANSFORM_CACHE_LIFETIME', 60 * 24 * 7), // 7 days
84+
'disk' => env('IMAGE_TRANSFORM_CACHE_DISK', 'local'),
85+
],
86+
87+
/*
88+
|--------------------------------------------------------------------------
89+
| Rate Limit
90+
|--------------------------------------------------------------------------
91+
|
92+
| Below you may configure the rate limit which is applied for each image
93+
| new transformation by the path and IP address. It is recommended to
94+
| set this to a low value, e.g. 2 requests per minute, to prevent
95+
| abuse.
96+
*/
97+
98+
'rate_limit' => [
99+
'enabled' => env('IMAGE_TRANSFORM_RATE_LIMIT_ENABLED', true),
100+
'disabled_for_environments' => [
101+
'local',
102+
'testing',
103+
],
104+
'max_attempts' => env('IMAGE_TRANSFORM_RATE_LIMIT_MAX_REQUESTS', 2),
105+
'decay_seconds' => env('IMAGE_TRANSFORM_RATE_LIMIT_DECAY_SECONDS', 60),
106+
],
107+
108+
/*
109+
|--------------------------------------------------------------------------
110+
| Response Headers
111+
|--------------------------------------------------------------------------
112+
|
113+
| Below you may configure the response headers which are added to the
114+
| response. This is especially useful for controlling caching behavior
115+
| of CDNs.
116+
|
117+
*/
118+
119+
'headers' => [
120+
'Cache-Control' => env('IMAGE_TRANSFORM_HEADER_CACHE_CONTROL', 'immutable, public, max-age=2592000, s-maxage=2592000'),
121+
],
122+
];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
8+
<title>Image-Transform-URL Playground</title>
9+
10+
<!-- Fonts -->
11+
<link rel="preconnect" href="https://fonts.bunny.net">
12+
<link href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600" rel="stylesheet" />
13+
14+
<!-- Tailwind CSS -->
15+
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
16+
17+
</head>
18+
19+
<body
20+
class="bg-[#FDFDFC] dark:bg-[#0a0a0a] text-[#1b1b18] flex p-6 lg:p-8 items-center lg:justify-center min-h-screen flex-col">
21+
<h1 class="text-white">Playground</h1>
22+
<img
23+
src="test-data/cat.png"
24+
srcset="
25+
image-transform/width=200/cat.png 200w,
26+
image-transform/width=400/cat.png 400w,
27+
image-transform/width=800/cat.png 800w,
28+
image-transform/width=1200/cat.png 1200w,
29+
image-transform/width=1920/cat.png 1920w
30+
"
31+
alt="Cat Image"
32+
/>
33+
</body>
34+
35+
</html>

workbench/routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
use Illuminate\Support\Facades\Route;
44

55
Route::get('/', function () {
6-
return view('welcome');
6+
return view('index');
77
});

0 commit comments

Comments
 (0)