ElkArte Community

Elk Development => Feature Discussion => Topic started by: radu81 on October 18, 2021, 04:09:40 pm

Title: Support for webp images
Post by: radu81 on October 18, 2021, 04:09:40 pm
https://developers.google.com/speed/webp
I did a test by enabling webp extension in Attachment Settings, the attachment is uploaded, but is displayed as full width inside a post, not as a thumbnail. I attach a screenshot
(Link-7103)

What do you think about supporting this format in Elkarte? As far as I can see, it was recently added as in wordpress (https://make.wordpress.org/core/2021/06/07/wordpress-5-8-adds-webp-support/), and I start to see more and more websites using this format for images.
Title: Re: Support for webp images
Post by: Arantor on October 19, 2021, 06:29:17 am
The main drama with WebP is that it only got added to GD (the graphics library in PHP) relatively recently and I don’t know how up to date hosts are on the subject.
Title: Re: Support for webp images
Post by: radu81 on October 19, 2021, 10:52:24 am
to avoid this, the webp extension should be disabled from default.
In ACP > Forum > Attachments settings > Allowed attachment extensions > ? :
(Link-7105)
we can change:
QuoteSpecify what attachment types are allowed, for example: jpg,png,gif Remember to be careful in what you allow as some file extensions can cause a security risk to your website.
to something like:
QuoteSpecify what attachment types are allowed, for example: jpg,png,gif Remember to be careful in what you allow as some file extensions can cause a security risk to your website. For webp file extension GD library is required....
Title: Re: Support for webp images
Post by: Spuds on October 25, 2021, 10:21:07 am
I have a foggy memory of looking at this a one point.  I guess the short of it is, yeah it probably should be supported at some point.  I'll add a task on git so we remember.
Title: Re: Support for webp images
Post by: Spuds on February 12, 2022, 02:30:11 pm
Finally looking at this and here is what I'm thinking (and actually have) doing

1) Added a check in the ACP for if you have WebP capability either in GD or Imagick.  This will trigger if you add webp as one of the allowed file types. 
2) With a WebP enabled server, when you upload a WebP image and it will create the thumbnail just like any other image

I'm going to drop the ACP option of "Save thumbnails as PNG" and update the thumbnail functionality as follows:

1) If you have WebP enabled, all thumbnails will be saved as WebP images.  The WebP thumbnail images are smaller in size than JPG or PNG and retain alpha/transparency.  For the thumbs I am only using lossy compression, unlike the old "PNG only thumbs" which by definition were lossless.  The reality is they look just as good but it will saves some space/bandwidth, and its a thumbnail.
2) If you do not have WebP, and the uploaded image is a PNG with some alpha/transparency, then it will create the thumbnail as PNG
3) All others to JPG

Still to do:
1) Avatars
2) How I want integrate WebP options into Image Attachment Resizing (now built into 2.0)
Title: Re: Support for webp images
Post by: Spuds on February 15, 2022, 03:06:50 pm
And a test
Title: Re: Support for webp images
Post by: Mrs. Chaos on February 15, 2022, 04:01:35 pm

This already looks very promising!  :)
Title: Re: Support for webp images
Post by: badmonkey on February 15, 2022, 04:47:52 pm
I don't know why, but entering this thread made the menu icons go blank on an Android mobile.
Title: Re: Support for webp images
Post by: Spuds on February 15, 2022, 05:47:10 pm
Could you flush your cache and see if that helps, there were changes in the css
Title: Re: Support for webp images
Post by: badmonkey on February 15, 2022, 07:35:50 pm
Quote from: Spuds – Could you flush your cache and see if that helps, there were changes in the css
That finally worked after the third time. Emptying the Chrome cache doesn't empty the Chrome cache. Apparently you have to threaten it's family. ;D
Title: Re: Support for webp images
Post by: Spuds on February 15, 2022, 10:14:28 pm
I've notice that mobile devices hold the cache at all costs !! :cool: that you got it cleared :smile:
Title: Re: Support for webp images
Post by: radu81 on February 16, 2022, 02:39:45 am
Let's brake this thing with some tests: :D
Title: Re: Support for webp images
Post by: radu81 on February 16, 2022, 02:42:37 am
and some inline webp images:

Thumbnail:
(Link-9921)

300px width:
(Link-9921)

Full size:
(Link-9921)

Thumbnail center:
(Link-9921)

Full size right:
(Link-9921)


Quote from: radu81 – Let's brake this thing with some tests: :D
It seems that I wasn't able to do it
Title: Re: Support for webp images
Post by: radu81 on February 16, 2022, 02:55:53 am
In the end I was able to break something, have a look at the latest image  ;D
Title: Re: Support for webp images
Post by: Spuds on February 16, 2022, 10:00:35 am
Ah cool, breakage :smile:  I don't think that is specific to webp but an ILA float issue.  Should be an easy :head_bandage:
Title: Re: Support for webp images
Post by: Antechinus on February 16, 2022, 06:49:21 pm
It's happening because the .quoteheader is a div, which is block level display by default. It would need a right margin to stop it overlapping the floated image.

Best solution is probably to rewrite the markup for quotes, so that the quoteheader stuffz goes inside the blockquote (cite tag, or whatever else works).
Title: Re: Support for webp images
Post by: Spuds on February 16, 2022, 08:56:00 pm
I wonder if a display: flex; on the quote header would do the trick since a float should not intrude into a flex area?   If not probably will have to change the way that markup is done, but can be more involved I fear.

I added this to the tracker so its not forgotten :D

Title: Re: Support for webp images
Post by: Antechinus on February 16, 2022, 09:21:25 pm
Just tried flex in dev tools. Seems to work, at least with the example post. Might be worth trying a few other examples with different quoteheader content.

Although really the markup change would be sensible anyway, just from the point of markup and CSS. The dark side have gone with a cite tag inside the blockquote for 2.1, which is nice and simple. Offhand I can't recall how Subs (or whatever you use now) handles quote markup in Elk, but from memory it wasn't too gnarly.

If you want to change it I'd be happy to tackle that. If not, flex on the existing will probably be ok.
Title: Re: Support for webp images
Post by: Spuds on February 16, 2022, 10:46:42 pm
If you want to tackle it, that would be great!

I don't think you will find anything in Subs.php, its all going to be in the BBC parser which is its own thing now.  Doing a quick search it looks to be in the alternateQuoteStyle() method down in /sources/ElkArte/BBC/BBCParser.php 

When you go there you will note that is where I did some juggling to test out what would be required fort those CSS only expandable quotes, I needed PHP to set the markup due to the number of conditions.

ETA::

There is also some juggling in handleCollapsedQuotes() which if I recall was for the nested quote problems.

And lasty the intial BBC codes are set up in Codes.php found in sources/ElkArte/BBC/Codes.php ... This is the standard bbc to markup definition that will look somewhat familiar, its just that quotes being a PITA need lots of other processing, at least for the nested stuff, which is where I choose to intercept things for the collapsed quotes.

Hope that makes some sense at least when you go looking ... Codes -> basic markup -> alternateQuoteStyle() -> advanced markup based on conditions -> handleCollapsedQuotes() for additional issues due to nesting.