original_string: public function get_thumb_url($image_url, $orig_width, $orig_height, $thumb_width = 75, $force = false) {
          global $OUTPUT;
  
          if (!$force && $orig_width <= $thumb_width && $orig_height <= $thumb_width) {
              return $image_url;
          } else {
              $thumb_url = '';
              $commons_main_dir = 'https://upload.wikimedia.org/wikipedia/commons/';
              if ($image_url) {
                  $short_path = str_replace($commons_main_dir, '', $image_url);
                  $extension = strtolower(pathinfo($short_path, PATHINFO_EXTENSION));
                  if (strcmp($extension, 'gif') == 0) {  //no thumb for gifs
                      return $OUTPUT->image_url(file_extension_icon('.gif', $thumb_width))->out(false);
                  }
                  $dir_parts = explode('/', $short_path);
                  $file_name = end($dir_parts);
                  if ($orig_height > $orig_width) {
                      $thumb_width = round($thumb_width * $orig_width/$orig_height);
                  }
                  $thumb_url = $commons_main_dir . 'thumb/' . implode('/', $dir_parts) . '/'. $thumb_width .'px-' . $file_name;
                  if (strcmp($extension, 'svg') == 0) {  //png thumb for svg-s
                      $thumb_url .= '.png';
                  }
              }
              return $thumb_url;
          }
      }
code: public function get_thumb_url($image_url, $orig_width, $orig_height, $thumb_width = 75, $force = false) {
          global $OUTPUT;
  
          if (!$force && $orig_width <= $thumb_width && $orig_height <= $thumb_width) {
              return $image_url;
          } else {
              $thumb_url = '';
              $commons_main_dir = 'https://upload.wikimedia.org/wikipedia/commons/';
              if ($image_url) {
                  $short_path = str_replace($commons_main_dir, '', $image_url);
                  $extension = strtolower(pathinfo($short_path, PATHINFO_EXTENSION));
                  if (strcmp($extension, 'gif') == 0) {  //no thumb for gifs
                      return $OUTPUT->image_url(file_extension_icon('.gif', $thumb_width))->out(false);
                  }
                  $dir_parts = explode('/', $short_path);
                  $file_name = end($dir_parts);
                  if ($orig_height > $orig_width) {
                      $thumb_width = round($thumb_width * $orig_width/$orig_height);
                  }
                  $thumb_url = $commons_main_dir . 'thumb/' . implode('/', $dir_parts) . '/'. $thumb_width .'px-' . $file_name;
                  if (strcmp($extension, 'svg') == 0) {  //png thumb for svg-s
                      $thumb_url .= '.png';
                  }
              }
              return $thumb_url;
          }
      }
code_tokens: public function get_thumb_url ( $ image_url , $ orig_width , $ orig_height , $ thumb_width = 75 , $ force = false ) { global $ OUTPUT ; if ( ! $ force && $ orig_width <= $ thumb_width && $ orig_height <= $ thumb_width ) { return $ image_url ; } else { $ thumb_url = '' ; $ commons_main_dir = 'https://upload.wikimedia.org/wikipedia/commons/' ; if ( $ image_url ) { $ short_path = str_replace ( $ commons_main_dir , '' , $ image_url ) ; $ extension = strtolower ( pathinfo ( $ short_path , PATHINFO_EXTENSION ) ) ; if ( strcmp ( $ extension , 'gif' ) == 0 ) { //no thumb for gifs return $ OUTPUT -> image_url ( file_extension_icon ( '.gif' , $ thumb_width ) ) -> out ( false ) ; } $ dir_parts = explode ( '/' , $ short_path ) ; $ file_name = end ( $ dir_parts ) ; if ( $ orig_height > $ orig_width ) { $ thumb_width = round ( $ thumb_width * $ orig_width / $ orig_height ) ; } $ thumb_url = $ commons_main_dir . 'thumb/' . implode ( '/' , $ dir_parts ) . '/' . $ thumb_width . 'px-' . $ file_name ; if ( strcmp ( $ extension , 'svg' ) == 0 ) { //png thumb for svg-s $ thumb_url .= '.png' ; } } return $ thumb_url ; } }
docstring: Generate thumbnail URL from image URL.
  
  @param string $image_url
  @param int $orig_width
  @param int $orig_height
  @param int $thumb_width
  @param bool $force When true, forces the generation of a thumb URL.
  @global object OUTPUT
  @return string
docstring_tokens: Generate thumbnail URL from image URL .