[4.0] Proposal for image scaling in template and layout files #27158
Replies: 18 comments
-
(dam I use that site several times a week and I never realised it was Joomla - well done) |
Beta Was this translation helpful? Give feedback.
-
(Haha! Well, that cheered me up today!) |
Beta Was this translation helpful? Give feedback.
-
How does it work with article images? |
Beta Was this translation helpful? Give feedback.
-
It doesn't at present work with images in article text, although it works with intro and full-text images. To make it work with images in article text it needs a content plugin, to search for image tags and create the src links via the data model. A benefit of this is that the plugin could process the image according to the width and height specified in the WYSIWYG editor, to produce an optimised image. We use the scaler component to create responsive images for different DPIs, which could be an additional feature for a plugin. |
Beta Was this translation helpful? Give feedback.
-
That is actually what I meant ;) I can't speak for anyone else but it does sound like a good addition for Joomla 4 to me. Maybe the quickest thing to do to gauge opinion would be to make a small video recording of it in action in the admin? |
Beta Was this translation helpful? Give feedback.
-
sounds good to me too, at least on the paper, looking forward to see at some RFC/POC/PR |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
This would have to be able to be turned off and I would like to know a LOT more about the technology doing the cropping/resizing. For some sites and some people touching an image in anyway is a quick way to lose a J! user. |
Beta Was this translation helpful? Give feedback.
-
Yes, definitely it needs to be able to be turned off. Currently on our projects we include it where we need it, however if it's included in Joomla then the component should have an "off" option which simply returns back the original image url, rather than a url for a processed image. If there is a content plugin as well, to handle in-text images, then that could be turned off separately if required. We've done a large-scale professional photography site before and this isn't the technique we use for generating images for that. This is a usability enhancement to ensure that images fit with the design, which we find is a habitual problem which users struggle with. The code we use is very simple and no doubt there's room for improvement. In the model, once the query is validated, we do a scaled centered crop using ImageMagick.
The way you build responsive images using this is that you request multiple images in the template code, each one being a separate request. So, you are fully in control of how you map onto screen resolution, screen size or a bit of both. |
Beta Was this translation helpful? Give feedback.
-
Wow nice!!! We typically use a thing like this... https://gist.github.com/simbus82/3eb70128691ab93a6fd420ed6592e99f I like a lot the Magento 1.9.x Image Processing. |
Beta Was this translation helpful? Give feedback.
-
Hi @simbus82 , |
Beta Was this translation helpful? Give feedback.
-
imagemagick has a great algorithm, although I've heard there are a couple of better ones but they were far above my brain cell capacity lol. |
Beta Was this translation helpful? Give feedback.
-
@waveywhite please submit PR for consideration/testing. |
Beta Was this translation helpful? Give feedback.
-
Yes. Sorry for the delay. I'll get on to this. |
Beta Was this translation helpful? Give feedback.
-
Modified title as this would have to be done for 4.0 (new feature). |
Beta Was this translation helpful? Give feedback.
-
I've uploaded the code to https://github.com/waveywhite/com_scaler - is someone able to take it from there? I'm unsure of the proper way to integrate it as a Joomla 4 PR. A few issues with the code:
|
Beta Was this translation helpful? Give feedback.
-
Hi all. I'm looking at moving over to the Joomla 4 MVC for com_scaler. Is there a good example of best practice for a J4 MVC component? Or are we doing things like com_content does? |
Beta Was this translation helpful? Give feedback.
-
I've found https://github.com/ceford/j4xdemos-com-mywalks so I'll base my changes on that. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Something we have developed for our Joomla sites is the means to render scaled and cropped images on the front-end, without opening up a can of worms. Is this something the Joomla team would be interested in?
In brief, on sites such as https://www.northernrailway.co.uk/ we have a component which renders images via URLs such as https://www.northernrailway.co.uk/img/2568/360/260/Tickets-to-mobile_Promo-Box_720x520_V2.jpg, which we then distribute via CDN.
The URL path elements are
<menu>/<id>/<width>/<height>/filename
The way we avoid abuse by constructing URLs which force the server to render arbitrary images, is that images are requested in the template like so:
We store the image request in the database and render out a routed path. When the browser requests the image, the router uses the request id to find the image, renders it to specification and return it. We do an optimised scale-and-crop on images and use the Joomla caching layer.
Image requests to constructed URLs don't work. The image size on the path is compared with the database details and a 404 is returned if it doesn't match.
We find it's a massive help with usability because users don't have to worry about the absolute dimensions of images, they just need to worry about aspect ratio.
Please let me know if this would be a helpful contribution to Joomla.
-David.
Beta Was this translation helpful? Give feedback.
All reactions