laravel imagesx() 期望参数 1 是资源,布尔值给定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12470251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:48:46  来源:igfitidea点击:

imagesx() expects parameter 1 to be resource, boolean given

phpapachelaravel

提问by Nyxynyx

I am using a image thumbnailing library (Laravel's resizer bundle) which takes a jpg from a directory and uses imagesx()to save that image in a different size. This works without error most of the time.

我正在使用图像缩略图库(Laravel 的 resizer),它从目录中获取 jpg 并用于imagesx()以不同的大小保存该图像。这在大多数情况下都不会出错。

Problem:However sometimes when there is a batch of images to be processed, I get the error below. While debugging, I did

问题:但是有时当要处理一批图像时,我会收到以下错误。在调试时,我做了

....
print_r($this->image);
imagesx($this->image);
....

PHP output

PHP输出

Resource id #64Resource id #67Resource id #73Resource id #76Resource id #82Resource id #85Resource id #91Resource id #94Resource id #100Resource id #103Resource id #109Resource id #112Resource id #118Resource id #121Resource id #127Resource id #130Resource id #136Resource id #139Resource id #145Resource id #148Resource id #154Resource id #157Resource id #163Resource id #166

Unhandled Exception

Message:

imagesx() expects parameter 1 to be resource, boolean given
Location:

/home/dev/public_html/bundles/resizer/resizer.php on line 69
Stack Trace:

#0 /home/dev/public_html/laravel/laravel.php(40): Laravel\Error::native(2, 'imagesx() expec...', '/home/dev/publi...', 69)
#1 [internal function]: Laravel\{closure}(2, 'imagesx() expec...', '/home/dev/publi...', 69, Array)
#2 /home/dev/public_html/bundles/resizer/resizer.php(69): imagesx(false)
#3 /home/dev/public_html/bundles/resizer/resizer.php(81): Resizer->__construct('/home/photos/pu...')
#4 /home/dev/public_html/application/controllers/crawl/cl.php(369): Resizer::open('/home/photos/pu...')
#5 /home/dev/public_html/application/controllers/crawl/cl.php(315): Crawl_CL_Controller->save_photos(Array, 2516533, '2012-09-17 18:4...')
#6 [internal function]: Crawl_CL_Controller->action_crawl_next_item()
#7 /home/dev/public_html/laravel/routing/controller.php(325): call_user_func_array(Array, Array)
#8 /home/dev/public_html/laravel/routing/controller.php(285): Laravel\Routing\Controller->response('crawl_next_item', Array)
#9 /home/dev/public_html/laravel/routing/controller.php(165): Laravel\Routing\Controller->execute('crawl_next_item', Array)
#10 /home/dev/public_html/laravel/routing/route.php(153): Laravel\Routing\Controller::call('crawl.cl@(:1)', Array)
#11 /home/dev/public_html/laravel/routing/route.php(124): Laravel\Routing\Route->response()
#12 /home/dev/public_html/laravel/laravel.php(165): Laravel\Routing\Route->call()
#13 /home/dev/public_html/public/index.php(34): require('/home/dev/publi...')
#14 {main}

Together with the stack trace above, you can see that $this->imageis falseright after its Resource id #166.

连同上面的堆栈跟踪,你可以看到,$this->imagefalse其之后Resource id #166

Any idea what may have caused this? I dont understand why it can sometimes be false. Thanks!

知道是什么原因造成的吗?我不明白为什么有时会这样false。谢谢!

采纳答案by Maikel D

This is happening because the mime type for that file isn't being recognised or is not a jpg/jpeg/png/gif.

发生这种情况是因为该文件的 MIME 类型未被识别或不是 jpg/jpeg/png/gif。

The $this->image is being set to false on line 196 in resizer.php.

$this->image 在 resizer.php 的第 196 行被设置为 false。

If you can't get it to work, please create an issue on Github so I can follow it up :-)

如果你不能让它工作,请在 Github 上创建一个问题,以便我可以跟进:-)