diff --git a/CHANGELOG.md b/CHANGELOG.md index c977078c3..f924acf57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,18 @@ All notable changes to `laravel-medialibrary` will be documented in this file -## 7.19.2 - 2020-03-09 +## 7.19.3 - 2020-03-09 - fix responsive images extension (#1752) - use native file copy (#1758) +## 7.19.2 - 2020-03-04 + +- revert changes in 7.19.1 + ## 7.19.1 - 2020-03-04 -- Update S3 url generator to use media disk #1755 +- Update S3 url generator to use media disk (#1755) ## 7.19.0 - 2020-03-03 diff --git a/src/ResponsiveImages/ResponsiveImageGenerator.php b/src/ResponsiveImages/ResponsiveImageGenerator.php index 0a1e3e725..771b1e71c 100644 --- a/src/ResponsiveImages/ResponsiveImageGenerator.php +++ b/src/ResponsiveImages/ResponsiveImageGenerator.php @@ -82,7 +82,7 @@ public function generateResponsiveImage( int $targetWidth, BaseTemporaryDirectory $temporaryDirectory ) { - $responsiveImagePath = $this->appendToFileName($media->file_name, "___{$conversionName}_{$targetWidth}"); + $responsiveImagePath = $this->appendToFileName($media->file_name, "___{$conversionName}_{$targetWidth}", $baseImage); $tempDestination = $temporaryDirectory->path($responsiveImagePath); @@ -133,11 +133,11 @@ public function generateTinyJpg(Media $media, string $originalImagePath, string ResponsiveImage::registerTinySvg($media, $base64Svg, $conversionName); } - protected function appendToFileName(string $filePath, string $suffix): string + protected function appendToFileName(string $filePath, string $suffix, string $extensionFilePath = null): string { $baseName = pathinfo($filePath, PATHINFO_FILENAME); - $extension = pathinfo($filePath, PATHINFO_EXTENSION); + $extension = pathinfo($extensionFilePath ?? $filePath, PATHINFO_EXTENSION); return $baseName.$suffix.'.'.$extension; } diff --git a/src/UrlGenerator/S3UrlGenerator.php b/src/UrlGenerator/S3UrlGenerator.php index 46bae7de4..5874c7acb 100644 --- a/src/UrlGenerator/S3UrlGenerator.php +++ b/src/UrlGenerator/S3UrlGenerator.php @@ -35,7 +35,7 @@ public function getUrl(): string $url = $this->versionUrl($url); - return config('medialibrary.'.$this->media->disk.'.domain').'/'.$url; + return config('medialibrary.s3.domain').'/'.$url; } /** @@ -76,6 +76,6 @@ public function getResponsiveImagesDirectoryUrl(): string $url = $root.'/'.$url; } - return config('medialibrary.'.$this->media->disk.'.domain').'/'.$url; + return config('medialibrary.s3.domain').'/'.$url; } } diff --git a/tests/Feature/ResponsiveImages/ResponsiveImageGeneratorTest.php b/tests/Feature/ResponsiveImages/ResponsiveImageGeneratorTest.php index 79f977c66..66b4ec245 100644 --- a/tests/Feature/ResponsiveImages/ResponsiveImageGeneratorTest.php +++ b/tests/Feature/ResponsiveImages/ResponsiveImageGeneratorTest.php @@ -33,6 +33,18 @@ public function its_conversions_can_have_responsive_images() $this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___thumb_50_41.jpg')); } + /** @test */ + public function its_conversions_can_have_responsive_images_and_change_format() + { + $this->testModelWithResponsiveImages + ->addMedia($this->getTestPng()) + ->withResponsiveImages() + ->toMediaCollection(); + + $this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___pngtojpg_700_883.jpg')); + $this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___pngtojpg_585_737.jpg')); + } + /** @test */ public function it_triggers_an_event_when_the_responsive_images_are_generated() { diff --git a/tests/Support/TestModels/TestModelWithResponsiveImages.php b/tests/Support/TestModels/TestModelWithResponsiveImages.php index d92cf1a6f..6491038c3 100644 --- a/tests/Support/TestModels/TestModelWithResponsiveImages.php +++ b/tests/Support/TestModels/TestModelWithResponsiveImages.php @@ -2,6 +2,7 @@ namespace Spatie\MediaLibrary\Tests\Support\TestModels; +use Spatie\Image\Manipulations; use Spatie\MediaLibrary\Models\Media; class TestModelWithResponsiveImages extends TestModel @@ -20,5 +21,12 @@ public function registerMediaConversions(Media $media = null) $this->addMediaConversion('otherImageConversion') ->greyscale(); + + $this->addMediaConversion('pngtojpg') + ->width(700) + ->quality(1) + ->background('blue') + ->format(Manipulations::FORMAT_JPG) + ->withResponsiveImages(); } }