Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-02-15 00:08:54

Myusername
Member
Registered: 2019-12-12
Posts: 165

Convert images to .webp

I want to convert images to .webp format at the moment I upload them in the image panel. Is there any plugin that does this or something similar?

Offline

#2 2024-02-16 02:37:40

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,093
Website GitHub Mastodon Twitter

Re: Convert images to .webp

Myusername wrote #336664:

I want to convert images to .webp format at the moment I upload them in the image panel. Is there any plugin that does this or something similar?

Just a heads up that older macs do not support the webp format and images appear broken in the browser windows.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2024-02-16 06:59:26

Myusername
Member
Registered: 2019-12-12
Posts: 165

Re: Convert images to .webp

Yes, I am aware of that. That’s why I like to use images in jpg and copies in webp. There are many ways to work around this in the frontend. However, I can’t find a satisfactory way to do this in Textpattern. I don’t know if there’s any hook that I can intercept at the moment of the image uploads to create copies in .webp or something like that. I was hopeful that there would be, but, well, I guess I’ll have to forget about it, as I don’t have much time to delve deeper.

Offline

#4 2024-02-16 08:53:46

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,225
Website

Re: Convert images to .webp

As far as I can tell, there are no hooks currently, and I don’t a plugin exists that can extend Textpattern in some way to do this.

What I do is prepare the images locally (jpg + webp + sometimes avif), upload the jpg and then FTP the other formats. I then have a custom field on the edit image panel to “link” them and a TXP shortcode to build the output block(figure and picture inside). It is a little cumbersome… and I most often limit myself to jpg’s which more often than not sufficient.

Who knows though, in the future the option might exist, the image branch has some option, I think. But that is _future_…


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#5 2024-02-16 09:04:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,468
Website GitHub

Re: Convert images to .webp

Myusername wrote #336669:

I don’t know if there’s any hook that I can intercept at the moment of the image uploads to create copies in .webp

There are Images panel hooks available. My smd_thumbnail plugin, for one, uses them to manage multiple copies of images.

However, as phiw13 notes, Textpattern isn’t yet geared up to allow multiple copies of the same image ID with different extensions. If you roll your own, you’ll have to manually construct things using the various <txp:image*> tags to build the components and tack on the extension by hand. It’s stored in the database and there’s only one per image, sadly. This needs a rethink as we move forward – perhaps by querying and stashing the mime type per image when they are (auto-)generated at the required dimensions.

Last edited by Bloke (2024-02-16 09:12:21)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#6 2024-02-16 09:06:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,743
Website

Re: Convert images to .webp

I would have thought the image_uploaded callback would be the hook you need (here in the source). You could then convert to web via PHP (this perhaps) or with a corresponding library on your server.

Keep us posted if you get something nice working.

There’s also a little quick’n‘dirty htaccess snippet that will use a webp if a file is on the server alongside the jpg. See here.

EDIT: Bloke was faster again :-) but maybe the htaccess tip helps as there’s nothing to change in Textpattern.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2024-02-16 09:19:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,468
Website GitHub

Re: Convert images to .webp

jakob wrote #336675:

maybe the htaccess tip helps as there’s nothing to change in Textpattern.

That is indeed a good workaround for now. I like that idea, albeit loading the web server with work, which means we’d need to maintain Nginx and others somehow.

I’d still prefer a core solution one day. One day…


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#8 2024-02-16 23:13:05

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Re: Convert images to .webp

I wrote this Textpattern plugin for creating those .webp versions. The plugin adds a new 💾 WebP link in the Edit image page.

Offline

#9 2024-02-16 23:30:21

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,094
Website Mastodon

Re: Convert images to .webp

kuopassa wrote #336686:

I wrote this Textpattern plugin for creating those .webp versions. The plugin adds a new 💾 WebP link in the Edit image page.

Thank-you, this looks promising. I installed it but I am unable to edit any images. I notice that the plugin is installed as: kuo_webp_v0.1 copy and I am listed as the author. there doesn’t seem to be any help doc.


…. texted postive

Offline

#10 2024-02-17 01:13:26

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Re: Convert images to .webp

^ bici, this is the code that came out from ied_plugin_composer. I don’t know how to use other compiling methods…

Offline

#11 2024-02-17 01:46:18

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,225
Website

Re: Convert images to .webp

kuopassa wrote #336688:

^ bici, this is the code that came out from ied_plugin_composer. I don’t know how to use other compiling methods…

ied_plugin_composer is, afaik, brøken in more recent of Textpattern & PHP. The good old route of using the plugin template and compiling at the command line still works fine (documentation). Bloke or Jakob might point to other methods. Textpattern 4.9-dev also has a full-fledge plugin editor build-in.

PS – based on your screengrab only, might it not be better inserting your widget after the main image – and just before the thumbnail generating area?


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#12 2024-02-17 01:57:00

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,225
Website

Re: Convert images to .webp

jakob wrote #336675:

There’s also a little quick’n‘dirty htaccess snippet that will use a webp if a file is on the server alongside the jpg. See here.

Interesting… If I understand it correctly, this checks (1) if the browser supports .webp, then (2) checks if there is an image in that format for with the same name as the requested .jpg and then (3) replace the latter with the former. Hmm, is it not a little wasteful? the action would happen on every image request…

I think I prefer my method of using a custom field on the edit images panel to establish a link between the various image formats and a little shortcode to insert the images with the required code. No additional server lookups, the whole “thing” is known upfront. (the result could eventually be cached with etc_cache ??)


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

Board footer

Powered by FluxBB