Skip to content

feat: add clearMetadata() method to provide privacy options when using imagick handler #9538

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

Open
wants to merge 6 commits into
base: 4.7
Choose a base branch
from

Conversation

michalsn
Copy link
Member

@michalsn michalsn commented Apr 22, 2025

Description
This PR introduces a flexible clearMetadata() method that allows for convenient and configurable removal of image metadata, which can improve privacy.

While metadata such as EXIF is automatically stripped when using the GD image handler, this method is specifically designed for use with the Imagick handler, where metadata is preserved by default.

To ensure API consistency, the BaseHandler also provides the same clearMetadata() method, but it is implemented as a no-op (does nothing).

Reference: #6149 (comment)

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added enhancement PRs that improve existing functionalities 4.7 labels Apr 22, 2025
@michalsn
Copy link
Member Author

Okay, I guess I have to revisit the data I'm trying to strip. I will look for an example JPEG (preferably small) with some ready EXIF data because our default PNG acts differently depending on the OS.

This will have to wait, probably for tomorrow.

@michalsn
Copy link
Member Author

Okay, apparently I was too optimistic to introduce various options for deleting metadata and we have to make it work only with simple stripping of all the data. When imagick shows properties like exif:DateTime, it's parsed from the binary profile for display, but deletion via deleteImageProperty() doesn't actually modify the binary EXIF block.

I thought I could make it more flexible, but it will not work the same for all images… Now, after the changes, we will have the same functionality for both handlers - just stripping all the metadata.

@github-actions github-actions bot added the stale Pull requests with conflicts label May 2, 2025
@michalsn michalsn force-pushed the feat/image-clearMetadata branch from c6cb511 to f85e635 Compare May 2, 2025 15:44
@michalsn michalsn removed the stale Pull requests with conflicts label May 2, 2025
@codeigniter4 codeigniter4 deleted a comment from github-actions bot May 2, 2025
@michalsn
Copy link
Member Author

michalsn commented May 2, 2025

@paulbalandan Now I'm wondering, shouldn't we also modify the interface? It would be a breaking change, but making sure every handler has the clearMetadata() method seems valid. What do you think?

@paulbalandan
Copy link
Member

That seems fair considering that we want to reduce the disconnect of methods in the abstract class and the interface. However, we should also think if other image handlers (if there's any) implementing solely the interface would need the clearMetadata() method. Otherwise, we would be violating the interface segregation principle.

@michalsn
Copy link
Member Author

michalsn commented May 2, 2025

There are two other possible image handlers that come to my mind: Gmagick and libvips. Both support clearing metadata from images, so including a clearMetadata() method in the interface might make sense.

It's possible that someone has extended the existing handlers to add new features, but this would not produce any problems. If a new handler had been developed, I would assume we’d have seen a PR by now - though perhaps that’s an optimistic assumption.

@samsonasik Do you have any opinion on this one?

@paulbalandan
Copy link
Member

Hmm. Then we can go add the clearMetadata method to the interface.

@michalsn
Copy link
Member Author

michalsn commented May 3, 2025

I have added this new method to the interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.7 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants