Save images in multple sizes for responsive?
Hi Support Team,
I would like to ask if Twill can store the images in multiple size for desktop, mobile?
And what is the purpose of the Mobile crop?
11 Replies
Hi @Huy Tớn Yes you can define whatever crops you want for an image. I generally use this where we want to use the same image for Desktop or Mobile but don't want to load the larger image on smaller screen sizes.
Crops can be defined in the Model
Then it's up to you how you want to render or make use of this in your frontend.
This is a good article on options for responsive images - https://css-tricks.com/a-guide-to-the-responsive-images-syntax-in-html/
Chris Coyier
CSS-Tricks
A Guide to the Responsive Images Syntax in HTML | CSS-Tricks
This guide is about the HTML syntax for responsive images (and a little bit of CSS for good measure). We'll go over srcset and , plus a whole bunch of things to consider to help you get the best performance and design control from your images.
You can also check out the Twill Image package (https://github.com/area17/twill-image) for art-directed images
GitHub
GitHub - area17/twill-image: Twill Image is a package designed to w...
Twill Image is a package designed to work with Twill. It leverages Twill image processing with modern lazy-loading techniques and art-directed responsive images. - area17/twill-image
ok thanks @pauldwight
I will have a look
Hi @pauldwight
Can we have multiple sizes of images that be uploaded for devices
For example, we upload 1 image with 1920x1080px, 3 images will be stored for 3 devices: desktop (1920x1080px), tablet (768x480px), mobile (320x480px)
I have added the config to the model
And tried to save it in the admin
But it does not save a separate cropped image
It just stores the 2 dimensions (desktop and mobile) with the same original image ID 699
The crops are generated when it is requested rather than on upload
Can I know the requested mean, when I hit "Update", and save the page, there is no cropped image will be created 😅
Sorry - there is 1 image uploaded, the original, the defined crops will then be saved in the db table (as you can see). Your frontend then requests the crop you want e.g. This image url contains the crop details and gets passed to the Image Rendering Service - default will be Glide and returns the cropped image
When I tried $homepage->image('opening_banner', 'mobile'), it returned the original image URL, is that correct?
How we can get a cropped image URL instead? With Image Rendering Service - Glide?
The returned url should include params. e.g. http://domaintest/img/uuid-for-image/image-file-name.jpg?fm=jpg&q=80&fit=max&crop=500%2C500%2C0%2C0
Glide is just an on-demand image manipulation library. It has requirements like GD library
Crops defined on your Model will be used, but in the aspect ratio.
If you really want a custom w and h, you can do something like this
thank you so much