original_string: public function fit($src, $dest, $width, $height){
          // Calculate
          $size = getimagesize($src);
          $ratio = max($width / $size[0], $height / $size[1]);
          $old_width = $size[0];
          $old_height = $size[1];
          $new_width = intval($old_width * $ratio);
          $new_height = intval($old_height * $ratio);
          // Resize
          @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
          $image = imagecreatefromstring( file_get_contents( $src ) );
          $new_image = wp_imagecreatetruecolor( $new_width, $new_height );
          imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
          if ( IMAGETYPE_PNG == $size[2] && function_exists('imageistruecolor') && !imageistruecolor( $image ) ){
              imagetruecolortopalette( $new_image, false, imagecolorstotal( $image ) );
          }
          // Destroy old image
          imagedestroy( $image );
          // Save
          switch($size[2]){
              case IMAGETYPE_GIF:
                  $result = imagegif($new_image, $dest);
                  break;
              case IMAGETYPE_PNG:
                  $result = imagepng($new_image, $dest);
                  break;
              default:
                  $result = imagejpeg($new_image, $dest);
                  break;
          }
          imagedestroy($new_image);
          return $result;
      }
code: public function fit($src, $dest, $width, $height){
          // Calculate
          $size = getimagesize($src);
          $ratio = max($width / $size[0], $height / $size[1]);
          $old_width = $size[0];
          $old_height = $size[1];
          $new_width = intval($old_width * $ratio);
          $new_height = intval($old_height * $ratio);
          // Resize
          @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
          $image = imagecreatefromstring( file_get_contents( $src ) );
          $new_image = wp_imagecreatetruecolor( $new_width, $new_height );
          imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
          if ( IMAGETYPE_PNG == $size[2] && function_exists('imageistruecolor') && !imageistruecolor( $image ) ){
              imagetruecolortopalette( $new_image, false, imagecolorstotal( $image ) );
          }
          // Destroy old image
          imagedestroy( $image );
          // Save
          switch($size[2]){
              case IMAGETYPE_GIF:
                  $result = imagegif($new_image, $dest);
                  break;
              case IMAGETYPE_PNG:
                  $result = imagepng($new_image, $dest);
                  break;
              default:
                  $result = imagejpeg($new_image, $dest);
                  break;
          }
          imagedestroy($new_image);
          return $result;
      }
code_tokens: public function fit ( $ src , $ dest , $ width , $ height ) { // Calculate $ size = getimagesize ( $ src ) ; $ ratio = max ( $ width / $ size [ 0 ] , $ height / $ size [ 1 ] ) ; $ old_width = $ size [ 0 ] ; $ old_height = $ size [ 1 ] ; $ new_width = intval ( $ old_width * $ ratio ) ; $ new_height = intval ( $ old_height * $ ratio ) ; // Resize @ ini_set ( 'memory_limit' , apply_filters ( 'image_memory_limit' , WP_MAX_MEMORY_LIMIT ) ) ; $ image = imagecreatefromstring ( file_get_contents ( $ src ) ) ; $ new_image = wp_imagecreatetruecolor ( $ new_width , $ new_height ) ; imagecopyresampled ( $ new_image , $ image , 0 , 0 , 0 , 0 , $ new_width , $ new_height , $ old_width , $ old_height ) ; if ( IMAGETYPE_PNG == $ size [ 2 ] && function_exists ( 'imageistruecolor' ) && ! imageistruecolor ( $ image ) ) { imagetruecolortopalette ( $ new_image , false , imagecolorstotal ( $ image ) ) ; } // Destroy old image imagedestroy ( $ image ) ; // Save switch ( $ size [ 2 ] ) { case IMAGETYPE_GIF : $ result = imagegif ( $ new_image , $ dest ) ; break ; case IMAGETYPE_PNG : $ result = imagepng ( $ new_image , $ dest ) ; break ; default : $ result = imagejpeg ( $ new_image , $ dest ) ; break ; } imagedestroy ( $ new_image ) ; return $ result ; }
docstring: Fit small image to specified bound
  
  @param string $src
  @param string $dest
  @param int $width
  @param int $height
  @return bool
docstring_tokens: Fit small image to specified bound