Jump to content
jacmaes

Webp support

Recommended Posts

I just downloaded the newest dev version and upgraded my website, but image fields does not support WebP. I replaced wire folder, index.php and .htaccess.
Invalid image (in /wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 821)

Apache2 / PHP7.0 has GD and ImageMagick enabled.

Share this post


Link to post
Share on other sites
1 hour ago, anttila said:

but image fields does not support WebP. I replaced wire folder, index.php and .htaccess.
Invalid image (in /wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 821)

Do you mean you tried to upload a WebP image to an Images field? If so that's not supported - the blog post explains that WebP is an output format only:

Quote

WEBP is an output format

WEBP images are fundamentally different from other image formats you have used in ProcessWire. WEBP is purely an output format, not an input format. That’s because you still need a fallback JPG or PNG for any WEBP image that you serve, as not all browsers will be able to consume the WEBP images.

In addition, WEBP images have a type of compression that makes them unsuitable for any further manipulation or transformation, so PNG and/or JPG images should still be the standard for any images you upload to your site. All the WEBP images delivered by ProcessWire are automatically generated from source PNG or JPG images.

 

  • Like 1

Share this post


Link to post
Share on other sites

I have WebP support enabled in GD (PHP 7.3), but

$image_field->webp->url

still returns a JPEG file. Anything I'm missing? Is there something to add in the config.php file?

gd.png

Share this post


Link to post
Share on other sites
Just now, jacmaes said:

still returns a JPEG file

Did it create the WEBP version? Maybe the JPG was smaller so it served that up instead. In my limited experience, it's quite common that the webp version is actually larger :)

Share this post


Link to post
Share on other sites

@adrian That's what I first thought too, but no, it's not generated in the corresponding "files" folder. Digging a bit further, it looks like it does not work with @horst's CroppableImage 3 Module, at least in the way I expected it should. So:

$page->image->first->getCrop('landscape')->webp->url;

does NOT work. But:

$page->image->first->webp->url;

does generate a Webp variant correctly.

Share this post


Link to post
Share on other sites

Hello @horst,

first of all thank you for all your efforts to bring WebP support to ProcessWire. 🙂

I have installed ProcessWire 3.0.132 and implemented this code to almost every image:

<?php $image = $image->size(1600, 900); ?>
<picture>
    <source srcset="<?=$image->webp->url?>" type="image/webp">
    <img src="<?=$image->url?>"
         width="<?=$image->width?>"
         height="<?=$image->height?>"
         alt="<?=$image->description?>">
</picture>

Of course with more variations. This is just an example code.

My issue is, that my local MAMP server doesn't support WebP and my webhosting does support it. On the webhoster the WebP variations get generated and everything is fine. But on my local MAMP server, ProcessWire can't generate the WebP variations and tries to generate them on every page load, which leads to a server timeout.

I saw a condition $image->hasWebp in your early drafts. Can I use this for environments that don't support or should ProcessWire better not try to generate WebP variations at all, if there is no WebP support? 😉

Regards, Andreas

Share this post


Link to post
Share on other sites
44 minutes ago, AndZyk said:

My issue is, that my local MAMP server doesn't support WebP and my webhosting does support it.

Have you tried following these instructions to add WebP support to MAMP?

Share this post


Link to post
Share on other sites

I have tried, but don't have pecl installed on my macOS High Sierra and don't know how to install it. I have tried to install pear, but have not managed yet to get it running.

I have contacted the MAMP support and they will consider enabling WebP in a future update. 😉

Share this post


Link to post
Share on other sites

With some help and the instructions I have now managed to install a newer version of Imagick for MAMP and now the WebP support is also working local for me fine.

But is it possible to detect on the server side if WebP is supported so it doesn't try to generate WebP variations on every page load on environments with no WebP support? It think this would be a good addition. 🙂

Share this post


Link to post
Share on other sites

The image rendering engines have gotten a method / check if and which supports webp creation. I think you best drop an issue at pw github, so that ryan gets knowledge about it. 

If I find time I try to check this too. 

  • Like 2

Share this post


Link to post
Share on other sites

Hi,

I have a strange problem as below:
 

Linux box
Chrome always serves jpg files instead of webp files but Firefox does serves the webp files.

Mac Bookpro
Both Chrome and FireFox serve jpg files only.

Any clues??

