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

Grav's Responsive Images functionality not working/working differently #1136

Closed
nineteeneightyeight opened this issue Oct 27, 2016 · 13 comments · Fixed by #1147
Closed

Grav's Responsive Images functionality not working/working differently #1136

nineteeneightyeight opened this issue Oct 27, 2016 · 13 comments · Fixed by #1147

Comments

@nineteeneightyeight
Copy link

(https://learn.getgrav.org/content/media#responsive-images)

Since updating Grav (to 1.1.8) my client's site has been getting some errors relating to the responsive images support. In the admin plugin, when selecting an image from the dropdown it is now showing 'image@3x.jpg' - previously that would have been 'image.jpg' - because the responsive images functionality within Grav would have done it's magic and generated 3 images (i.g. image.jpg, image@2x.jpg and image@3x.jpg).

If the image is set to just 'image.jpg' within the markdown itself, then an error occurs:

Whoops\Exception\ErrorException thrown with message "imagecreatetruecolor(): product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
"

Stacktrace:
#0 Whoops\Exception\ErrorException in /home/grav/www/html/vendor/gregwar/image/Gregwar/Image/Adapter/GD.php:77
@flaviocopes
Copy link
Contributor

From which dropdown you select an image? A filepicker field?

@flaviocopes
Copy link
Contributor

I tried uploading a image@3x.png image in the Page Media and inserted it as ![](image.png) in the markdown, was added correctly in the frontend as

<img src="/grav-develop/images/2/3/6/7/7/2367706e56f8dce23de92170318e212d8a219a0f-image1x.png" srcset="/grav-develop/images/2/a/5/2/c/2a52cf157245687258079bb23c6223745d95e163-image3x.png 1200w, /grav-develop/images/e/9/f/1/3/e9f1303f0ca4f3f35d90bb08bd4c43cd11b8aefd-image2x.png 800w, /grav-develop/images/2/3/6/7/7/2367706e56f8dce23de92170318e212d8a219a0f-image1x.png 400w" sizes="100vw">

@nineteeneightyeight
Copy link
Author

I select the file using a pagemediaselect.

Sorry, when I said markdown I meant within the Frontmatter.

The image is output in the template as follows:

{% set header_image = page.header.header_image|defined(true) %}
{% set header_image_width  = page.header.header_image_width|defined(540) %}
{% set header_image_height = page.header.header_image_height|defined(480) %}
{% set header_image_file = page.header.header_image_file %}

{% if header_image %}
    {% if header_image_file %}
        {% set header_image_media = page.media.images[header_image_file] %}
     {% else %}
         {% set header_image_media = page.media.images|first %}
     {% endif %}

     {{ header_image_media.cropZoom(header_image_width, header_image_height).html }}
{% endif %}

@flaviocopes
Copy link
Contributor

pagemediaselect since the latest release is now an alias for filepicker and this might have caused your issue, as it uses raw files instead of page media.

I think this change getgrav/grav-plugin-admin@a42fd33 is going to fix your issue. You can try it now by downloading the latest develop branch of Admin from https://github.com/getgrav/grav-plugin-admin/archive/develop.zip

@nineteeneightyeight
Copy link
Author

nineteeneightyeight commented Oct 27, 2016

As far as being able to select the image from the dropdown - that seems to be fixed by using the admin plugin fix you mentioned. However, the main issue is still there. I'm still getting an error message from Grav Core (I believe) on the frontend of the site, when using these images.

I assume it's something to do with the automatic generation of these responsive images.

@flaviocopes
Copy link
Contributor

I've not been able to recreate it yet, I wonder if it's a Grav issue or rather a GD library issue http://stackoverflow.com/questions/20614686/gd-warning-product-of-memory-allocation-multiplication-would-exceed-int-max

@rhukster
Copy link
Member

How big is your image? Can you attach it here so I can test with it?

@thedistricts
Copy link

@rhukster test-3ximage.zip

@flaviocopes
Copy link
Contributor

Thanks, I tried but I can't replicate any error when using the images locally.

@thedistricts
Copy link

Is that replicating uploading the image on v1.0.10 and then upgrading Grav v1.1.8?

@fredrikekelund
Copy link
Contributor

This was introduced due to my changes in #1107. Sorry about that! Submitted a PR that should fix the problem

@fredrikekelund
Copy link
Contributor

Just a note on this one – this bug would basically affect any case where users try to use image alternatives (either as supplied from disk, or generated by ImageMedium#derivatives) in combination with image filters. So perhaps it would be good to do push a minor release to fix this

@fredrikekelund
Copy link
Contributor

@flaviocopes @rhukster sorry about troubling you with this, but I think the change change might warrant a bugfix release – see my previous comment for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants