title: Fatal error Uncaught Error: Call to undefined method WP_Error
body: <p>Error message</p>
  <pre><code>&lt;b&gt;Fatal error&lt;/b&gt;:  Uncaught Error: Call to undefined method WP_Error::resize() in C:\Users\User\Documents\xampp\htdocs\WordPress1\wp-content\themes\elina\framework\php\PeTheme\PeThemeImage.php:144
  Stack trace:
  #0 C:\Users\User\Documents\xampp\htdocs\WordPress1\wp-content\themes\elina\framework\php\PeTheme\PeThemeImage.php(282): 
  PeThemeImage-&amp;gt;iresize('C:\\Users\\User\\D...', 320, 240, true)
  #1 C:\Users\User\Documents\xampp\htdocs\WordPress1\wp-content\themes\elina\framework\php\PeTheme\PeThemeImage.php(364):
   PeThemeImage-&amp;gt;aq_resize('http://localhos...', 320, 240, true, false)
  #2 C:\Users\User\Documents\xampp\htdocs\WordPress1\wp-content\themes\elina\framework\php\PeTheme\PeThemeImage.php(369): PeThemeImage-&amp;gt;resize('http://localhos...', 320, 240, true)
  </code></pre>
  <p>from code</p>
  <pre class="lang-php prettyprint-override"><code>class PeThemeImage { 
  protected $basedir;
  protected $baseurl;
  protected $blanks = array();
  protected $retina_enabled;
  protected $lazyload_enabled;
  protected $optkey;
  public $generated;
  protected $md5;
  protected $image_sizes;
  
  public function __construct() {
      $wp_upload = wp_upload_dir();
      $this-&gt;basedir = $wp_upload[&quot;basedir&quot;];
      $this-&gt;baseurl = $wp_upload[&quot;baseurl&quot;];
      $this-&gt;retina_enabled = peTheme()-&gt;options-&gt;get(&quot;retina&quot;) === &quot;yes&quot;;
      $this-&gt;lazyload_enabled = peTheme()-&gt;options-&gt;get(&quot;lazyImages&quot;) === &quot;yes&quot;;
      $this-&gt;optkey = &quot;pe_theme_&quot;.PE_THEME_NAME.&quot;_thumbnails&quot;;
      //delete_option($this-&gt;optkey);
      $this-&gt;generated = get_option($this-&gt;optkey,array(&quot;index&quot; =&gt; array()));
      $this-&gt;md5 = md5(serialize($this-&gt;generated));
  
      //peTheme()-&gt;thumbnail-&gt;clean();
  }
  
  public function &amp;blank($w,$h) {
      $key = &quot;{$w}x{$h}&quot;;
      if (isset($this-&gt;blanks[$key])) {
          return $this-&gt;blanks[$key];
      }
  
      $external = &quot;/img/blank/$key.gif&quot;;
  
      if (file_exists(PE_THEME_PATH.$external)) {
          // a blank img exists with the requested size
          $this-&gt;blanks[$key] = PE_THEME_URL.$external;
      } else {
          // create blank img
          $image = imagecreate($w, $h);
          imagesavealpha($image, true);
          imagecolortransparent($image, imagecolorallocatealpha($image, 0, 0, 0, 0));
          ob_start();
          imagegif($image);
          $this-&gt;blanks[$key] = &quot;data:image/gif;base64,&quot;.base64_encode(ob_get_clean());
          imagedestroy($image);
      }
  
      return $this-&gt;blanks[$key];
  }
  
  public function placeholder($w,$h) {
      return sprintf('&lt;img src=&quot;%s&quot; width=&quot;%s&quot; height=&quot;%s&quot; alt=&quot;&quot; /&gt;',$this-&gt;blank($w,$h),$w,$h);
  }
  
  
  public function get_size($img) {
      return stripos($img,&quot;http&quot;) === 0 ? false : getimagesize($img);
  }
  
  public function is_url($url) {
      return stripos($url,'http://') === 0 || strpos($url,'http://') === 0;
  }
  
  
  public function get_retina($url) {
  
      $ret = $this-&gt;retina_enabled;
      $lazy = $ret || $this-&gt;lazyload_enabled;
      $common = sprintf('src=&quot;%s&quot; alt=&quot;&quot;',$url);
  
      $img = str_replace(PE_THEME_URL,PE_THEME_PATH,$url);
      if ($this-&gt;is_url($img)) {
          $burl = $this-&gt;baseurl;
          $bdir = $this-&gt;basedir;
          $img = str_replace($burl,$bdir,$img);
          if ($this-&gt;is_url($img)) {
              // damn ... let's try adding/stripping www
              if (stripos(&quot;://www.&quot;,$url) &gt; -1) {
                  // www is there, try removing it
                  $burl = str_replace(&quot;://www.&quot;,&quot;://&quot;,$burl);
              } else {
                  // no www, try adding it
                  $burl = str_replace(&quot;://&quot;,&quot;://www.&quot;,$burl);
              }
              $img = str_replace($burl,$bdir,$img);
          }
      }
  
      if ($ret || $lazy) {
          
          if ($ret) {
              $ret = preg_replace(&quot;/\.(\w+)$/&quot;,'@2x.$1',$img);
              $ret = is_readable($ret) ? preg_replace(&quot;/\.(\w+)$/&quot;,'@2x.$1',$url) : false;
          }
  
          if ($ret || $lazy) {
              // try to get image size
              $size = $this-&gt;get_size($img);
              if ($size) {
                  list($w,$h) = $size;
                  $common = sprintf('src=&quot;%s&quot; width=&quot;%s&quot; height=&quot;%s&quot; alt=&quot;&quot;',$this-&gt;blank($w,$h),$w,$h);
              } else {
                  $common = sprintf('src=&quot;%s&quot; alt=&quot;&quot;',$this-&gt;blank(1,1));
              }
  
              $lazy = sprintf(' data-original=&quot;%s&quot;',$url);
              $ret = $ret ? sprintf(' data-original-hires=&quot;%s&quot;',$ret) : &quot;&quot;;
          }
      } else {
          $size = $this-&gt;get_size($img);
  
          if ($size) {
              list($w,$h) = $size;
              $common = sprintf('src=&quot;%s&quot; width=&quot;%s&quot; height=&quot;%s&quot; alt=&quot;&quot;',$url,$w,$h);
          } 
      }
  
      return sprintf(&quot;&lt;img %s%s%s&gt;&quot;,$common,$lazy,$ret);
  }
  
  public function retina($img) {
      echo $this-&gt;get_retina($img);
  }
  
  
  public function iresize($file,$width,$height,$crop) { // compatibilty wrapper for 3.4, &gt;= 3.5 use wp_get_image_editor
      if (function_exists(&quot;wp_get_image_editor&quot;)) {
  
          // check if custom cropping defined
          $size = &quot;{$width}x{$height}&quot;;
          $thumb = str_replace($this-&gt;basedir,&quot;&quot;,preg_replace(&quot;/(\.\w+)$/&quot;,&quot;-$size\\1&quot;,$file));
          if (!empty($this-&gt;generated[&quot;crop&quot;][$thumb])) {
              $crop = $this-&gt;generated[&quot;crop&quot;][$thumb];
              $url = str_replace($this-&gt;basedir,$this-&gt;baseurl,$file);
              $this-&gt;crop($url,$crop,$width,$height);
              return $this-&gt;basedir.$thumb;
          }
  
          // WP 3.5
          $editor = wp_get_image_editor($file);
          $editor-&gt;resize($width,$height,$crop);
          $dest_file = $editor-&gt;generate_filename();
          $editor-&gt;save($dest_file);
          return $dest_file;
      } else {
          $f = &quot;image_resize&quot;; // compatibilty with WP 3.4 and below
          return $f($file,$width,$height,$crop);
      }
  }
  
  
  public static function makeBWimage($file,$dest) {
      //$image = wp_load_image($file);
      $image = imagecreatefromstring( file_get_contents( $file ) );
      $res = imagefilter($image,IMG_FILTER_GRAYSCALE);
      $res = $res &amp;&amp; imagejpeg($image,$dest);
      imagedestroy($image);
      return $res;
  }
  
  public function blackwhite_filter($meta) {
      if (!isset($meta) || !is_array($meta) || count($meta) == 0) {
          return $meta;
      }
      $base = dirname($this-&gt;basedir.&quot;/&quot;.$meta[&quot;file&quot;]);
      $thumbs = array_keys(PeGlobal::$config[&quot;image-sizes&quot;]);
  
      if (isset($meta[&quot;sizes&quot;])) {
          $sizes =&amp; $meta[&quot;sizes&quot;];
      }
  
      foreach ($thumbs as $thumb) {
          if (substr($thumb,-3,3) == &quot;-bw&quot;) {
              $normal = substr($thumb,0,strlen($thumb)-3);
              if (isset($sizes) &amp;&amp; isset($sizes[$normal])) {
                  $bwthumb = array_merge($sizes[$normal]);
              } else {
                  $bwthumb = array(&quot;file&quot; =&gt; wp_basename($meta[&quot;file&quot;]), &quot;width&quot; =&gt; $meta[&quot;width&quot;], &quot;height&quot; =&gt; $meta[&quot;height&quot;]);
              }
              $file = &quot;$base/{$bwthumb['file']}&quot;;
              $dest = preg_replace('/\.\w+$/', &quot;-bw.jpg&quot;, $file);
              if (!isset($seen[$file])) {
                  $seen[$file] = true;
                  $this-&gt;makeBWimage($file,$dest);
              }
              $bwthumb[&quot;file&quot;] = wp_basename($dest);
              $meta[&quot;sizes&quot;][$thumb] = $bwthumb;
          }
      }
  
      return $meta;
  }
  
  /**
   * Title        : Aqua Resizer
   * Description  : Resizes WordPress images on the fly
   * Version  : 1.1.3
   * Author   : Syamil MJ
   * Author URI   : http://aquagraphite.com
   * License  : WTFPL - http://sam.zoy.org/wtfpl/
   * Documentation    : https://github.com/sy4mil/Aqua-Resizer/
   *
   * @param string $url - (required) must be uploaded using wp media uploader
   * @param int $width - (required)
   * @param int $height - (optional)
   * @param bool $crop - (optional) default to soft crop
   * @param bool $single - (optional) returns an array if false
   * @uses wp_upload_dir()
   *
   * @return str|array
   */
  public function aq_resize( $url, $width, $height = null, $crop = null, $single = true ) {
      
      //validate inputs
      if(!$url OR !$width ) return false;
      
      //define upload path &amp; dir
      $upload_dir = $this-&gt;basedir;
      $upload_url = $this-&gt;baseurl;
      
      //check if $img_url is local
      //if(strpos( $url, home_url() ) === false) return false;
      if(strpos( $url, $upload_url ) === false) return false;
      
      //define path of image
      $rel_path = str_replace( $upload_url, '', $url);
      $img_path = $upload_dir . $rel_path;
      
      //check if img path exists, and is an image indeed
      if( !file_exists($img_path) OR !getimagesize($img_path) ) return false;
      
      //get image info
      $info = pathinfo($img_path);
      $ext = $info['extension'];
      list($orig_w,$orig_h) = getimagesize($img_path);
      
      //get image size after cropping
      $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
      $dst_w = $dims[4];
      $dst_h = $dims[5];
      
      //use this to check if cropped image already exists, so we can return that instead
      $suffix = &quot;{$dst_w}x{$dst_h}&quot;;
  
      $dst_rel_path = str_replace( '.'.$ext, '', $rel_path);
      $destfilename = &quot;{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}&quot;;
      
      //if orig size is smaller
      if($width &gt;= $orig_w) {
          
          if(!$dst_h) :
              //can't resize, so return original url
              $img_url = $url;
          $dst_w = $orig_w;
          $dst_h = $orig_h;
          
          else :
              //else check if cache exists
              if(file_exists($destfilename) &amp;&amp; getimagesize($destfilename)) {
                  $img_url = &quot;{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}&quot;;
              } 
          //else resize and return the new resized image url
              else {
                  $resized_img_path = $this-&gt;iresize( $img_path, $width, $height, $crop );
                  $resized_rel_path = str_replace( $upload_dir, '', $resized_img_path);
                  $img_url = $upload_url . $resized_rel_path;
                  
              }
          
          endif;
          
      }
      //else check if cache exists
      elseif(file_exists($destfilename) &amp;&amp; getimagesize($destfilename)) {
          $img_url = &quot;{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}&quot;;
      } 
      //else, we resize the image and return the new resized image url
      else {
          $resized_img_path = $this-&gt;iresize( $img_path, $width, $height, $crop );
          $resized_rel_path = str_replace( $upload_dir, '', $resized_img_path);
          $img_url = $upload_url . $resized_rel_path;
      }
      
  
      //return the output
      if($single) {
          //str return
          $image = $img_url;
      } else {
          //array return
          $image = array (
                          0 =&gt; $img_url,
                          1 =&gt; $dst_w,
                          2 =&gt; $dst_h
                          );
      }
      
      $this-&gt;bwMode = false;
  
      if ($url != $img_url &amp;&amp; !is_admin()) {
          $size = &quot;{$dst_w}x{$dst_h}&quot;;
          if (!isset($this-&gt;generated[&quot;index&quot;][$rel_path][$size])) {
              $this-&gt;generated[&quot;index&quot;][$rel_path][$size] = true;
          }
      }
  
      return $image;
  }
  
  public function file($url) {
      if(strpos($url,$this-&gt;baseurl) === false) return false;
      return str_replace($this-&gt;baseurl, $this-&gt;basedir, $url);
  }
  
  
  public function crop($url,$crop,$w,$h) {
  
      if (($file = $this-&gt;file($url)) === false) return false; 
  
      $file = str_replace($this-&gt;baseurl, $this-&gt;basedir, $url);
      $size = &quot;{$w}x{$h}&quot;;
      $thumb = preg_replace(&quot;/(\.\w+)$/&quot;,&quot;-$size\\1&quot;,$file);
  
      list($x1,$y1,$x2,$y2) = explode(&quot;,&quot;,$crop);
      $cw = $x2-$x1;
      if ($cw&lt;$w) {
          // fix x1
          $x1 -= min($x1,$w-$cw);
          $cw = $x2-$x1;
          if ($cw &lt; $w) {
              // fix x2
              $x2 += $w-$cw;
          }
      }
      $y2 =  $y1 + ceil($h*($cw/$w));
      $ch = $y2-$y1;
      if ($ch&lt;$h) {
          // fix y1
          $y1 -= min($y1,$h-$ch);
          $ch = $y2-$y1;
          if ($ch &lt; $h) {
              // fix y2
              $y2 += $h-$ch;
          }
      }
      $cw = $x2-$x1;
      $ch = $y2-$y1;
      $editor = wp_get_image_editor($file);
      $editor-&gt;crop($x1,$y1,$cw,$ch,$w,$h);
      $ret = $editor-&gt;save($thumb);
      if (!empty($ret[&quot;path&quot;])) {
          $ret[&quot;url&quot;] = str_replace($this-&gt;basedir,$this-&gt;baseurl,$ret[&quot;path&quot;]);
          $ret[&quot;cburl&quot;] = $ret[&quot;url&quot;].&quot;?t=&quot;.filemtime($ret[&quot;path&quot;]); 
      }
      $editor = null;
      return $ret;
  }
  
  
  public function resize($url,$w,$h = null,$crop = true) {
      return $this-&gt;aq_resize($url,$w,$h,$crop,false);
  }
  
  public function resizedImg($url,$w,$h = null,$crop = true) {
      if (!$url) return;
      $result = $this-&gt;resize($url,$w,$h,$crop);
      if (!$result) return;
      $unscaled = $url;
      list($url,$w,$h) = $result;
  
      return apply_filters(&quot;pe_theme_resized_img&quot;,&quot;&lt;img alt=\&quot;\&quot; width=\&quot;$w\&quot; height=\&quot;$h\&quot; src=\&quot;$url\&quot;/&gt;&quot;,$url,$w,$h,$unscaled);
  }
  
  public function resizedImgUrl($url,$w,$h = null,$crop = true) {
      return $this-&gt;aq_resize($url,$w,$h,$crop,true);
  }
  
  public function stats() {
      if ($this-&gt;md5 != md5(serialize($this-&gt;generated))) {
          update_option($this-&gt;optkey,$this-&gt;generated);
      }
  }
  
  public function get_images_size() {
      // make thumbnails and other intermediate sizes
      global $_wp_additional_image_sizes;
  
      $this-&gt;image_sizes = array();
      foreach ( get_intermediate_image_sizes() as $s ) {
          $sizes[$s] = array( 'width' =&gt; '', 'height' =&gt; '', 'crop' =&gt; false );
          if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
              $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
          else
              $sizes[$s]['width'] = get_option( &quot;{$s}_size_w&quot; ); // For default sizes set in options
          if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
              $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
          else
              $sizes[$s]['height'] = get_option( &quot;{$s}_size_h&quot; ); // For default sizes set in options
          if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
              $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
          else
              $sizes[$s]['crop'] = get_option( &quot;{$s}_crop&quot; ); // For default sizes set in options
      }
  
      $this-&gt;image_sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
  
  }
  
  
  public function post_thumbnail_html_filter($html,$post_id,$post_thumbnail_id,$size,$attr,$retina = false,$lazy = false) {
      //return $html;
      if (empty($post_thumbnail_id)) return $html;
      $url = wp_get_attachment_url($post_thumbnail_id);
      if (empty($url)) return $html;
      
      if (!isset($this-&gt;image_sizes[$size])) {
          $this-&gt;get_images_size();
          if (!isset($this-&gt;image_sizes[$size])) {
              return $html;
          }
      }
  
      $size = (object) $this-&gt;image_sizes[$size];
  
      if (!empty($size-&gt;width) &amp;&amp; !empty($size-&gt;height)) {
          $resized = $this-&gt;resize($url,$size-&gt;width,$size-&gt;height,empty($size-&gt;crop) ? false : true);
          if (empty($resized)) {
              return $html;
          }
      }
  
      list($img,$w,$h) = $resized;
  
      if ($retina || $lazy) {
          $blank = $this-&gt;blank($w,$h);
          if ($retina) {
              $lazy = true;
              $retina = $this-&gt;resizedImgUrl($url,$w*2,$h*2);
              $newsrc = sprintf('src=&quot;%s&quot; data-original=&quot;%s&quot; data-original-hires=&quot;%s&quot;',$blank,$img,$retina);
          } else {
              $newsrc = sprintf('src=&quot;%s&quot; data-original=&quot;%s&quot;',$blank,$img);
          }
      } else {
          $newsrc = sprintf('src=&quot;%s&quot;',$img);
      }
  
      $newwidth = sprintf('width=&quot;%s&quot;',$w);
      $newheight = sprintf('height=&quot;%s&quot;',$h);
  
      $html = preg_replace(&quot;/src=\&quot;[^\&quot;]+\&quot;/&quot;,$newsrc,$html);
      $html = preg_replace(&quot;/width=\&quot;\d+\&quot;/&quot;,$newwidth,$html);
      $html = preg_replace(&quot;/height=\&quot;\d+\&quot;/&quot;,$newheight,$html);
  
      if ($lazy) {
          if (strpos($html,'class=') &gt; -1) {
              $html = preg_replace(&quot;/class=\&quot;/&quot;,'class=&quot;peLazyLoading ',$html);
          } else {
              $html = preg_replace(&quot;/&lt;img /&quot;,'&lt;img class=&quot;peLazyLoading&quot; ',$html);
          }
      }
  
      return $html;
  }
  
  public function bw($url) {
      if(!$url) return &quot;&quot;;
      
      //define upload path &amp; dir
      $upload_dir = $this-&gt;basedir;
      $upload_url = $this-&gt;baseurl;
  
      //check if $img_url is local
      if(strpos( $url, $upload_url ) === false) return false;
      
      //define path of image
      $rel_path = str_replace( $upload_url, '', $url);
      $img_path = $upload_dir . $rel_path;
      
      //check if img path exists, and is an image indeed
      if( !file_exists($img_path) OR !getimagesize($img_path) ) return &quot;&quot;;
      
      //get image info
      $info = pathinfo($img_path);
      $ext = $info['extension'];
  
      $dst_rel_path = str_replace( '.'.$ext, '', $rel_path);
      $destfilename = &quot;{$upload_dir}{$dst_rel_path}-bw.jpg&quot;;
  
      if (file_exists($destfilename) &amp;&amp; getimagesize($destfilename)) {
          $url = &quot;{$upload_url}{$dst_rel_path}-bw.jpg&quot;;
      } else {
          try {
              if (@$this-&gt;makeBWimage($img_path,$destfilename)) {
                  $url = &quot;{$upload_url}{$dst_rel_path}-bw.jpg&quot;;
              }
          } catch(Exception $e) {
          }
      }
  
      return $url;
  }
  
  
  
  }
  </code></pre>