Change destination folder
-
Hello,
how can I change the destination folder of the new images? I would like save my image into the same folder of the original image.
Thank you for support and for you plugin!
D.
-
Currently, there is no configuration option for that. I am however considering such an option. You are not the first who would like the converted images to be stored in the same folder as the original images.
There is one caveat by storing in same folder though: There might be permission problems for images that don’t reside in the upload folder – ie. theme images. I’m considering how to handle that situation. One way could be to fall back at the current location for such images.
If you cannot wait for the feature to be implemented, you can manually edit wod/webp-on-demand.php. In the line before the last line, insert this:
$destination = $source . '.webp';
Thank you for your reply.
I would have another request: I would like remove the extension of original file from the filename of new file.
I ask to you this info because I am using another plugin that manage and <picture> tags on the front-end base on user device. But for this plugin works it is necessary that the folder and the filename would be the same.
Thanks!
But with this plugin, there is really no need for pointing to webp version with a <picture> tag, as it takes take of serving the webp version to browsers that supports it.
But perhaps there is some benefit of pointing to webp version directly in the HTML, which I am not aware of?
It is explained here: https://css-tricks.com/using-webp-images/
In my point – base on the lecture about the Webp – it seams better manage also the front-end.
Maybe you consider to add this feature in the future.
PS: Can you help me about the previous question? ??
- This reply was modified 5 years, 12 months ago by damianocongedo.
The article doesn’t really provide any reasons for managing it front end rather than server side.
This article here however shows how using the picture tag can become unmanageable, when wanting to take more than just webp into account: https://developers.google.com/web/updates/2015/09/automating-resource-selection-with-client-hints. And it shows how all this trouble goes away by letting the server do the task of image selection.
That said, I can however find one reason to use picture tag: It will not bring confusion to those who wants to download the image. With WebP Express, a user who downloads a jpg image in chromium will get a webp image – but the filename will have the jpg extension. So the user have a file with wrong file extension. Not ideal. And that thing will not happen with the <picture> tag.
I shall return with code in a moment…
To have webp express save the converted files in the same directory, with ‘webp’ extension *instead* of original extension, edit wod/webp-on-demand.php. In the line before the last line, insert this:
$destination = preg_replace('/\.(jpg|jpeg|png)$/', '.webp', $source);
Be aware that the conversion takes place when the jpeg is first requested. Until that, there will be no webp. So make sure that you request the jpeg at least once in your workflow.
To avoid missing webp’s, you could create a rewrite rule which triggers when a webp is requested, but not found. When that happens, the server could look if there is a jpeg file in that directory, which matches the filename (besides the extension). If so – it could convert the jpeg to webp right away.
I actually created a small php/.htaccess project for this very thing: https://github.com/rosell-dk/webp-realizer. Note that it is not a WordPress plugin and that I departed from the project, as I found the other way round to be more usable.
Oh yeah, the readme of webp-realized reminded me that the “frontend” approach also has the benefit that it requires no special setup of CDN’s
Btw: Which plugin is it that you are using for generating the picture tags?
Hi rosell,
thank you for the support and information.
The plugin is ShortPixel, it was developed for compression images but also has a feature for conversion to .webp and insert <picture> tag.
I am using it only for the <picture> tag.
It could be a great idea adding to your plugin this feature, in this case we could use just one plugin ??
D.
Sorry, but I don’t think I shall add the ability to generate <picture> tags to the plugin. Not in near future anyway, as I rather want to focus on core functionality. But I think I shall implement custom destination folder. There are however other things on the roadmap that takes priority.
Btw: I assume you are aware that the hacks I gave you here will have to be reimplemented when you update WebP Express
Yes, I know. So good, thank for you effort. I will wait for new plugin version!
Hi,
Just released 0.8.0. But the feature you requested is not part of 0.8.0. But I think I will add it in 0.9.0. I have created an issue for it on github: https://github.com/rosell-dk/webp-express/issues/104
- The topic ‘Change destination folder’ is closed to new replies.