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

Image Transparency/Opacity Including Html Reader Changes #4142

Merged
merged 14 commits into from
Oct 8, 2024

Conversation

oleibman
Copy link
Collaborator

See discussion #4117. This PR implements image transparency, for Xlsx Reader and Writer, Html Reader, and Html/Dompdf/Mpdf Writer. (Mpdf treats 100% opacity as if it were zero, but it's otherwise okay and that would be an unusual choice anyhow.) A new property opacity with getter/setter is added to BaseDrawing (and therefore Drawing and MemoryDrawing). Although the Excel UI lets you set the image transparency, the value stored in the Xml is actually its opacity (expressed as an integer between 0 and 100,000). Likewise Html/Css lets you set opacity (as a float between 0 and 1). PhpSpreadsheet lets you set it as it is stored in Xml - so a value of 40,000 would indicate 40% opacity = 60% transparency.

In the course of testing, some problems with Html Reader presented themselves. They are corrected as part of this ticket:

  • Web page title will no longer be "Untitled Spreadsheet" if a title tag is present in the header section of the html.
  • If a class attribute is used with the table tag representing a worksheet, showGridlines and printGridlines will be set according to whether gridlines and/or gridlinesp are among the class names.
  • Reader has been performing urldecode on the src attribute of the img tag. This breaks data url's by converting plus signs to spaces. It will now perform urldecode only for non-data url's.
  • If height and width are not used as attributes on the img tag, they will be extracted from the style attribute if they are present there.

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

Why this change is needed?

Provide an explanation of why this change is needed, with links to any Issues (if appropriate).
If this is a bugfix or a new feature, and there are no existing Issues, then please also create an issue that will make it easier to track progress with this PR.

See discussion PHPOffice#4117. This PR implements image transparency, for Xlsx Reader and Writer, Html Reader, and Html/Dompdf/Mpdf Writer. (Mpdf treats 100% opacity as if it were zero, but it's otherwise okay and that would be an unusual choice anyhow.) A new property `opacity` with getter/setter is added to BaseDrawing (and therefore Drawing and MemoryDrawing). Although the Excel UI lets you set the image *transparency*, the value stored in the Xml is actually its *opacity* (expressed as an integer between 0 and 100,000). Likewise Html/Css lets you set opacity (as a float between 0 and 1). PhpSpreadsheet lets you set it as it is stored in Xml - so a value of 40,000 would indicate 40% opacity = 60% transparency.

In the course of testing, some problems with Html Reader presented themselves. They are corrected as part of this ticket:
- Web page title will no longer be "Untitled Spreadsheet" if a title tag is present in the header section of the html.
- If a class attribute is used with the table tag representing a worksheet, showGridlines and printGridlines will be set according to whether gridlines and/or gridlinesp are among the class names.
- Reader has been performing urldecode on the src attribute of the img tag. This breaks data url's by converting plus signs to spaces. It will now perform urldecode only for non-data url's.
- If height and width are not used as attributes on the img tag, they will be extracted from the style attribute if they are present there.
I usually ignore complexity warnings, but let's see if I can fix this one.
Do not allow use of Php propietary protocols to retrieve linked images. Restrict to http, https, ftp, file, and s3.
Render hyperlink as text if it begins with a string of word characters followed by colon, unless the string is one of http, https, file, ftp, or s3.
@oleibman oleibman marked this pull request as draft October 7, 2024 17:54
@oleibman
Copy link
Collaborator Author

oleibman commented Oct 7, 2024

Too much has happened since this PR was started. I will probably replace it with a new version.

@oleibman oleibman marked this pull request as ready for review October 7, 2024 19:39
@oleibman
Copy link
Collaborator Author

oleibman commented Oct 7, 2024

Not sure why "docs" step failed, but, since this PR doesn't update any docs, I don't think there's any cause for concern.

@oleibman oleibman added this pull request to the merge queue Oct 8, 2024
Merged via the queue into PHPOffice:master with commit 8a57259 Oct 8, 2024
12 of 13 checks passed
@oleibman oleibman deleted the imgtransparent branch October 8, 2024 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant