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:
require_once` JPATH_BASE . '/components/com_scaler/models/image.php';
$scaler = new ScalerModelImage();
$image = $scaler-request($imagePath, $width, $height);
?>
<img src="<?=$image?> />
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.
Labels |
Added:
?
|
(Haha! Well, that cheered me up today!)
How does it work with article images?
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.
It doesn't at present work with images in article text, although it works with intro and full-text images.
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?
sounds good to me too, at least on the paper, looking forward to see at some RFC/POC/PR
There's very little to show in the admin, so I'm not sure how much value a video would be. Here's the extent of the admin section.
Options. You may want to handle the existing options differently as the CDN and live domain options are just there to help us with how we arrange things, and it would help to have a default JPEG quality option.
A menu item. This is the SEF end-point for rendered images
And that's it!
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.
For example, only product photography site I would blow a gasket if J! decided I didn't know what I wanted my images to look like.
Unless your developers are EXTREMELY familiar with how images are built internally I doubt they could do anything to my image(s) that wouldn't degrade them. Not bragging, ijs, I've got pro grade tools I run them thru before they ever land in my storage folders.
To the best of my knowledge there is no perfect responsive image handler YET.
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.
$imagick = new Imagick(JPATH_ROOT . '/' . $path);
$imagick->cropthumbnailimage($width, $height);
$format = $imagick->getimageformat();
if ($format == 'JPEG' || $format == 'JPG') {
$imagick->setimagecompressionquality($this->params->get('jpeg_quality', 70));
$imagick->stripimage();
}
$data->img = $imagick->getImageBlob();
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.
Wow nice!!!
We typically use a thing like this... https://gist.github.com/simbus82/3eb70128691ab93a6fd420ed6592e99f
but it is really "rude" (it's an old version, the actual used for some our customers generates scrset too.)
Really slow on the first load of page... but then it's good ;-)
I like a lot the Magento 1.9.x Image Processing.
In the frontend you simply call a function "$this->image(original_url)->resize(300,200)" to have a perfect cached resized image without losing the original.
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.
that magento behavior looks exactly like imagemagick's process.
@simbus82 your method sounds alot like retina behavior. I wonder what sites like smugmug use for their compression.
Labels |
Added:
Information Required
|
@waveywhite please submit PR for consideration/testing.
Labels |
Added:
?
|
Yes. Sorry for the delay. I'll get on to this.
Title |
|
Modified title as this would have to be done for 4.0 (new feature).
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:
Labels |
Removed:
Information Required
|
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?
I've found https://github.com/ceford/j4xdemos-com-mywalks so I'll base my changes on that.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-12-18 10:29:44 |
Closed_By | ⇒ | rdeutz |
(dam I use that site several times a week and I never realised it was Joomla - well done)