Gideon

P.S. Solved. Seems like it is a browser cache problem.

Share this post


Link to post
Share on other sites
Posted (edited)

I understand thats it's crucial to save bandwith. That's why we have webP now, finally.

But there is one line in PagefileExtra.php that delivers the normal image url instead of the webp version, if the webp filesize is larger.

In my case and I think on other sites too this is an unwanted behaviour, as quality and colors are different if you compare a jpg and a webp image.

To illustrate this I attached this image, where you can see that the first three products which are being delivered as JPGs because the filesize is smaller are really different looking than the next 3 which are in webp format , especially in the logo area. This is somewhat hard to see here, but on my development site it looks really bad and is a showstopper for me to use webp.

What I ask for is an option to skip the filesize check and maybe the option to enter a treshold value when to use the smaller image.

I created a github issue "make the fallback optional if pagefile->url is smaller than webp"

EDIT: This is already possible if you use  following code:

//_init.php
// output webp version for all $image->url() calls, skip SVG's
if($page->template != 'admin') {
  $wire->addHookAfter('Pageimage::url', function($event) {
    static $n = 0;

    if(++$n === 1) {
      if (strstr($event->object->filename, '.svg') === false){
        $event->return = $event->object->webp()->url(false);
      }
    }
    $n--;
  });
}

chrome_2019-06-12_10-36-09.thumb.png.a4b82c4cb239290161640c47f0b3e418.png

 

Edited by jens.martsch
Solved
  • Like 4

Share this post


Link to post
Share on other sites

What about PNG images with transparency? The transparent areas are appearing as black in the webp images. Any special settings for those?

  • Like 2

Share this post


Link to post
Share on other sites
On 9/27/2019 at 3:31 PM, kalimati said:

What about PNG images with transparency? The transparent areas are appearing as black in the webp images. Any special settings for those?

I've had this problem for quite some time, even without WebP. Somewhere I think there is a bug in the ImageSizers. This happens with compressed PNGs, which were previously compressed via tinypng.com, for example.

Share this post


Link to post
Share on other sites
1 hour ago, David Karich said:

I've had this problem for quite some time, even without WebP. Somewhere I think there is a bug in the ImageSizers. This happens with compressed PNGs, which were previously compressed via tinypng.com, for example.

@David Karich & @kalimati Which PW version(s) do show this behave? AND: which ImageSizerEngine(s) have you enabled there? (GD | IMagick)

We had a change in what image types are supported by IMagick and need to revert back some sorts of PNGs, especially 8bit PNGs are not correct supported by IMagick, and in very rare cases there also was wrong handling for some 8bit-PNGs in GD-Engine.

Maybe you can provide the informations plus one or two of the (original uploaded) images in a ZIP to me?

  • Like 1

Share this post


Link to post
Share on other sites

It may have something to do with the graphics conversion engine installed. I corrected the problem on my local server by installing ImageMagick.

Share this post


Link to post
Share on other sites
On 10/2/2019 at 1:03 PM, horst said:

@David Karich & @kalimati Which PW version(s) do show this behave? AND: which ImageSizerEngine(s) have you enabled there? (GD | IMagick)

We had a change in what image types are supported by IMagick and need to revert back some sorts of PNGs, especially 8bit PNGs are not correct supported by IMagick, and in very rare cases there also was wrong handling for some 8bit-PNGs in GD-Engine.

Maybe you can provide the informations plus one or two of the (original uploaded) images in a ZIP to me?

This one is converted to webp with black background by GD on my localhost. I tried another one it behaves the same way. Is there any requirements on GD version or php?

Share this post


Link to post
Share on other sites

What about a scenario when client upload a webp image (.webp renamed to .jpg)?
I just had that case with one of my clients on pw 3.0.123. With processwire 3.0.123 I am able to edit and view the page with uploaded webp image. Only drawback: no thumbnails are generated.

Now, reproducing that scenario with pw 3.0.141, whenever I try to edit or view a page containing uploaded webp image, I'm getting 500 internal server error.
Tracy says: ProcessWire\WireException webmimage-9.0x260.jpg - not a supported image type
Source file: File: .../dev/wire/core/ImageSizerEngine.php:574

574:                throw new WireException(basename($filename) . " - not a supported image type");

