original_string: protected function create_file_preview(stored_file $file, $mode) {
  
          $mimetype = $file->get_mimetype();
  
          if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
              // make a preview of the image
              $data = $this->create_imagefile_preview($file, $mode);
  
          } else {
              // unable to create the preview of this mimetype yet
              return false;
          }
  
          if (empty($data)) {
              return false;
          }
  
          $context = context_system::instance();
          $record = array(
              'contextid' => $context->id,
              'component' => 'core',
              'filearea'  => 'preview',
              'itemid'    => 0,
              'filepath'  => '/' . trim($mode, '/') . '/',
              'filename'  => $file->get_contenthash(),
          );
  
          $imageinfo = getimagesizefromstring($data);
          if ($imageinfo) {
              $record['mimetype'] = $imageinfo['mime'];
          }
  
          return $this->create_file_from_string($record, $data);
      }
code: protected function create_file_preview(stored_file $file, $mode) {
  
          $mimetype = $file->get_mimetype();
  
          if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
              // make a preview of the image
              $data = $this->create_imagefile_preview($file, $mode);
  
          } else {
              // unable to create the preview of this mimetype yet
              return false;
          }
  
          if (empty($data)) {
              return false;
          }
  
          $context = context_system::instance();
          $record = array(
              'contextid' => $context->id,
              'component' => 'core',
              'filearea'  => 'preview',
              'itemid'    => 0,
              'filepath'  => '/' . trim($mode, '/') . '/',
              'filename'  => $file->get_contenthash(),
          );
  
          $imageinfo = getimagesizefromstring($data);
          if ($imageinfo) {
              $record['mimetype'] = $imageinfo['mime'];
          }
  
          return $this->create_file_from_string($record, $data);
      }
code_tokens: protected function create_file_preview ( stored_file $ file , $ mode ) { $ mimetype = $ file -> get_mimetype ( ) ; if ( $ mimetype === 'image/gif' or $ mimetype === 'image/jpeg' or $ mimetype === 'image/png' ) { // make a preview of the image $ data = $ this -> create_imagefile_preview ( $ file , $ mode ) ; } else { // unable to create the preview of this mimetype yet return false ; } if ( empty ( $ data ) ) { return false ; } $ context = context_system :: instance ( ) ; $ record = array ( 'contextid' => $ context -> id , 'component' => 'core' , 'filearea' => 'preview' , 'itemid' => 0 , 'filepath' => '/' . trim ( $ mode , '/' ) . '/' , 'filename' => $ file -> get_contenthash ( ) , ) ; $ imageinfo = getimagesizefromstring ( $ data ) ; if ( $ imageinfo ) { $ record [ 'mimetype' ] = $ imageinfo [ 'mime' ] ; } return $ this -> create_file_from_string ( $ record , $ data ) ; }
docstring: Generates a preview image for the stored file
  
  @param stored_file $file the file we want to preview
  @param string $mode preview mode, eg. 'thumb'
  @return stored_file|bool the newly created preview file or false
docstring_tokens: Generates a preview image for the stored file