spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

[11.x] Incorrect PDF conversion results when used with GD driver #3475

Closed kduma closed 11 months ago

kduma commented 11 months ago

Continuation of #3465.

With following configuration in User.php model:

public function registerMediaConversions(Media $media = null): void
{
    $this->addMediaConversion('preview')
        ->fit(Fit::Crop, 300, 300)
        ->format('png')
        ->nonQueued();
}

Given the following test case: ExampleTest.php

$user = \App\Models\User::factory()
    ->create();

$user
    ->addMedia(resource_path('dummy.pdf'))
    ->preservingOriginal()
    ->toMediaCollection();

$path = $user->getFirstMediaPath(conversionName: 'preview');

[$width, $height] = getimagesize($path);

$this->assertEquals(300, $width, 'The width of the conversion is not 300px.');
$this->assertEquals(300, $height, 'The height of the conversion is not 300px.');

The generated conversion is incorrect. Here are results from failed assertions:

1) The width of the conversion is not 300px.
Failed asserting that 1190 matches expected 300.
Expected :300
Actual   :1190

2) The height of the conversion is not 300px.
Failed asserting that 1684 matches expected 300.
Expected :300
Actual   :1684

Repository with test app: kduma-archive/test-laravel-medialibrary-failing-pdf

freekmurze commented 11 months ago

Let me know when #3476 can be reviewed.

Thanks for you work on this.

kduma commented 11 months ago

Let me know when #3476 can be reviewed.

Thanks for you work on this.

@freekmurze Looks that spatie/image#221 PR fixes this.