Its the same error with either GD (2.1.0 compatible) or ImageMagic (6.9.4-10 Q16 x86_64 2017-05-23).
PHP version: 7.2.22

------

@Ivan Gretsky, I was able to convert your image to webp with GD and ImageMagic (libraries, php and pw version same as above).

webp.png.ec35444d3e2d6cfba86e05257975f0cf.png

(blue background is from a css style)

  • Like 2

Share this post


Link to post
Share on other sites

Thanks, @johndoe!

The conversion did not work on my local xampp with some php 5.6, but did work on a live server. I can guess some requirements are not met on localhost. It would be nice to know those requirements, bit for now I know that I should try to keep the server environment as fresh as possible (which is a good thing anyway)))

Share this post


Link to post
Share on other sites

Is it just me who don't understand the percentage for the webp generated variation? Original is 311k, webp is 62k, how do I get 80% ? That means webp is 80% smaller than original? And if webp is bigger than original, I get (webp -20%). And while here, how do I delete webp variation?

Screenshot.png

Share this post


Link to post
Share on other sites
13 hours ago, matjazp said:

That means webp is 80% smaller than original?

I think that's just about it: 62k is ~20% of 311k, so the conversion has shaved off 80% of the size of the original source image. Kind of seems to me that in this context displaying the size of the WebP image in comparison to the source file (20%) could've made more sense, but I guess it depends on how you like to think about it 🙂

About deleting a WebP variation – I've no idea.

Share this post


Link to post
Share on other sites
8 hours ago, teppo said:

but I guess it depends on how you like to think about it

Yeah. Maybe simple text like "80% smaller" or "20% larger" would make more sense. Or maybe no info at all. I'm also confused with the word "Original"...

Share this post


Link to post
Share on other sites

Hi,

On desktop everything works fine: Chrome, FF, Edge shows webp
On mobile (IOS) nothing works at all: no webp and no fallback jpg/png in no browser

PW Version: 3.0.142
.htaccess: AddType image/webp .webp
config.php:
$config->useWebP = true;
$config->contentTypes('webp', 'image/webp');

ImageMagick 7.0.8-25

Cleared cache!

Any ideas??

Thank you

Share this post


Link to post
Share on other sites
On 10/2/2019 at 12:03 PM, horst said:

@David Karich & @kalimati Which PW version(s) do show this behave? AND: which ImageSizerEngine(s) have you enabled there? (GD | IMagick)

We had a change in what image types are supported by IMagick and need to revert back some sorts of PNGs, especially 8bit PNGs are not correct supported by IMagick, and in very rare cases there also was wrong handling for some 8bit-PNGs in GD-Engine.

Maybe you can provide the informations plus one or two of the (original uploaded) images in a ZIP to me?

@horst Sorry for the later feedback, but here's the summary.

PW Version: 3.0.143 (dev, from 28. October 2019)
IMagick Image Sizer: 0.0.3
PHP imagick: 3.4.3
PHP: 7.2.x and 7.3.x

Otherwise no other image modules activated. I think that problem with PNG8 has occurred since the change in the module from 7.6.2019 or 6.7.2019. However you formatted the comment. I deactivate the ImageSizerEngineIMagick, and GD takes over, I have no problems.

In the attachment two test PNGs, one without compression (which works) and one compressed with tinypng.com (this one will change from a transparent background to a black background when resizing).

test-PNGs.zip

Share this post


Link to post
Share on other sites

Has anyone encountered such a problem?

When you generate WEBP via $image->webp (IMagick Image Sizer enabled), files are created, but they are not valid. Accordingly, they do not open in the browser. These files look quite functional, but are not displayed. I can’t understand what kind of images can go bad during generation.

I took one image, generated it in the same formats to get a working webp and a broken one. Google Chrome in the console displayed loading webp images, but did not display it. I downloaded both files. Comparing the files that I discovered a size mismatch for the generated WEBP files. File sizes differed by only 1 byte.
screenshot.

With the help of the HEX editor I looked at what was missing there. It turned out that during the generation of PHP does not append 1 byte to the end of the file, the file is not valid and Chrome can not display it.

Working file;
Broken file;

Having studied the structure of WEBP a bit, I came to the conclusion that all live files always end with byte x00, in addition WEBP continues to work fine if you add any number of x00 to the end. You can check it yourself, everything works fine.

