picturefill.js.wp icon indicating copy to clipboard operation
picturefill.js.wp copied to clipboard

PHP Warning: getimagesize(): Filename cannot be empty

Open pixeline opened this issue 10 years ago • 2 comments

I get lots of lines like this in my server 's php error log

[23-Feb-2015 13:36:59 UTC] PHP Warning:  getimagesize(): Filename cannot be empty in /srv/data/web/vhosts/bjab.org/htdocs/wp-content/plugins/picturefill.js.wp-master/inc/class-model-image-picturefill-wp.php on line 167

it points to the third line of this function

  private function get_image_width_height(array $attachment_data){
      if(ini_get('allow_url_fopen')){
        $image_size = getimagesize($attachment_data['url']);

        if(!empty($image_size)){
          $attachment_data['width'] = $image_size[0];
          $attachment_data['height'] = $image_size[1];
        }
      }else{
        preg_match('/^(?:.+?)(?:-(\d+)x(\d+))\.(?:' . implode('|', $this->application_model->get_allowed_image_extensions()) . ')(?:(?:\?|#).+)?$/i', $attachment_data['url'], $image_width_height);
        if(!empty($image_width_height)){
          $attachment_data['width'] = $image_width_height[1];
          $attachment_data['width'] = $image_width_height[2];
        }
      }

      return $attachment_data;
    }

Any idea what causes this error?

pixeline avatar Feb 23 '15 17:02 pixeline

(I am not the plugin developer).

My guess is that it's because there is a logic error in get_unadjusted_size(): get_image_width_height() is being sent a pure array, when it should be sent a hash. Because it's sent an array, there is no such thing as $attachment_data['url'], the url is stored in $attachment_data[0].

I'm honestly not sure how to fix this. The way the code is written, get_unadjusted_size() creates a side-effect where it modifies the image_attributes property of the model (to add a width and height of the real image) in a permanent way. Currently the way it is written it doesn't do that because the code returns the PHP Warning which causes it to crap out and by a luck of nature use the existing width and height parameters (which are probably empty or the code wouldn't have executed in the manner to generate the erorr).

https://github.com/tychay/picturefill.js.wp/commit/4c809941cb51a3060df1e465bc708a50b13188c6

(Basically theoretically my patch will cause the currently linked image to write width and height tags if they were not provided.)

tychay avatar Apr 24 '15 04:04 tychay

Pull request https://github.com/kylereicks/picturefill.js.wp/pull/66

tychay avatar Apr 29 '15 06:04 tychay