|
111 | 111 | ->and($thumbWasCreatedTwice)->toBeFalse(); |
112 | 112 | }); |
113 | 113 |
|
114 | | -it('allows to define an encoder when creating the thumbnail', function () { |
115 | | - $file = createImage(name: 'my-image.png'); |
116 | | - $upload = createSharpUploadModel($file); |
117 | | - |
118 | | - $thumb = $upload->thumbnail() |
119 | | - ->setQuality(80) |
120 | | - ->when($upload->mime_type == 'image/png', fn ($thumbnail) => $thumbnail->toWebp()) |
121 | | - ->make(150); |
122 | | - |
123 | | - expect($thumb) |
| 114 | +it('allows to define an encoder when creating the thumbnail', function (string $driver) { |
| 115 | + sharp()->config() |
| 116 | + ->configureUploadsThumbnailCreation(imageDriverClass: $driver); |
| 117 | + |
| 118 | + expect( |
| 119 | + createSharpUploadModel(createImage(name: 'my-image.png'))->thumbnail()->setQuality(80) |
| 120 | + ->toWebp()->make(150) |
| 121 | + ) |
124 | 122 | ->toEqual('/storage/thumbnails/data/150-_q-80/my-image.webp') |
125 | | - ->and(Storage::disk('public')->exists('thumbnails/data/150-_q-80/my-image.webp')) |
126 | | - ->toBeTrue(); |
127 | | -}); |
| 123 | + ->and(Storage::disk('public')->exists('thumbnails/data/150-_q-80/my-image.webp'))->toBeTrue(); |
| 124 | + |
| 125 | + expect( |
| 126 | + createSharpUploadModel(createImage(name: 'my-image.png'))->thumbnail()->setQuality(80) |
| 127 | + ->toGif()->make(150) |
| 128 | + ) |
| 129 | + ->toEqual('/storage/thumbnails/data/150-_q-80/my-image.gif') |
| 130 | + ->and(Storage::disk('public')->exists('thumbnails/data/150-_q-80/my-image.gif'))->toBeTrue(); |
| 131 | + |
| 132 | + expect( |
| 133 | + createSharpUploadModel(createImage(name: 'my-image.gif'))->thumbnail()->setQuality(80) |
| 134 | + ->toPng()->make(150) |
| 135 | + ) |
| 136 | + ->toEqual('/storage/thumbnails/data/150-_q-80/my-image.png') |
| 137 | + ->and(Storage::disk('public')->exists('thumbnails/data/150-_q-80/my-image.png'))->toBeTrue(); |
| 138 | + |
| 139 | + expect( |
| 140 | + createSharpUploadModel(createImage(name: 'my-image.gif'))->thumbnail()->setQuality(80) |
| 141 | + ->toJpeg()->make(150) |
| 142 | + ) |
| 143 | + ->toEqual('/storage/thumbnails/data/150-_q-80/my-image.jpeg') |
| 144 | + ->and(Storage::disk('public')->exists('thumbnails/data/150-_q-80/my-image.jpeg'))->toBeTrue(); |
| 145 | + |
| 146 | + if ($driver === \Intervention\Image\Drivers\Imagick\Driver::class) { |
| 147 | + expect( |
| 148 | + createSharpUploadModel(createImage(name: 'my-image.png'))->thumbnail()->setQuality(80) |
| 149 | + ->toAvif()->make(150) |
| 150 | + ) |
| 151 | + ->toEqual('/storage/thumbnails/data/150-_q-80/my-image.avif') |
| 152 | + ->and(Storage::disk('public')->exists('thumbnails/data/150-_q-80/my-image.avif'))->toBeTrue(); |
| 153 | + } |
| 154 | +}) |
| 155 | + ->with([ |
| 156 | + \Intervention\Image\Drivers\Gd\Driver::class, |
| 157 | + \Intervention\Image\Drivers\Imagick\Driver::class, |
| 158 | + ]); |
128 | 159 |
|
129 | 160 | it('allows to create SVG thumbnail by only copying the file', function () { |
130 | 161 | $file = createImage('local', 'test.svg'); |
|
0 commit comments