Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG conversion to AVIF / WebP does not work reliably #1798

Open
felixarntz opened this issue Jan 13, 2025 · 10 comments
Open

PNG conversion to AVIF / WebP does not work reliably #1798

felixarntz opened this issue Jan 13, 2025 · 10 comments
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken

Comments

@felixarntz
Copy link
Member

Bug Description

When I uploaded a PNG to my website in the block editor, I ran into a problem where the image file would not be found. As the file was (supposed to be) transformed to AVIF, I suspected it might have something to do with the Modern Image Formats plugin. Indeed that appears to be the case.

Some more details on what I am experiencing:

  • The thumbnail file {orig-name}-150x150.avif was successfully generated. But the main attachment file {orig-name}-png.avif is not to be found.
  • To test, I changed the target format option from "AVIF" to "WebP". After doing that, the same file doesn't get transformed at all. Obviously better than a broken image, but it's just as strange that the WebP transformation doesn't appear to even occur in this case.
  • I'm seeing the warning in Site Health that "Your site does not send AVIF image headers correctly". Could that be causing it? If that's the case and we already detect it though, we should probably not be generating AVIF.
  • It's strange that this happened, because literally a minute before I had uploaded another PNG image which was transformed into AVIF without any issues. So it's not consistent, but definitely seems unreliable.

There is a chance this has to do with certain server support / configuration, but in any case we should try to figure it out since we shouldn't offer transforming to AVIF in situations where it's not reliable.

Possibly caused by addition of PNG support which was done via #371. I don't have any problems with transforming JPEG into AVIF or WebP, the problems only occur with PNG files.

Steps to reproduce

  1. Make sure the plugin is set to transform into AVIF.
  2. Make sure generating fallback formats is off.
  3. Either edit a post in the block editor and upload a PNG image. Or upload a PNG image directly to the media library.

Additional Context

  • PHP Version: 8.1
  • WordPress Version: 6.7.1
  • OS: Mac OS
  • Browser: Chrome
  • Plugin Version: 2.4.0
@felixarntz felixarntz added [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken labels Jan 13, 2025
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2024 Jan 13, 2025
@felixarntz
Copy link
Member Author

@adamsilverstein Any idea what might be going on here?

@adamsilverstein
Copy link
Member

@adamsilverstein Any idea what might be going on here?

Could it possibly be related to the PNG itself? ie. does one PNG consistently fail to generate sub sizes while another consistently works? Can you check server logs and the browser console log for any potential errors?

I can give this a test to see if I can reproduce on my end

@felixarntz
Copy link
Member Author

felixarntz commented Jan 14, 2025

@adamsilverstein I can confirm it always happens with specific PNG images, but not others. So there has to be something maybe in the different PNG encodings that makes my server not want to deal with some of them.

There are no errors or Console logs when uploading them. So the problem isn't flagged, it's "silently" failing. When I try to open the full size image (for one of the PNG uploads where the problem occurs), I just get a 404.

@adamsilverstein
Copy link
Member

I can confirm it always happens with specific PNG images, but not others.

Could be related to alpha channel presence, transparency or bit depth.

Can you share your site health->info->media details so we can see what version GD/Imagick you are using?

If possible, can you share a working and non-working image? these would be useful for a unit test to reproduce the issue.

We recently landed some PNG handling improvements in core that could help, if possible can you try agains trunk?

@adamsilverstein
Copy link
Member

Possibly your generated images are larger that the original and so is being discarded in webp_uploads_should_discard_additional_image_file.

Do you have the "Also generate fallback images in the original upload format" option enabled under settings->media? If so, try disabling that to see if generation works for all images.

If you want both images always, you can disable the deletion behavior with:

add_filter( 'webp_uploads_discard_larger_generated_images', '__return_false' );

@felixarntz
Copy link
Member Author

Here's my Site Health info for media:

image_editor: WP_Image_Editor_Imagick
imagick_module_version: 1693
imagemagick_version: ImageMagick 6.9.13-17 Q16 x86_64 18482 https://legacy.imagemagick.org
imagick_version: 3.7.0
file_uploads: 1
post_max_size: 100M
upload_max_filesize: 100M
max_effective_size: 100 MB
max_file_uploads: 50
imagick_limits: 
	imagick::RESOURCETYPE_AREA: 503 GB
	imagick::RESOURCETYPE_DISK: 9.2233720368548E+18
	imagick::RESOURCETYPE_FILE: 24576
	imagick::RESOURCETYPE_MAP: 252 GB
	imagick::RESOURCETYPE_MEMORY: 126 GB
	imagick::RESOURCETYPE_THREAD: 1
	imagick::RESOURCETYPE_TIME: 0
imagemagick_file_formats: 3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FLV, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIDEO, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV
gd_version: bundled (2.1.0 compatible)
gd_formats: GIF, JPEG, PNG, WebP, BMP, AVIF, XPM
ghostscript_version: 9.27

It looks like my site's Imagemagick version does not support AVIF, but GD does, so I assume my site attempts to use GD for AVIF.

@felixarntz
Copy link
Member Author

Do you have the "Also generate fallback images in the original upload format" option enabled under settings->media? If so, try disabling that to see if generation works for all images.

That option is turned off on my site, so I have the problem even with the (technically much simpler) setup of only mapping the output format.

@adamsilverstein
Copy link
Member

This might be related to a GD "false positive" issue, see https://core.trac.wordpress.org/ticket/60628 which mentions zero sized image failures for some GD versions (although its odd that some sizes work).

Can you try to determine your PHP / GD versions and maybe see if you are able to get them upgraded or get imagick installed by your host?

@felixarntz
Copy link
Member Author

Aside: Since the PNG to AVIF generation only fails for the original image, but not the thumbnail, I wonder whether any of the additional processing of the sub-sizes (e.g. scaling down the image) alters something in the PNG file already, which then makes the conversion to AVIF work.

Since only the originally uploaded image is failing to convert to AVIF (which of course is completely outside of WordPress's control in terms of how it's encoded etc.), I wonder whether it would work if we first did some other (temporary) processing to that image before saving it as AVIF.

@adamsilverstein
Copy link
Member

adamsilverstein commented Jan 15, 2025

Since only the originally uploaded image is failing to convert to AVIF (which of course is completely outside of WordPress's control in terms of how it's encoded etc.), I wonder whether it would work if we first did some other (temporary) processing to that image before saving it as AVIF.

Maybe - we can certainly try retracing the calls more carefully and trying to reproduce. One thing I noticed is we do call resize on the image, but the image dimensions match those of the original, so that call returns early (this conditional returns true). We could try calling with a slightly different size to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken
Projects
Status: Not Started/Backlog 📆
Development

No branches or pull requests

2 participants