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

Modified image gets reset after html() in twig template; width and height not correct #3568

Open
Rotzbua opened this issue Mar 21, 2022 · 1 comment
Assignees

Comments

@Rotzbua
Copy link
Contributor

Rotzbua commented Mar 21, 2022

Environment

Grav: v1.7.31
Admin: v1.10.31

auto_sizes is enabled.

Example

Twig template

{# test 1 #}
{% set img1 = image.cropResize(1200,1200) %}
{{ img1.path() }} {# path to cropResize image #}
{{ img1.path() }} {# suddenly reset to original image #}

{# test 2 #}
{% set img1 = image.cropResize(1200,1200) %}
{{ img1.get('width')|raw }} {# original width not expected cropResize #}
{{ img1.get('height')|raw }} {# original height not expected cropResize, but not resets the image #}
{{ img1.html()|raw }} {# outputs correct width and height #}
{{ img1.html()|raw }} {# suddenly reset to original image #}

{# test 3 #}
{% set img1 = image.cropResize(1200,1200) %}
{{ img1.get('width')|raw }} {# original width not cropResize #}
{{ img1.get('height')|raw }} {# original height not cropResize #}
{{ img1.path()|getimagesize[0] }} {# correct width #}
{{ img1.path()|getimagesize[1] }} {# resets to original like test 1 #}

{# test 4 #}
{{ image.cropResize(1200,1200).html()|raw }}
{{ image.cropResize(1200,1200).html()|raw }} {# correct file, not reset like in test 1 #}

Output

{# test 1 #}
/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg
/images/5/e/4/4/1/5e44127351cd4a12f9aaeb4691c964e272f76321.jpeg 

{# test 2 #}
2736
1824
<img alt="" src="/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg" width="1200" height="800" />
<img alt="" src="/images/5/e/4/4/1/5e44127351cd4a12f9aaeb4691c964e272f76321.jpeg" width="2736" height="1824" /> 

{# test 3 #}
2736
1824
1200
1824 

{# test 4 #}
<img alt="" src="/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg" width="1200" height="800" />
<img alt="" src="/images/d/9/7/9/5/d979577c736379ff6a39ce03de454b7218037681.jpeg" width="1200" height="800" />

Expected behavour

  • Output should not change if html() is called twice like in test 2.
  • Output should be consistent like test 4.
  • Furthermore the width and height should be from the modified image and not the original image.

Related issues

@mahagr
Copy link
Member

mahagr commented Mar 22, 2022

Actually, html() and some other methods reset the image "by purpose". Also, the size of the image only changes only when the operations get applied. So the results are what I am expecting due to limitations in the implementation.

That said, I'm currently rewriting all of this logic for Grav 1.8; the size is now being calculated per operation, but I have not yet touched the reset behavior as I think it's being used in somewhere.

@mahagr mahagr self-assigned this Mar 22, 2022
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

No branches or pull requests

2 participants