rushy Posted October 4 Posted October 4 (edited) Hi forum Have been using a site locally and live for a few years, recently I am encountering and error when a new image is added to any page when the page is displayed on the site I do not see the image but get an error text - Warning: filesize(): stat failed for /home/ltwdbmj/www/site/assets/files/1021/image_teleconsultations.0x0.jpg in /home/ltwdbmj/www/wire/core/Pageimage.php on line 951 Looking in the logs there are no errors but an image-sizer.txt containing - 026-10-04 20:32:33 admin https://mysite.com/qui-suis-je/ /site/assets/files/1021/image_teleconsultations.0x0.jpg - ImageSizer::resize(0, 0) failed for /home/ltwdbmj/www/site/assets/cache/WireTempDir/.PFM0.92432800T1791142353RdlwJDaqhIJzlh8Kgk/0/image_teleconsultations.0x0.jpg GD FAILED Resize: image_teleconsultations.jpg => image_teleconsultations.0x0.jpg (0x0) 0.0020 secs 1106568 => bytes (quality=90, sharpening=soft) It looks to me as if a 0x0 resize is attempted and hence GD fails, but I don't know why. File priviledges looks correct. PW 3.0.259 and PHP 8.5 Any ideas greatly apprectiated! Edited Saturday at 12:24 PM by rushy Solved
adrian Posted October 4 Posted October 4 Hi @rushy, The `0x0` in the variation name tells you what's happening: something is calling `$image->size()` (or `width()`/`height()`) with width and height that both evaluate to 0. That includes `''`, `null`, and unset variables. ImageSizer has always refused a 0x0 resize, which gives the "GD FAILED Resize … (0x0)" log entry. GD and the image itself are fine. If PHP couldn't read the JPG, ImageSizer would throw "not a recognized image" before it got to the resize step. The variation name also has no `-ms` suffix, so it isn't coming from `maxSize()`. I'd look at the template for `/qui-suis-je/` (page 1021), or any partial or module it uses, for the code that resizes images. Something there gives a width and height that come out as 0 for the newly added images. For example, it might read them from a field or setting that's empty for new images, or from a variable that isn't set. A quick way to find it: $wire->addHookBefore('Pageimage::size', function($e) { if(!(int) $e->arguments(0) && !(int) $e->arguments(1)) { $e->log->save('image-0x0', $e->object->basename . "\n" . (new \Exception())->getTraceAsString()); } }); Put that in /site/ready.php, load the page, then check /site/assets/logs/image-0x0.txt for the calling file and line. The "filesize(): stat failed" warning is a small core issue. With $config->debug on, the image-sizer log line calls filesize() on the variation even when it was never created. It only shows up because the resize failed, so once the 0x0 call is fixed it'll go away too. Core fix, for @ryan, in Pageimage::___size(): - "({$width}x{$height}) " . Debug::timer($timer) . " secs $originalSize => " . filesize($filenameFinal) . " bytes " . + "({$width}x{$height}) " . Debug::timer($timer) . " secs $originalSize => " . (is_file($filenameFinal) ? filesize($filenameFinal) : 0) . " bytes " . 2
rushy Posted October 7 Author Posted October 7 Hi @adrian Thank you for your useful help. I'll try out that hook code you gave to see why a zero resize is happening. I have a copy of the site on my localhost and this problem does not occur so it's not obvious what's gone wrong, but hopefully your hook should reveal more to me.
rushy Posted Saturday at 12:15 PM Author Posted Saturday at 12:15 PM SOLVED. Whoops I has forgotten on this site I have vars. in my config.php to define thumbnail sizes as below: $config->thumbWidth = 200; $config->thumbHeight = 150; Very useful until I forgot when making a new config. file so these being undefined created the above error. Thanks @adrian for pointing me in the right direction.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now