Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 9, 2020
2 parents 67d4968 + a2cc5ef commit 7d6b634
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/ResponsiveImages/ResponsiveImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/UrlGenerator/S3UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
}
12 changes: 12 additions & 0 deletions tests/Feature/ResponsiveImages/ResponsiveImageGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
8 changes: 8 additions & 0 deletions tests/Support/TestModels/TestModelWithResponsiveImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\MediaLibrary\Tests\Support\TestModels;

use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\Models\Media;

class TestModelWithResponsiveImages extends TestModel
Expand All @@ -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();
}
}

0 comments on commit 7d6b634

Please sign in to comment.