core icon indicating copy to clipboard operation
core copied to clipboard

Image field getValue always returns thumbnails as 400x400 with no cropping/fitting

Open andysh-uk opened this issue 2 years ago • 2 comments

In the code below, an image field will always return a "thumbnail" property as the URL to a thumbnail sized at 400x400 with no cropping/fitting, so the thumbnail will be stretched to fit 400x400.

https://github.com/bolt/core/blob/161ca2f05e25f104b07f97e4c1451fbc4ba1a69e/src/Entity/Field/ImageField.php#L67

As this is a field-level property, I feel this could be configurable on a per-field level to allow a field on one content type to return a thumbnail that is a different size to another content type.

andysh-uk avatar Apr 12 '22 10:04 andysh-uk

I have a working proof of concept for this on my dev site, I'll create a PR.

andysh-uk avatar Apr 12 '22 10:04 andysh-uk

To illustrate this, in the Bolt Git clone website, insert the following line in public/theme/skeleton/record.twig:

{{ dump(record.photo.value) }}

Then view the /page/this-is-a-page page.

Underneath the heading, you will see:

image

My PR will allow this to be controlled via a "thumbnails" configuration within the content type definition:

pages:
    name: Pages
    singular_name: Page
    title_format: '{heading} - {subheading}'
    excerpt_format: '📦 {teaser}'
    fields:
        photo:
            type: image
            label: "Eén plaatje"
            placeholder: https://source.unsplash.com/1280x768/?business,workplace/__random__
.... new config below ....
            thumbnails:
                size: [100,100]
                cropping: crop

With my change - and the above config - in place, you'll now get:

image

Without the above config in place (but with my change in place), you will still get the previous behaviour of 400x400 with no cropping/fitting.

andysh-uk avatar Apr 12 '22 11:04 andysh-uk