document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. function WP_img_resize( $url, $width, $height = null, $crop = null, $single = true ) {
  2.     if(!$url OR !$width ) return false;
  3.  
  4.     $upload_info = wp_upload_dir();
  5.     $upload_dir = $upload_info[\'basedir\'];
  6.     $upload_url = $upload_info[\'baseurl\'];
  7.  
  8.     if(strpos( $url, $upload_url ) === false) return false;
  9.  
  10.     $rel_path = str_replace( $upload_url, \'\', $url);
  11.     $img_path = $upload_dir . $rel_path;
  12.  
  13.     if( !file_exists($img_path) OR !getimagesize($img_path) ) return false;
  14.  
  15.     $info = pathinfo($img_path);
  16.     $ext = $info[\'extension\'];
  17.     list($orig_w,$orig_h) = getimagesize($img_path);
  18.  
  19.     $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
  20.     $dst_w = $dims[4];
  21.     $dst_h = $dims[5];
  22.  
  23.     $suffix = "{$dst_w}x{$dst_h}";
  24.     $dst_rel_path = str_replace( \'.\'.$ext, \'\', $rel_path);
  25.     $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
  26.  
  27.     if(!$dst_h) {
  28.         $img_url = $url;
  29.         $dst_w = $orig_w;
  30.         $dst_h = $orig_h;
  31.     } elseif(file_exists($destfilename) && getimagesize($destfilename)) {
  32.         $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
  33.     } else {
  34.         $resized_img_path = image_resize( $img_path, $width, $height, $crop );
  35.         if(!is_wp_error($resized_img_path)) {
  36.             $resized_rel_path = str_replace( $upload_dir, \'\', $resized_img_path);
  37.             $img_url = $upload_url . $resized_rel_path;
  38.         } else {
  39.             return false;
  40.         }
  41.     }
  42.     if($single) {
  43.         $image = $img_url;
  44.     } else {
  45.         $image = array (
  46.             0 => $img_url,
  47.             1 => $dst_w,
  48.             2 => $dst_h
  49.         );
  50.     }
  51.  
  52.     return $image;
  53. }
');