Review main Merged

80617[FEATURE] Crop SVG images natively

Garvin Hicking CR +2 V +2 Expert +1345 −19 updated 04/05/24, 13:17

Commit message

This change adds support for SVGs to be processed. They can be
scaled and cropped, without them being rasterized (converted
to pixel formats like PNG).

This way, SVGs are now natively used for cropping and scaling
without quality loss.

All cropping operations on SVGs will create a processedFile variant,
just like their pixel counterparts. The processed files will
contain SVG wrappers to reset coordinate systems and apply the
cropped viewBox. This way, responsive styling can be applied to
generated images, and processed SVGs can also be used as
background images via <f:uri.image>.

Tests are added for the fluid ViewHelpers as well as TypoScript-
based rendering of assets.

Note that SVG cropping is solely based on the "crop" argument,
either passed to a viewHelper or inferred via the
sys_file_reference entry, that the image editor creates.
Other arguments like `width="100c-10"` which are used for
pixel cropping are not evaluated (because they rely on
pixel operations).

maxWidth and maxHeight attributes (like used in the backend)
will accordingly force a specific size for the <img> tag
and the inner SVG width/height specification. Browsers
can still override this via CSS to enforce lossless resizing.

This change preserves the possibility to rasterize a SVG
to PNG by setting a file extension explicitly.
(Remember, not all image processors support converting SVG
to pixel formats; GraphicsMagick should work, ImageMagick needs
additional helpers.)

Example to keep PNG output format via TypoScript:

```
10 = IMAGE
10.file = 2:/myfile.svg
10.file.crop = 20,20,500,500
10.file.ext = png
```

or via Fluid:

```
<f:image image="{image}" fileExtension="png" />
```

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Benni Mack +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 16

Review log 115170

