Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spatie/laravel-medialibrary
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: virtruvio/laravel-medialibrary
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bugfix
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on May 6, 2018

  1. Copy the full SHA
    60d7f52 View commit details

Commits on May 7, 2018

  1. Copy the full SHA
    ae95195 View commit details

Commits on May 10, 2018

  1. Copy the full SHA
    b4cc6f7 View commit details

Commits on May 11, 2018

  1. Copy the full SHA
    2c8cd5c View commit details

Commits on May 16, 2018

  1. Copy the full SHA
    327471d View commit details

Commits on Jun 9, 2018

  1. Copy the full SHA
    f1f3763 View commit details

Commits on Jul 9, 2018

  1. Copy the full SHA
    bd2827b View commit details
  2. Copy the full SHA
    24cd57b View commit details

Commits on Jul 15, 2018

  1. Copy the full SHA
    10efaa4 View commit details
  2. Correct parameter pass

    virtruvio committed Jul 15, 2018
    Copy the full SHA
    27281f7 View commit details
  3. Copy the full SHA
    7469a57 View commit details

Commits on Jul 17, 2018

  1. roll back last 3 commits

    virtruvio committed Jul 17, 2018
    Copy the full SHA
    32626d2 View commit details
  2. Revert "roll back last 3 commits"

    This reverts commit 32626d2.
    virtruvio committed Jul 17, 2018
    Copy the full SHA
    35ac791 View commit details
  3. Revert "correct img() parameter defaults"

    This reverts commit 7469a57.
    virtruvio committed Jul 17, 2018
    Copy the full SHA
    0f3c182 View commit details
  4. Revert "Correct parameter pass"

    This reverts commit 27281f7.
    virtruvio committed Jul 17, 2018
    Copy the full SHA
    4bd0dbc View commit details
  5. Copy the full SHA
    4163298 View commit details
  6. Copy the full SHA
    3ad3db6 View commit details

Commits on Jul 30, 2018

  1. Copy the full SHA
    a0b480b View commit details

Commits on Aug 2, 2018

  1. line break fix

    virtruvio committed Aug 2, 2018
    Copy the full SHA
    5a56612 View commit details

Commits on Aug 12, 2018

  1. Copy the full SHA
    b10293e View commit details

Commits on Aug 13, 2018

  1. Copy the full SHA
    be5abf4 View commit details
  2. Add Auth class

    virtruvio committed Aug 13, 2018
    Copy the full SHA
    4b5a598 View commit details
  3. Typo

    virtruvio committed Aug 13, 2018
    Copy the full SHA
    802f92a View commit details

Commits on Sep 11, 2018

  1. check in console

    virtruvio committed Sep 11, 2018
    Copy the full SHA
    9156f76 View commit details
  2. Copy the full SHA
    64d4daf View commit details
  3. finished merge

    virtruvio committed Sep 11, 2018
    Copy the full SHA
    dbe887b View commit details

Commits on Dec 25, 2018

  1. Copy the full SHA
    883b02f View commit details

Commits on Mar 28, 2019

  1. Copy the full SHA
    b5fb212 View commit details

Commits on Jul 28, 2019

  1. Copy the full SHA
    c5e6299 View commit details
2 changes: 1 addition & 1 deletion src/Commands/CleanCommand.php
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@ protected function deleteResponsiveImagesForDeprecatedConversions(Media $media)
->map(function (Conversion $conversion) {
return $conversion->getName();
})
->push('medialibrary_original');
->push('ml_bri');

$responsiveImagesGeneratedFor = array_keys($media->responsive_images);

13 changes: 6 additions & 7 deletions src/Conversion/Conversion.php
Original file line number Diff line number Diff line change
@@ -239,21 +239,20 @@ public function shouldBeQueued(): bool
}

/*
* Get the extension that the result of this conversion must have.
*/
* Get the extension that the result of this conversion must have.
*/
public function getResultExtension(string $originalFileExtension = ''): string
{
if ($this->shouldKeepOriginalImageFormat()) {
if (in_array($originalFileExtension, ['jpg', 'jpeg', 'pjpg', 'png', 'gif'])) {
return $originalFileExtension;
}
$supportedFormats = ['jpg', 'pjpg', 'png', 'gif'];
if ($this->shouldKeepOriginalImageFormat() && in_array($originalFileExtension, $supportedFormats)) {
return $originalFileExtension;
}

if ($manipulationArgument = $this->manipulations->getManipulationArgument('format')) {
return $manipulationArgument;
}

return $originalFileExtension;
return 'jpg';
}

public function getConversionFile(string $file): string
2 changes: 1 addition & 1 deletion src/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ public function removeFile(Media $media, string $path)
$this->filesystem->disk($media->disk)->delete($path);
}

public function removeResponsiveImages(Media $media, string $conversionName = 'medialibrary_original')
public function removeResponsiveImages(Media $media, string $conversionName = 'ml_bri')
{
$responsiveImagesDirectory = $this->getResponsiveImagesDirectory($media);

21 changes: 17 additions & 4 deletions src/Models/Media.php
Original file line number Diff line number Diff line change
@@ -264,13 +264,24 @@ public function toHtml()
return $this->img();
}

/**
* @param string $viewFile
*
* @return string
*/
public function toEmbed(String $viewFile) {
return $this->img('', [], $viewFile);
}

/**
* @param string|array $conversion
* @param array $extraAttributes
*
* @return string
*/
public function img($conversion = '', array $extraAttributes = []): string
public function img($conversion = '',
array $extraAttributes = [],
$viewFile = 'responsiveImageWithPlaceholder'): string
{
if (! (new Image())->canHandleMime($this->mime_type)) {
return '';
@@ -302,9 +313,11 @@ public function img($conversion = '', array $extraAttributes = []): string
$width = '';

if ($this->hasResponsiveImages($conversion)) {
$viewName = config('medialibrary.responsive_images.use_tiny_placeholders')
? 'responsiveImageWithPlaceholder'
: 'responsiveImage';
// $viewName = config('medialibrary.responsive_images.use_tiny_placeholders')
// ? 'responsiveImageWithPlaceholder'
// : 'responsiveImage';

$viewName = $viewFile;

$width = $this->responsiveImages($conversion)->files->first()->width();
}
19 changes: 13 additions & 6 deletions src/ResponsiveImages/RegisteredResponsiveImages.php
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public function __construct(Media $media, string $conversionName = '')
$this->media = $media;

$this->generatedFor = $conversionName === ''
? 'medialibrary_original'
? 'ml_bri'
: $conversionName;

$this->files = collect($media->responsive_images[$this->generatedFor]['urls'] ?? [])
@@ -44,11 +44,18 @@ public function getUrls(): array

public function getSrcset(): string
{
$filesSrcset = $this->files
->map(function (ResponsiveImage $responsiveImage) {
return "{$responsiveImage->url()} {$responsiveImage->width()}w";
})
->implode(', ');
$filesSrcset = $this->files
->map(function (ResponsiveImage $responsiveImage) {
if ($this->media->hasCustomProperty('custom.art.'.$responsiveImage->width().'.active'))
{
$customUrl = $this->media->getUrl(). $this->media->getCustomProperty('custom.art.'.$responsiveImage->width().'.qS');
$customUrl = str_replace('storage','xstorm', $customUrl);
return "{$customUrl} {$responsiveImage->width()}w";
} else {
return "{$responsiveImage->url()} {$responsiveImage->width()}w";
}
})
->implode(', ');

$shouldAddPlaceholderSvg = config('medialibrary.responsive_images.use_tiny_placeholders')
&& $this->getPlaceholderSvg();
6 changes: 3 additions & 3 deletions src/ResponsiveImages/ResponsiveImageGenerator.php
Original file line number Diff line number Diff line change
@@ -50,12 +50,12 @@ public function generateResponsiveImages(Media $media)
$media = $this->cleanResponsiveImages($media);

foreach ($this->widthCalculator->calculateWidthsFromFile($baseImage) as $width) {
$this->generateResponsiveImage($media, $baseImage, 'medialibrary_original', $width, $temporaryDirectory);
$this->generateResponsiveImage($media, $baseImage, 'ml_bri', $width, $temporaryDirectory);
}

event(new ResponsiveImagesGenerated($media));

$this->generateTinyJpg($media, $baseImage, 'medialibrary_original', $temporaryDirectory);
$this->generateTinyJpg($media, $baseImage, 'ml_bri', $temporaryDirectory);

$temporaryDirectory->delete();
}
@@ -155,7 +155,7 @@ protected function guardAgainstInvalidTinyPlaceHolder(string $tinyPlaceholderPat
}
}

protected function cleanResponsiveImages(Media $media, string $conversionName = 'medialibrary_original') : Media
protected function cleanResponsiveImages(Media $media, string $conversionName = 'ml_bri') : Media
{
$responsiveImages = $media->responsive_images;
$responsiveImages[$conversionName]['urls'] = [];
9 changes: 8 additions & 1 deletion src/UrlGenerator/LocalUrlGenerator.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace Spatie\MediaLibrary\UrlGenerator;

use Auth;
use DateTimeInterface;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\Exceptions\UrlCannotBeDetermined;
@@ -49,8 +50,14 @@ public function getPath(): string

protected function getBaseMediaDirectoryUrl(): string
{
if ($diskUrl = $this->config->get("filesystems.disks.{$this->media->disk}.url")) {
if (Auth::check() || app()->runningInConsole()) {
if ($diskUrl = $this->config->get("filesystems.disks.{$this->media->disk}.url")) {
return str_replace(url('/'), '', $diskUrl);
}
} else {
if ($diskUrl = $this->config->get('filesystems.disks.cloudfront.url')) {
return str_replace(url('/'), '', $diskUrl);
}
}

if (! Str::startsWith($this->getStoragePath(), public_path())) {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

return '<img srcset="/media/2/responsive-images/test___medialibrary_original_340_280.jpg 340w, /media/2/responsive-images/test___medialibrary_original_284_233.jpg 284w, /media/2/responsive-images/test___medialibrary_original_237_195.jpg 237w, data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHg9IjAiCiB5PSIwIiB2aWV3Qm94PSIwIDAgMzQwIDI4MCI+Cgk8aW1hZ2Ugd2lkdGg9IjM0MCIgaGVpZ2h0PSIyODAiIHhsaW5rOmhyZWY9ImRhdGE6aW1hZ2UvanBlZztiYXNlNjQsLzlqLzRBQVFTa1pKUmdBQkFRQUFBUUFCQUFELy9nQTdRMUpGUVZSUFVqb2daMlF0YW5CbFp5QjJNUzR3SUNoMWMybHVaeUJKU2tjZ1NsQkZSeUIyT1RBcExDQnhkV0ZzYVhSNUlEMGdPVEFLLzlzQVF3QURBZ0lEQWdJREF3TURCQU1EQkFVSUJRVUVCQVVLQndjR0NBd0tEQXdM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d6Z0NzNlh4OWNhellMTGF0OWprSDNnL0ZVdmlaOFJrK0hFZ00xbUxrVGNESXJ4enhWOFVyN1U3Q1NTejAzeWd3eU5ncnpWaTY4NXpoN0t5amF6L0FKcnZYN2p3OGRVeHVCblRqUnBlMDUzcnJibFhjOWtiNG5yNGJzcEo5UXVrbmZzcW11djhIK01ZUEZ0a2wxYnNDcDZnZHErUE5QOEFESGkzNGd3R08ydFpDeEdlaHIxYjludWZVL0NWNVBvMnFvNnlvMk1OWDAzMUtGYWxWOWpPOG8yc3JicnI5eDlYbk9YMGFjS1A5bjF2YVNkbkpKV3QzUjZ0OFJ2QVVIanQ0YmFkZG9VNURZNlY1MTRqK0R1citIbDNXQ0xjMnFEb1JYdnpqOTRLbXVQbXMzQjVIdlh4ZVovV2FWSG13OVRsZCsxelpWSVlpdERuanBvamp2Z2RiWDJoeUpOZjJNY2NKWEhTcXZpdlQ0NS9IaHViTzFDUnVjbGxGZDNiL0xab0J3UGFxYklwbnpnWjljVjZQRDJLeFZGT3RYbnp0M1cxZzlyREQxcDhrZE5VZi8vWiI+Cgk8L2ltYWdlPgo8L3N2Zz4= 32w" onload="this.onload=null;this.sizes=Math.ceil(this.getBoundingClientRect().width/window.innerWidth*100)+\'vw\';" sizes="1px" src="/media/2/test.jpg" width="340">
return '<img srcset="/media/2/responsive-images/test___ml_bri_340_280.jpg 340w, /media/2/responsive-images/test___ml_bri_284_233.jpg 284w, /media/2/responsive-images/test___ml_bri_237_195.jpg 237w, data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OT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izes="1px" src="/media/2/test.jpg" width="340">
';
Original file line number Diff line number Diff line change
@@ -18,10 +18,10 @@ public function it_will_register_generated_responsive_images_in_the_db()
$media = $this->testModel->getFirstMedia();

$this->assertEquals([
'test___medialibrary_original_340_280.jpg',
'test___medialibrary_original_284_233.jpg',
'test___medialibrary_original_237_195.jpg',
], $media->responsive_images['medialibrary_original']['urls']);
'test___ml_bri_340_280.jpg',
'test___ml_bri_284_233.jpg',
'test___ml_bri_237_195.jpg',
], $media->responsive_images['ml_bri']['urls']);
}

/** @test */
@@ -36,7 +36,7 @@ public function it_can_render_a_srcset_when_the_base64svg_is_not_rendered_yet()

$responsiveImages = $media->responsive_images;

unset($responsiveImages['medialibrary_original']['base64svg']);
unset($responsiveImages['ml_bri']['base64svg']);

$media->responsive_images = $responsiveImages;

Original file line number Diff line number Diff line change
@@ -17,9 +17,9 @@ public function it_can_generate_responsive_images()
->withResponsiveImages()
->toMediaCollection();

$this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___medialibrary_original_237_195.jpg'));
$this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___medialibrary_original_284_233.jpg'));
$this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___medialibrary_original_340_280.jpg'));
$this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___ml_bri_237_195.jpg'));
$this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___ml_bri_284_233.jpg'));
$this->assertFileExists($this->getTempDirectory('media/1/responsive-images/test___ml_bri_340_280.jpg'));
}

/** @test */