$image = $page->images->first();
$resized = $image->size(1600, 960);
$webp = $resized->webp->url;
$file = fopen($webp, "a+");
fwrite($file, chr(0x00));
fclose($file);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Martin Wuehr
      Hello everybody,
      I'm hosting a Processwire Installation for a client. It runs on Processwire 2.5.3. Over the years everything was fine but now there is an issue with one Image-Field in one Template. Trying to upload an Image the Error "Not enough Memory to load/resize" occure. Other Image-Fields in all other Templates working without any issue. The Images I Tried to upload are very small (600px * 420px). The Images blongs to a News feed, and worked before.
      I read about the problem in the forum but I can't get this solved. I have no access to the php.ini to modify the memory_limit.
      I tried to update the Processwire Verion but failed. (Tried 2.7 /2.8 / 3.2) Got Always Internal Server Error and in the error Log: 
      Compile Error:     Cannot redeclare PageEditFieldPermissionConfig()….
      Has anybody any idea how I can get this solved?
      Thank you so much
      Martin
       
    • By August
      Hi again, after trying pages2PDF, RockPDF and mpdf I'm not sure which of them I should use. Of course, there is also wirePDF.
      I merged mpdf with rockPDF, add a footer and a page in Landscape and that works, like in the code-snippet below but be am I on the right way?
      After that I tried a couple of times rendering an image. Nothing happend, the same with Pages2PDF too. I also copied an Image-URL within processwire and tried further getting an Image within the PDF-Document, but it still display only the red marked placeholder.
      I simply would like create an PDF on click from some Pages including the Images.
      Are there special requirements on Debian 10 with Apache and php 7.3 using Processwire 3.0.123.?
      Is there a guide that I didn't found?
      Is somebody out there who has a similar issue solved and would you be so kind to explain?
       
      $pdf = $modules->get('RockPdf'); $mpdf = $pdf->mpdf; # $mpdf->showImageErrors = true; $pdf->set('SetHeader', 'header text'); $mpdf->AddPage('L'); # $mpdf->Image(urlencode('site/assets/files/1845/image-2.275x200.jpg'), 0, 0, 210, 297, 'jpg', '', true, false); $pdf->set('SetFooter', ' <table width="100%"> <tr> <td width="33%">{DATE j.m.Y}</td>        <td width="33%" align="center">{PAGENO}/{nbpg}</td> <td width="33%" style="text-align: right;">whatever</td> </tr> </table>'); $pdf->show(); // generate pdf  
    • By Hardoman
      Hello community,
      we have a website running version 3.0.118. The owner would like to have a watermark merged to the images, that are being uploaded in the CKEditor as a requirement.
      Image upload besides the CKEditor within galleries and single images works as a charm already. We also use croppable image 3 there. (PIM2)
      To realize this requirement, I thought of using a hook in the admin area. So, I read a lot in our forums and tested this by adding a hook into the ready.php file.
      $this->addHookAfter('InputfieldFile::fileAdded',function(HookEvent$event){ wire('log')->save('test','Image upload works'); ... The log entry is being created correctly. But when I try to use the pim/watermark-function like in a template, he cannot find the watermark-image anymore. Furthermore, when I try to get the page-id, it does not seem to be accessible, because the application does not seem to know how to reference it, or I dont know the right way to do so…
      So my questions are:
       
      Is this the right attempt at all or will there be another, better workaround? It seems, I cannot access the page object (of the content page) within this scope or file but I would need it to save the processed image inside the right files/id folder Would it be better to place the hook into the admin-template? (or admin.php)
        Thanks for any hints in advance. 🙂
    • By klikrzys
      Hello processwire world!
      Im having a little problem with getting my image in WEBP format.
      $image = $pages->get('/')->images->first();             echo $image->webp()->url();
    • By toni
      Hi,
      I'm facing a strang problem. In my template I'm setting different sizes for srcset:
      $view->set('images', $page->picture); <img srcset="{$img->size(780,0)->url} 780w, {$img->size(1024,0)->url} 1024w, {$img->size(1440,0)->url} 1440w" src="{$img->url}" class="col__image"> All fine. However, the moment I reorder images in backend the different generated image sizes are broken.
      Does somebody has an idea what could cause it? 
      Version: ProcessWire 3.0.123 
       
      Thanks!
      Toni
×
×
  • Create New...