Show 98145 earlier messages
  1. Garvin Hicking uploaded patch set 1 08/22/23, 13:00

  2. core-ci voted on patch set 1 V -1 08/22/23, 13:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45679

  3. Garvin Hicking commented on patch set 1 08/22/23, 13:26

    OK, I see PHPstan errors on the build pipeline, will address those.
  4. Garvin Hicking uploaded patch set 2 V -1 08/22/23, 14:31

  5. core-ci voted on patch set 2 V +1 08/22/23, 14:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45689

  6. Garvin Hicking commented on patch set 2 08/23/23, 10:04

    To clarify on this patch: This is more a "proof of concept". It is meant to kickstart discussion about how to handle the "non-cropping" of SVGs. A current workaround for us is to override ViewHelpers and simply set the argument `fileExtension` to `svg`. Since this is not a valid output format, the whole core processing logic of converting svg to png/jpg will be circumvented. But overriding a viewhelper remains a workaround. The TYPO3 core should be able to let integrators decide whether SVGs shall be converted to bitmaps or shown as is. The main drawback of this patch as it currently is: It appends a "#svgView(viewBox(...)))" parametrization to the target URI. This is escaped however, and needs to be unsecaped for further processing. Also, the changes needed for the patch are currently a lot, and maybe there is a denser approach to this. If anyone at some point is open for getting this solved, I am open to discussion and creating other PoC variants of this. Let me know - I could also participate in a codesprint about this... :-)
  7. Garvin Hicking uploaded patch set 3 V +1 08/23/23, 17:28

  8. Garvin Hicking commented on patch set 3 08/23/23, 17:31

    I have tried a second approach to this, which doesn't make vector to bitmap processing optional (thanks to input from @lolli42). Testing instructions: * Ensure that you create a test page and insert a standard content element using a SVG image that is rendered through fluid * Make sure you clear your processed files through the TYPO3 backend maintenance panel (existing processed, rasterized files might be cached otherwise!) * Check the HTML source, search for a '#svgView' piece, that should be inserted. * Let me know your thoughts on this or different approaches 😊
  9. core-ci voted on patch set 3 V -1 08/23/23, 17:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45763

  10. Garvin Hicking uploaded patch set 4 V -1 08/23/23, 17:49

  11. core-ci voted on patch set 4 V +1 08/23/23, 17:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45764

  12. Simon Praetorius commented on patch set 4 CR -1 08/25/23, 17:05

    I think that this could be implemented in a cleaner way, either by registering a separate processor for SVG files (see $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['processors'] and TYPO3\CMS\Core\Resource\Processing\ProcessorRegistry) or by using a "BeforeFileProcessingEvent". This would get rid of the "is it a SVG" check in the LocalCropScaleMaskHelper that otherwise uses im/gm for image processing.
  13. Garvin Hicking commented on patch set 4 08/25/23, 17:09

    Reply

    You mean the core on its own should use an event to "fix" this behaviour? I'd have to dig into using FAL processors, I don't have knowledge about this yet on how to proceed with that approach. (Personally, firing events at this or using a full processor when a simple bypass is all that's needed might require more resources and be harder to maintain...? But I value your input on this, I'll check out how much overhead that really would be)
  14. Simon Praetorius commented on patch set 4 08/25/23, 17:15

    Reply

    You're right, the event probably doesn't make sense. 😊 I'd guess that the SVG processor would be pretty lightweight compared to the existing processor. It can also be tested separately and could be extended to cover other SVG-specific adjustments in the future.
  15. Garvin Hicking commented on patch set 4 08/25/23, 17:18

    Reply

    Oh boy. Why did I just now find out about these 'fal' processors? I see there's already a SvgImageProcessor. It bails when 'crop' is defined. So I actually need to "just" implement the croping in that processor I think. Wow, I feel stupid. I'll be processing ;) this and report back with a new approach. Your input was invaluable to me, thank you!
  16. Garvin Hicking commented on patch set 4 08/25/23, 17:21

    Reply

    (I think I'll possibly add a new Processor like SvgImageCropProcessor, so if actually someone ever wants to not Crop SVGs, they could just remove the SvgImageCropProcessor from the configuration...)
  17. Garvin Hicking uploaded patch set 5 CR -1 V +1 08/29/23, 09:21

  18. core-ci voted on patch set 5 V -1 08/29/23, 09:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45961

  19. Garvin Hicking uploaded patch set 6 V -1 08/29/23, 10:00

  20. core-ci voted on patch set 6 V +1 08/29/23, 10:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45966

  21. Garvin Hicking uploaded patch set 7 V +1 08/29/23, 12:37

  22. Garvin Hicking uploaded patch set 8 08/29/23, 12:41

  23. Garvin Hicking uploaded patch set 9 08/29/23, 12:42

  24. Garvin Hicking commented on patch set 9 V +1 CR +1 08/29/23, 12:45

    Reply

    Done

    Reply

    Done
    Sorry for the patchset flood. There was a lot to address, thanks to Simon. I hope this leaves us now to discuss, whether a distinct processor is acceptable. If this can find acceptance, I'll be happy to work on additional tests.
  25. core-ci voted on patch set 7 V -1 08/29/23, 12:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45978

  26. core-ci voted on patch set 8 V -1 08/29/23, 12:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45979

  27. core-ci voted on patch set 9 V -1 08/29/23, 12:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45980

  28. Andreas Kienast commented on patch set 9 08/29/23, 12:53

    General remark: please do not vote your own patch, unless somebody else reworked it completely. Also, if it's a breaking change, please prepend your commit message with `[!!!]`, e.g `[!!!][FEATURE] Prevent SVG...`
  29. core-ci voted on patch set 9 V +1 08/29/23, 12:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45980

  30. Garvin Hicking commented on patch set 9 V 0 CR 0 08/29/23, 12:58

    Reply

    Ah ok, I'm sorry. I'm not familiar enough with this system yet, so this helps. I thought that I could use this to indicate that a patch works on my system, my fault. I'll change the `[!!!]` prefix later, good point. It seems the CI build process is currently wonky, so I don't want to add to the queue and do that later on when additional feedback is provided (and leave this unresolved so long).
  31. Garvin Hicking updated the commit message in patch set 10 V +1 08/30/23, 08:30

  32. Garvin Hicking commented on patch set 10 08/30/23, 08:32

    Reply

    Done
    Updated commit message
  33. core-ci voted on patch set 10 V +1 08/30/23, 08:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46020

  34. Benni Mack commented on patch set 10 09/18/23, 21:09

    clever solution. I like it. Will do some cleanups in this area currently, but will get back to this one soon
  35. Garvin Hicking uploaded patch set 11 V +1 09/19/23, 07:13

  36. Garvin Hicking rebased onto patch set 12 09/19/23, 07:15

  37. Garvin Hicking commented on patch set 12 09/19/23, 07:17

  38. core-ci voted on patch set 11 V +1 09/19/23, 07:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46731

  39. core-ci voted on patch set 12 V +1 09/19/23, 07:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46732

  40. Benni Mack commented on patch set 12 09/20/23, 22:25

    I suggest: - let's move all in one SvgProcessor to ease the complexity, - this way we can reduce the checks in the AbstractImageTask by allowing gif,png,jpeg,jpg,svg as well
  41. Garvin Hicking commented on patch set 12 09/21/23, 05:22

    Reply

    I could happily rebuild that. We would lose the flexibility to offer integrators NOT cropping SVGs then, so if anyone wants to actually rasterize cropped SVGs (for whatever reasons; not exposing raw vectors to the public, preventing security issues of SVGS, ...) -- they would then need to create their own falprocessor. Would be fine with me, just making sure about the implications.
  42. Garvin Hicking commented on patch set 12 09/21/23, 07:03

    Reply

    I think integrators might be able to live with specifying `fileExtension` as a parameter to i.e. f:image to deal with this kind of customization. I'll rework this and also think about testing and a demo extension to reproduce the extension, please hang on. :-)
  43. Benni Mack uploaded patch set 13 V +1 09/21/23, 11:13

  44. Benni Mack commented on patch set 13 09/21/23, 11:13

    Reply

    Done
  45. Garvin Hicking commented on patch set 13 09/21/23, 11:22

    Looking good to me from a "table read" perspective. I'll want to test this with an extension I'm trying to build catching different variations of it. Also want to enhance the commit message with a (working) fluid example on how to use a f:image viewhelper to force pixel conversion. It may take me until next week though to test this. If you need/want to proceed adding this before, don't let me be a holdup. Also not 100% sure on whether `applyCropping()` is a utility method that should be available in another Service and shouldn't be SVG-specific.
  46. core-ci voted on patch set 13 V +1 09/21/23, 11:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47006

  47. Benni Mack commented on patch set 13 CR -1 09/21/23, 11:51

    we need to document the behavior of this processingUrl, this took me most of the time, because this was originally built for deferred images, and is automatically emptied when the file is available. The combination of ->setUsesOriginalFile() and ->updateProcessUrl() needs some more fine-tuning.
  48. Garvin Hicking uploaded patch set 14 CR -1 V +1 09/21/23, 12:20

  49. core-ci voted on patch set 14 V +1 09/21/23, 12:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47010

  50. Garvin Hicking uploaded patch set 15 V +1 09/25/23, 13:11

  51. core-ci voted on patch set 15 V +1 09/25/23, 13:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47154

  52. Oliver Klee commented on patch set 15 09/25/23, 13:20

    SvgImageProcessor.php:111

    For the benefit of the human reader (to reduce cognitive load when reading this code), I suggest switching the condition to include the class: ```php if ($svg instanceof SimpleXMLElement) { ```
  53. Oliver Klee wrote 10/08/23, 13:23

    Removed cc Oliver Klee.
  54. Garvin Hicking commented on patch set 15 10/11/23, 07:23

    Just an update on this, because I only updated it in the ticket and not here: The current patch set 15 seems to work well with a content image crop (FAL-based). It also works when using i.e. a flexform or a custom content element and <f:image> with an image=... FAL reference. However, it does not work when using a <f:image src="..."> definition (non-FAL). Probably because $task->getTargetFile()->updateProcessingUrl(...) is only used for file references with attached crops, but not locally sourced static files? Sadly I don't know where to dig in the reorganized code to make it work for this. The SVG is passed through, but the '#svgBox...' URI fragment is missing. This may actually even be related to changes that seem to deprecate allowing passing non-FAL assets to <f:image> viewHelpers, which is IMO a very important thing that must work (see https://review.typo3.org/c/Packages/TYPO3.CMS/+/81319 for more) Bonus task: Currently it seems using <f:image ... fileExtension="png"> does NOT enforce rendering an SVG through a PNG process, probably because of that same non-FAL problem. I've created a simple extension showcasing the issue (requires the applied patch ofc): https://github.com/garvinhicking/gh_svg_crop
  55. Garvin Hicking uploaded patch set 16 V +1 10/16/23, 13:50

  56. core-ci voted on patch set 16 V +1 10/16/23, 13:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47824

  57. Garvin Hicking commented on patch set 16 10/16/23, 14:04

    (Some improvements, however non-FAL based image conversion/cropping is still broken via f:image, as well as forcing PNG conversion from an SVG via f:image)

    SvgImageProcessor.php:111 Reply

    Thanks, included that (with \SimpleXmlElement)
  58. Benjamin Franzke commented on patch set 16 V -1 10/30/23, 16:34

    Sorry, as much as I'd like this BUGFIX to have, I fear this doesn't work properly for images that are sized via CSS `width` or `height` property, as `#svgView` does only allow to set the viewBox, but doesn't keep infered width/height attributes. I did some testing, and whenever I set `width` or `height` via css the "cropping" (seen in example 1) is lost, because the correct width/height ratio is only available on the HTML tag attributes: https://bnf.dev/~ben/uploads/628dd/svgView-css-width-height.png Also the behavior differes between SVG's that contain `width` and `height` attributes (on the files `<svg>` tag) an those that do not. I think we need to find another way for this issue: We should actually create a proper SVG processor that: * Read's in SVGs * sanitizes via svg-sanitizer * parses viewBox and width/height attributes * wraps the sanitized SVG as-is as a child-svg into an outer `<svg width="…" height="…" viewBox="…">` tag This way the generated SVGs are fully stylable width `width` and `height` and behave as their "pixel"-counterparts. @Garvin, would you like to try doing that?
  59. Garvin Hicking commented on patch set 16 10/30/23, 17:33

    Reply

    I'm quite frustrated with this one here. Current approach did work for many cases but has some quirks, and I wasn't able to work it out on my own. I like your alternate approach you offered. Even though it has more "overhead", it is probably easier in implementation. I'd need someone to bounce approaches against though, because I think I'm a bit over my head in this. I'm much willing to do the legwork here if I could get someone to be a sparring partner (maybe not even a "mentor" level is needed). Would you be able to be "that guy" or anyone else reading this? I'll probably be around for the Codesprint in November, maybe someone would want to look over my shoulder on this... Thanks so much for your constructive criticism (the other's, too!) so far, much appreciated!
  60. Garvin Hicking commented on patch set 16 10/30/23, 17:35

    Reply

    (oh, one more thing - I agree this is no longer a bugfix, since it also now depends on the v13 FAL work to be applicable)
  61. Benjamin Franzke commented on patch set 16 11/27/23, 14:51

    Reply

    Sorry, I didn't noticed your answer. Feel free to ask me anything on slack, I'm sure we/you can get that done.
  62. Garvin Hicking commented on patch set 16 11/27/23, 15:24

    Reply

    Thanks! I'll try to find the willpower (again) for this and try a proof-of-concept with which we hopefully can go on. Due to deadline-projects of mine it may take me a few weeks though!
  63. Garvin Hicking commented on patch set 16 11/30/23, 11:52

    Just to document an update here. There are a couple of quirks that make using the `#svgView(viewBox())` URI fragement not usable within reasons. The main issue being that crops will be scaled/skewed, if the resulting SVG image is scaled via CSS/HTML operations. That can only be remedied by actually creating processed files where the proper viewBox and dimensions are "baked in". These are my findings: * We need "baked-in" viewBoxes. Per viewBox-crop, one processed file will need to be generated. Just like with pixel images. * We want to use IMG tags, because CSS styling is easier and less-breaking than requiring to style a SVG tag (which would prevent one layer of processed-file wrapping). Also, only with the img-way (using a wrapped processe file) we can use processed files as background images (i.e. make f:uri.image work with SVGs, too). * The processed file should create a SVG wrapper around the original input file. * We can NOT use the inline `<image>/<use>` reference to the original image, because browser's security models will not resolve it. The same reason prevents using `src:data...`. * The original input file needs manipulation to enforce receiving width/height attributes, because otherwise the cropping will not be relative to the image dimensions. * More specifically: The actual processing logic will need to ensure that width/height/viewbox attributes are properly set on both inner ("original file") and outer SVG ("crop/scale variant"). To allow proper browser resizing / responsivity on the `<img>` tag, the logic should be applied for both cropping and scale (without crop). A demo showing the evolution and issues of the alternatives can be checked out here https://gist.github.com/garvinhicking/257d4920da4da0c0e1c3fba3a0b313c9 Will check further with all of the Benjamins available to me. ;-)
  64. Garvin Hicking uploaded patch set 17 V +1 12/01/23, 20:59

    Huge rework dropping URI fragments creating processed files
  65. Garvin Hicking commented on patch set 17 12/01/23, 21:02

    I've spent a LOT of time on this now to get reworked to my "proof-of-concept" way of processing files, since the URI fragement thing proved a one-way-street. I've tested this with a simple dev environment here: https://github.com/garvinhicking/typo3-core-bugreproduce/tree/issue_80617 specifically: https://github.com/garvinhicking/typo3-core-bugreproduce/blob/issue_80617/packages/gh_svg_crop/Resources/Private/Templates/List.html This is still a bit flakey and needs refactoring, but I'm now holding my horses to get some feedback on both proof-of-concept and this current approach. Fingers crossed.
  66. core-ci voted on patch set 17 V -1 12/01/23, 21:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50222

  67. Garvin Hicking uploaded patch set 18 V -1 12/01/23, 21:10

    Removed accidental commit to cleanup task removed ViewHelper because this did not work as intended
  68. Garvin Hicking uploaded patch set 19 12/01/23, 21:12

    Revert once more with feeling
  69. core-ci voted on patch set 18 V -1 12/01/23, 21:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50223

  70. core-ci voted on patch set 19 V -1 12/01/23, 21:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50224

  71. Garvin Hicking uploaded patch set 20 V -1 12/01/23, 21:20

    CGL
  72. core-ci voted on patch set 20 V +1 12/01/23, 21:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50225

  73. Garvin Hicking uploaded patch set 21 V +1 12/19/23, 15:21

    Rebased fixed conflicts
  74. core-ci voted on patch set 21 V +1 12/19/23, 15:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50819

  75. Garvin Hicking uploaded patch set 22 V +1 12/19/23, 22:58

    Add tests
  76. core-ci voted on patch set 22 V -1 12/19/23, 23:03 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50825

  77. Garvin Hicking uploaded patch set 23 V -1 12/19/23, 23:09

    Fix ACL perms on SVGs and remove obsolete array
  78. core-ci voted on patch set 23 V +1 12/19/23, 23:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50828

  79. Simon Praetorius commented on patch set 23 12/21/23, 13:10

    SvgImageProcessor.php:104

    Maybe use null as fallback values here and apply real fallback values later when calling applyCroppingToProcessedFile()? That way the processor would behave similar when the json is invalid and when the comma-separated format is invalid/incomplete. Also, I'm not sure if 1 would be a better fallback for height/width?

    SvgImageProcessor.php:116

    Maybe a short example of the new svg structure could be added here as a comment.

    SvgImageProcessor.php:123

    Maybe a better variable name would be something like "wrapperSvg" or "croppedSvg"? I found the code hard to understand because of the two files

    SvgImageProcessor.php:137

    This would leak the TYPO3 version to a publicly available file. I don't think that this is wise and necessary.

    SvgImageProcessor.php:163

    Why are the original dimensions used here? If that's correct, it should be explained in the comment

    SvgImageProcessor.php:173

    If it exists, take info from that file and mark task as done

    SvgImageProcessor.php:215

    I would suggest "determineSvgDimensions" as an alternative name

    SvgImageProcessor.php:229

    Check for existence of 2 and 3. If the viewbox is invalid/incomplete, it's probably best to check for width/height next?

    SvgImageProcessor.php:235

    I would check if the width/height value is a valid number, for example with is_numeric(). If it isn't, fallback to default dimension.
  80. Garvin Hicking uploaded patch set 24 V +1 12/21/23, 22:23

    Added more tests and fixtures
  81. core-ci voted on patch set 24 V -1 12/21/23, 22:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50879

  82. Garvin Hicking uploaded patch set 25 V -1 12/21/23, 22:47

    Moved expecation check
  83. Garvin Hicking commented on patch set 25 12/21/23, 22:51

    @Simon - thanks for your initial review. That helped to refactor a few shortcomings and I hope to have adressed these properly. I'll still need to perform more tests on crop via "c" and "m" parameters, ensure it all works with (max|min)(Width|Height) set/unset, and add FAL-UID tests for the typoscript-based tests. The other crop tests now got a massive boost with 144 variations checked now. This is not really great to test, this "crop" syntax with sometimes relative 0..1 values or absolute X/Y coordinates and their juggling back and forth.

    SvgImageProcessor.php:104 Reply

    Note sure about this one yet, need to think on it and add more tests.

    SvgImageProcessor.php:116 Reply

    Done

    SvgImageProcessor.php:123 Reply

    Done

    SvgImageProcessor.php:137 Reply

    Done

    SvgImageProcessor.php:163 Reply

    Done

    SvgImageProcessor.php:173 Reply

    I copy+pasted this from LocalImageProcessor. The wording was a bit odd. I've adjusted it in both places now.

    SvgImageProcessor.php:215 Reply

    Done

    SvgImageProcessor.php:229 Reply

    Done

    SvgImageProcessor.php:235 Reply

    Done
  84. Garvin Hicking commented on patch set 25 12/21/23, 22:52

    Reply

    Done

    Reply

    Done

    Reply

    Done
  85. core-ci voted on patch set 25 V +1 12/21/23, 22:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50884

  86. Garvin Hicking uploaded patch set 26 V +1 12/23/23, 10:45

    Switch SVG assets for smaller variants
  87. core-ci voted on patch set 26 V -1 12/23/23, 10:52 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50925

  88. Garvin Hicking uploaded patch set 27 V -1 12/23/23, 11:03

    Fix unneeded fixture of pages
  89. core-ci voted on patch set 27 V +1 12/23/23, 11:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50926

  90. Garvin Hicking uploaded patch set 28 V +1 12/23/23, 18:25

    XML bugfix and optimize testing assets
  91. core-ci voted on patch set 28 V +1 12/23/23, 18:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50941

  92. Garvin Hicking uploaded patch set 29 V +1 12/23/23, 18:54

    Add safety typechecks for crop input conversion
  93. Garvin Hicking commented on patch set 29 12/23/23, 18:54

    SvgImageProcessor.php:104 Reply

    OK, I've altered this place to better handle fallbacks. I cannot use "null" due to later typehinting, where I want to expect integers. A malformed "crop" string could happen when passed to the imgResource typoscript place. ViewHelpers actually do not allow a commaseparated string, it only works with arrays (raw or json_encoded). Thanks for pointing me to this, I also now fall back to the image's width/height, if a malformed input cannot resolve proper newWidth/newHeights.
  94. core-ci voted on patch set 29 V +1 12/23/23, 18:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50942

  95. Anja Leichsenring commented on patch set 29 CR +1 V +1 01/03/24, 07:08

    that works like a charm. Thank you very much for taking care of this annoyance.
  96. Benjamin Franzke commented on patch set 29 CR -1 01/03/24, 09:46

    Thank you, looks good regarding the general approach: As we already discussed last year via slack (so this is basically for other reviewers): neither data-uri's (browsers didn't load them) nor references via <image> (not working for protected storages), nor svg fragments (css issues) where options, so yea, while this approach has the slight drawback, that we have to copy the entire SVG, it's the only compatible way for solving this we could find. So I think we should get this done. Some early remarks regarding the implementation below – I will test this soon, but will leave this feedback for now already. still -1 for now, as I'm certain `width`/`height` has to prefered over `viewBox` for initial/original width/height calculation.

    SvgImageProcessor.php:180

    I think preserveAspectRatio should be "preserved" => copy from inner svg

    SvgImageProcessor.php:182

    This seems unneeded, as the dimensions are available from the inner element. This looks a bit like a (useful) debugging helper, but nothing we'd want in production.

    SvgImageProcessor.php:185

    Not sure I like this: * Information Disclosure(?) * Do you mean to use this for future migrations? we do not have the raw input data available anyway, so I don't think we can autoupdate anyway.

    SvgImageProcessor.php:232

    This looks wrong, the initial width/height is the `width` and `height` attribute. We should only fallback to deviate from viewBox in case we encounter an SVG without explicit `width`/`height` attributes. I'll look into that, but for now this is a blocker IMO.

    SvgImageProcessor.php:273

    Looks good (because yea, wouldn't work without explicit inner width/height) definition in general. I just wonder what to do in case only one of the attributes is provided. Leaving this open in order to test such a case: We had cases where `<svg xmlns="http://www.w3.org/2000/svg"; height="135">…</svg>` was used to be able to only vertically scale an SVG. – sure we can't "properly" crop those, just want to test what happens to that wrapper, in order to avoid problematic bugs)
  97. Garvin Hicking commented on patch set 29 01/03/24, 10:39

    Thanks Benjamin for having a look. Just some quick feedback on one issue. Please feel free to modify this patch with changes. You probably are right about the width/height usage and its preference.

    SvgImageProcessor.php:185 Reply

    Yes I changed that from the main TYPO3 version after Simons remark. I do think we might need migrations and need some kind of information for it. We would only bump this version when needed, so a direct relation might not be needed? The original data is wrapped, so we could use it? Then again, we could also rebuild...
  98. Garvin Hicking uploaded patch set 30 CR +1 V +1 01/08/24, 09:19

    Rework width and height logic brush up
  99. Garvin Hicking commented on patch set 30 01/08/24, 09:20

    Adressed Benjamins comments, reworked width/height logic and removed some unneeded attributes. Crossing my fingers we could get this wrapped up for 13.0.

    SvgImageProcessor.php:180 Reply

    Good idea. Actually I can now remove a fixed default setting ("xMidYMid meet" is a default already).

    SvgImageProcessor.php:182 Reply

    Agreed. Added that as a comment, so it can be easily used and there's a pointer for people looking into it in the future.

    SvgImageProcessor.php:185 Reply

    After some more thought, I agree and removed this. Thanks for addressing it. We probably should just re-create all cropped SVG assets (could be deduced from sys_file_processedfile) in case of formatting changes. Just deleting the processed files and entries would then use new code, if added.

    SvgImageProcessor.php:232 Reply

    Yes, you are right. viewBox lead me onto a wrong path because it appeared as if pixel sizes were used there, while width/height COULD actually have "150cm" or "50%" values. I checked this with uploading SVGs into TYPO3v12 using a `width='50%'` or `width='23mm'` and there the image information gets saved as `50px`/`23px`, so the unit is just dropped. This kind of makes sense, because without DPI output information on processing, a real calculation can't be made, and a unit of `1` seems to make sense. I adapted the code to account for this, it now uses: * Use width/height, if numeric values (pixel) * else: if viewBox width/height is set, use that. * else: remove the unit, use width/height * else: no width/height, use viewBox * else: no width/height, no viewBox, use defaultDimensions (64x64) - but such an SVG will be quite broken

    SvgImageProcessor.php:273 Reply

    Can you provide an actual SVG of how the input would then look like, especially how/if a viewBox attribute was specified? I created a simple SVG image with only `height` attribute set, and I can't even upload such a SVG file to TYPO3v12 (it shows up as broken, has no dimensions set).
  100. core-ci voted on patch set 30 V +1 01/08/24, 09:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51206

  101. Garvin Hicking rebased onto patch set 31 V +1 01/25/24, 19:41

  102. core-ci voted on patch set 31 V +1 01/25/24, 19:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52204

  103. Benni Mack commented on patch set 31 01/25/24, 22:53

    ContentObjectRenderer.php:3725

    this can be removed, as I've done this a 2 lines further below
  104. Garvin Hicking uploaded patch set 32 V +1 01/26/24, 06:24

    Remove double floatval cast
  105. Garvin Hicking commented on patch set 32 01/26/24, 06:25

    ContentObjectRenderer.php:3725 Reply

    Thanks. Wonder if this got introduced with the rebase, can't remember seeing this.
  106. core-ci voted on patch set 32 V +1 01/26/24, 06:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52212

  107. Garvin Hicking rebased onto patch set 33 V +1 01/29/24, 13:56

  108. core-ci voted on patch set 33 V +1 01/29/24, 14:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52419

  109. Benni Mack commented on patch set 33 02/05/24, 07:33

    SvgImageProcessor.php:215

    should we remove the local file §temporaryFilename again?
  110. Garvin Hicking commented on patch set 33 02/05/24, 07:54

    SvgImageProcessor.php:215 Reply

    The local processed file is what gets emitted to the browser, so we need it (to prevent re-cropping the samw file time and again), or did I misunderstand you? (will address the merge conflicts later today, should be easy because Simons patch implemented part of my tests too)
  111. Garvin Hicking uploaded patch set 34 V +1 02/05/24, 08:49

    Rebase
  112. core-ci voted on patch set 34 V +1 02/05/24, 09:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52704

  113. Garvin Hicking uploaded patch set 35 V +1 02/26/24, 08:40

    Adapt to phpunit attributes
  114. Garvin Hicking uploaded patch set 36 02/26/24, 08:45

    Revert accidental commits from rector run
  115. core-ci voted on patch set 35 V -1 02/26/24, 08:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53584

  116. core-ci voted on patch set 36 V +1 02/26/24, 08:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53586

  117. Benni Mack uploaded patch set 37 V +1 03/05/24, 21:14

  118. core-ci voted on patch set 37 V -1 03/05/24, 21:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53984

  119. Benjamin Franzke uploaded patch set 38 V -1 03/05/24, 21:55

  120. Benjamin Franzke commented on patch set 38 03/05/24, 21:55

    SvgImageProcessor.php:114

    I'd like to understand when this case happens (that we receive crop data that does not define a width/height, only x/y) (This smells like this should be an exception instead, but I'll need to check other processors) The respective code in typo3/sysext/core/Classes/Imaging/ImageProcessingInstructions.php::streamlineOptions seems to assume that the width/height has to be set in the crop configuration. In general I wonder whether we can reuse the code for parsing the `crop`-string.

    SvgImageProcessor.php:116

    Can you point me to the place where te string representation is parsed for other image processors? (well, or is that passed-through to imagemagick? (in that case I'd add a comment, that we're preg-parsing the imagemgick syntax in here)
  121. core-ci voted on patch set 38 V -1 03/05/24, 22:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53987

  122. Benjamin Franzke commented on patch set 38 03/05/24, 22:06

    SvgImageProcessor.php:215 Reply

    The processed file is placed into the FAL storaged processed folder. For fileadmin that would be `/fileadmin/_processed_/`. We're still fine here, since updateWithLocalFile call FAL addFile which renames the input file. => That means the file is moved from typo3temp to `/fileadmin/_processed_/`. Therefore I'm resolving here

    SvgImageProcessor.php:273 Reply

    Simply removing the width attribute. But that is really a corner case and the code is handling this properly. All good.
  123. Benjamin Franzke uploaded patch set 39 CR -1 V +1 03/05/24, 22:28

    Revert to patchset 37
  124. core-ci voted on patch set 39 V -1 03/05/24, 22:33 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53989

  125. Benjamin Franzke uploaded patch set 40 V -1 03/05/24, 22:39

  126. core-ci voted on patch set 40 V +1 03/05/24, 22:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53991

  127. Oli Bartsch wrote 03/05/24, 23:10

    Removed cc Oli Bartsch.
  128. Benjamin Franzke uploaded patch set 41 V +1 03/05/24, 23:50

  129. Benjamin Franzke commented on patch set 41 03/05/24, 23:50

    SvgImageProcessor.php:114 Reply

    Removed and streamlined into ParseCropTrait.

    SvgImageProcessor.php:116 Reply

    See above, moved into ParseCropTrait
  130. core-ci voted on patch set 41 V -1 03/05/24, 23:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53993

  131. Benjamin Franzke uploaded patch set 42 CR +1 V +1 03/06/24, 05:24

  132. core-ci voted on patch set 42 V +1 03/06/24, 05:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53997

  133. Garvin Hicking uploaded patch set 43 CR +1 V +1 03/06/24, 11:30

    Consider maxWidth and maxHeight
  134. core-ci voted on patch set 43 V -1 03/06/24, 11:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54025

  135. Garvin Hicking uploaded patch set 44 V -1 03/06/24, 11:42

    Missed a rounding entry in commit
  136. core-ci voted on patch set 44 V +1 03/06/24, 11:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54027

  137. Garvin Hicking commented on patch set 44 03/06/24, 12:00

    As discussed with Benjamin Franzke, there was a problem in the backend. The FAL picker (IRRE assignment in a content element) used image maxWidth/maxHeight specifications. The current approach did not take that into account, because it was focussed at frontend integration, where a SVG asset is usually embedded with a fixed size (or inherent) and scaled via CSS. I've now addressed this via: * Passing along the imageDimension object to retrieve the calculated image size. `ImageProcessingInstructions::fromCropScaleValues()` does that, by way of `ImageDimension::fromProcessingTask()`. * That imageDimension object now fills width/height for both `targetFile::updateProperties()` as well as the wrapping `<svg>` container width/height attributes * Adjusted tests for that, and added a maxWidth test case, too. Adjusted commit message to drop the maxWidth note. * The tests revealed that the missing rounding of image dimension calculation don't account for the now created image dimensions (width/height calculation does the same `round()`, so it would mismatch if the crops were not rounded, too. That is in line with Benjamin's todo note, which is now removed. * Since this is not backportable anymore (within reason) we might want to declare it as a feature. Adjusted title, and added a ReST with it, that describes this very briefly.
  138. Benjamin Franzke commented on patch set 44 CR +1 V +1 03/06/24, 12:02

    ❤️
  139. Marvin Buchmann voted on patch set 44 V +1 03/08/24, 09:11

  140. Benjamin Franzke uploaded patch set 45 CR +1 V +1 03/08/24, 10:41

  141. core-ci voted on patch set 45 V -1 03/08/24, 10:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54232

  142. Benjamin Franzke uploaded patch set 46 V -1 03/08/24, 18:26

  143. core-ci voted on patch set 46 V -1 03/08/24, 18:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54297

  144. Benjamin Franzke uploaded patch set 47 V -1 03/08/24, 19:09

  145. Benjamin Franzke voted on patch set 47 CR +1 V +1 03/08/24, 19:10

  1. core-ci voted on patch set 47 V -1 03/08/24, 19:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54304

  2. Benjamin Franzke uploaded patch set 48 CR +1 V +1 03/08/24, 19:24

  3. Benjamin Franzke voted on patch set 48 CR +1 03/08/24, 19:24

  4. core-ci voted on patch set 48 V -1 03/08/24, 19:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54305

  5. Benjamin Franzke uploaded patch set 49 CR +1 V +1 03/08/24, 19:43

  6. core-ci voted on patch set 49 V -1 03/08/24, 19:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54307

  7. Benjamin Franzke uploaded patch set 50 V -1 03/08/24, 21:06

  8. core-ci voted on patch set 50 V +1 03/08/24, 21:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54310

  9. Benjamin Franzke rebased onto patch set 51 V +1 03/11/24, 07:17

  10. core-ci voted on patch set 51 V +1 03/11/24, 07:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54348

  11. Garvin Hicking commented on patch set 51 03/11/24, 09:13

    Thanks Benni & Benjamin for iterating on this again. Tried and works in all my test cases with all my test assets.
  12. Benni Mack uploaded patch set 52 V +1 03/11/24, 16:07

  13. Benni Mack voted on patch set 52 CR +1 V +1 03/11/24, 16:08

  14. Benni Mack uploaded patch set 53 CR +1 V +1 03/11/24, 16:10

  15. core-ci voted on patch set 52 V +1 03/11/24, 16:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54375

  16. Benni Mack voted on patch set 53 CR +1 V +1 03/11/24, 16:13

  17. core-ci voted on patch set 53 V +1 03/11/24, 16:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54376

  18. Benni Mack uploaded patch set 54 CR +1 V +1 03/11/24, 16:22

  19. Benni Mack voted on patch set 54 CR +1 V +1 03/11/24, 16:22

  20. Benjamin Franzke voted on patch set 54 CR +1 V +1 03/11/24, 16:24

  21. core-ci voted on patch set 54 V +1 03/11/24, 16:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54377

  22. Benjamin Franzke voted on patch set 54 CR +2 V +2 03/11/24, 16:46

  23. Benjamin Franzke merged patch set 55 03/11/24, 16:46

  24. Oliver Hader commented on patch set 55 03/11/24, 17:44

    SvgManipulation.php:60

  25. Garvin Hicking commented on patch set 55 04/05/24, 13:17

    SvgManipulation.php:60 Reply

    Acknowledged