Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow switching the ImageManager driver #3195

Merged
merged 11 commits into from
Dec 12, 2021
Merged

Conversation

imorland
Copy link
Member

@imorland imorland commented Dec 12, 2021

I recently identified an issue where image uploads were rendered with different color gamuts if they had been processed by Intervention in any way (resized, etc), if they had an embedded icc color profile. By switching to imagick, this profile was respected. Therefore, I'd like to introduce the option to use either driver everywhere in Flarum.

We use the ImageManager from Intervention in plently of places, both in core and extensions. Intervention supports two drivers - gd (default) and imagick. ref

This PR adds the possibility to switch to imagick, if this is required.

By default gd will still be used, however, adding the following to config.php, one can specify the alternative:

'intervention' =>
  array (
    'driver' => 'imagick',
  )

Extensions should update their code and refrain from new ImageManager() and resolve the singleton from the container instead.

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

@imorland imorland changed the title wip: Allow switching the ImageManager driver feat: Allow switching the ImageManager driver Dec 12, 2021
@imorland imorland marked this pull request as ready for review December 12, 2021 20:13
@matteocontrini
Copy link
Contributor

Pay attention to the fact that ImageMagick by default not only doesn't strip the ICC profile but EXIF data in general, which means that GPS data contained in an image's EXIF could be unintentionally leaked to everyone.

@askvortsov1
Copy link
Sponsor Member

Could we inject the ImageManager as a constructor dependency where possible?

Pay attention to the fact that ImageMagick by default not only doesn't strip the ICC profile but EXIF data in general, which means that GPS data contained in an image's EXIF could be unintentionally leaked to everyone.

We'd still be using gd as the default though? I feel like this is something we might want to mention in documentation rather than adding a layer to address it ourselves.

@imorland
Copy link
Member Author

I feel like this is something we might want to mention in documentation rather than adding a layer to address it ourselves.

Agreed. I'll look at adding something for this in fof/upload to protect GPS data, etc

@matteocontrini
Copy link
Contributor

Agreed. I'll look at adding something for this in fof/upload to protect GPS data, etc

If it helps, this is what I've been doing in a private extension in production for years I think:

$exif = $img->getCore()->getImageProfiles('exif', false);
if (count($exif) > 0) {
    $img->getCore()->removeImageProfile('exif');
}

The exif profile includes for example the GPS data but not the ICC data.

@SychO9 SychO9 added this to the 1.2 milestone Dec 12, 2021
@SychO9 SychO9 merged commit bd8ebb0 into master Dec 12, 2021
@SychO9 SychO9 deleted the im/intervention-driver branch December 12, 2021 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants