Duplicate Optimize Attachments failing on .pdf

cdarsch

Member
Affected version
2.3.6
I ran Optimize Attachments and got the following error:

  • ErrorException: [E_WARNING] imagewebp(): gd-webp encoding failed
  • src/XF/Image/Gd.php:224
  • Generated by: Christo
  • Feb 25, 2025 at 10:31 AM

Stack trace​

#0 [internal function]: XF::handlePhpError(2, '[E_WARNING] ima...', '/home/gmcrvfor/...', 224)
#1 src/XF/Image/Gd.php(224): imagewebp(Object(GdImage), '/home/gmcrvfor/...', 85)
#2 src/XF/Image/AbstractDriver.php(285): XF\Image\Gd->_optimizeImage('/home/gmcrvfor/...', 85)
#3 src/XF/Service/Attachment/PreparerService.php(183): XF\Image\AbstractDriver->optimizeImage('/home/gmcrvfor/...')
#4 src/addons/XFMG/XF/Service/Attachment/Preparer.php(13): XF\Service\Attachment\PreparerService->optimizeExistingAttachment(Object(SV\AttachmentImprovements\XF\Entity\AttachmentData))
#5 src/addons/SV/AttachmentImprovements/XF/Service/Attachment/Preparer.php(134): XFMG\XF\Service\Attachment\Preparer->optimizeExistingAttachment(Object(SV\AttachmentImprovements\XF\Entity\AttachmentData))
#6 src/XF/Job/AttachmentOptimization.php(33): SV\AttachmentImprovements\XF\Service\Attachment\Preparer->optimizeExistingAttachment(Object(SV\AttachmentImprovements\XF\Entity\AttachmentData))
#7 src/XF/Job/AbstractImageOptimizationJob.php(27): XF\Job\AttachmentOptimization->optimizeById(1372)
#8 src/XF/Job/AbstractRebuildJob.php(42): XF\Job\AbstractImageOptimizationJob->rebuildById(1372)
#9 src/XF/Job/AbstractImageOptimizationJob.php(18): XF\Job\AbstractRebuildJob->run(8)
#10 src/XF/Job/Manager.php(275): XF\Job\AbstractImageOptimizationJob->run(8)
#11 src/XF/Job/Manager.php(205): XF\Job\Manager->runJobInternal(Array, 8)
#12 src/XF/Job/Manager.php(121): XF\Job\Manager->runJobEntry(Array, 8)
#13 src/XF/Admin/Controller/ToolsController.php(146): XF\Job\Manager->runByIds(Array, 8)
#14 src/XF/Mvc/Dispatcher.php(362): XF\Admin\Controller\ToolsController->actionRunJob(Object(XF\Mvc\ParameterBag))
#15 src/XF/Mvc/Dispatcher.php(264): XF\Mvc\Dispatcher->dispatchClass('XF:Tools', 'RunJob', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#16 src/XF/Mvc/Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#17 src/XF/Mvc/Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#18 src/XF/App.php(2826): XF\Mvc\Dispatcher->run()
#19 src/XF.php(806): XF\App->run()
#20 admin.php(15): XF::runApp('XF\\Admin\\App')
#21 {main}

Request state​

array(4) {
["url"] => string(24) "/admin.php?tools/run-job"
["referrer"] => string(124) "https://www.gmcmotorhome.org/admin.php?tools/run-job&only_id=190583&_xfRedirect=/admin.php?tools/rebuild&success=1"
["_GET"] => array(1) {
["tools/run-job"] => string(0) ""
}
["_POST"] => array(3) {
["_xfRedirect"] => string(62) "https://www.gmcmotorhome.org/admin.php?tools/rebuild&success=1"
["_xfToken"] => string(8) "********"
["only_ids"] => string(6) "190583"
}
}

I then performed the following SQL query:

SELECT data_id
FROM xf_attachment_data
WHERE optimized = 0
ORDER BY data_id
LIMIT 1;

and when I looked at the row in the xf_attachment_data table that this query returned, the filename was xxxx.pdf.

Optimize Attachments should skip PDF files.

Discussion that led to this discovery: https://xenforo.com/community/threads/optimize-attachments-failure.229465/page-2#post-1735389
 
Not sure I understand your question.
Chunked Uploads is new

might be related to that if the issue is new.
 
so it won't be that then
thanks for pointing it out.
sorry, carry on.

at the same time, maybe chunked uploads is a SOLUTION to this issue
:)
The problem I'm having is with the bulk conversion of existing images into webp format via Tools/Rebuild/Caches/Optimize Attachments, not with the upload/conversion of new images.
 
There won't be any attempt to do image optimization on non-image attachments. The attachment data column being 0 reflects nothing other than the attachment was not optimized (because it was not an image).

The error message you're running into likely just bad error handling around libwebp in certain PHP versions. What PHP version are you running?
 
Hi Jeremy P! I'm running PHP 8.3.16. I'm not expecting image optimization on non-image attachments, but I do expect the procedure to skip non-image attachments without failing.
 
It already does (unless there are other inconsistencies in your database, but then you have bigger problems). This error will almost certainly be from it failing on a genuine image due to an encoding/decoding error in libwebp. I don't believe PHP provides us much of a way to handle this more gracefully yet, unfortunately.

I've revised my query slightly in the previous instructions I gave, if you wish to try to resolve it manually:
 
That enabled the process to bypass the problem image. Thank you!

However, upon investigating, the problem image is a panoramic photo with dimensions 12,368 x 3,776. The forum can display the image fine. This is still a bug, no?
 
Yes, but our options for dealing with it may be limited a bit. It’s being tracked in the linked bug report. The information you’ve provided is helpful though, maybe we can skip over images above a certain dimensional threshold for now.
 
Back
Top Bottom