/**
  * Render the thumbnail
  * @return mixed|string
  */
 public function render()
 {
     $this->getCacheFilename();
     $this->getCacheUrl();
     $this->cleanCache();
     $this->phpThumbOf->startDebug();
     /* if using s3, check for file there */
     $useS3 = $this->modx->getOption('useS3', $this->config, false);
     if ($useS3) {
         $expired = $this->checkForS3Cache();
         if ($expired !== true) {
             return $expired;
         }
     }
     $this->checkCacheFilePermissions();
     $this->phpThumbOf->endDebug();
     if ($cacheUrl = $this->checkForCachedFile()) {
         return $cacheUrl;
     }
     /* actually make the thumbnail */
     if ($this->phpThumb->GenerateThumbnail()) {
         // this line is VERY important, do not remove it!
         if ($this->phpThumb->RenderToFile($this->cacheKey)) {
             $this->checkCacheFilePermissions();
             if ($useS3) {
                 $this->cacheUrl = $this->pushToS3();
             }
             return str_replace(' ', '%20', $this->cacheUrl);
         } else {
             $this->modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not cache thumb "' . $this->input . '" to file at: ' . $this->cacheKey . ' - Debug: ' . print_r($this->phpThumb->debugmessages, true));
         }
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not generate thumbnail: ' . $this->input . ' - Debug: ' . print_r($this->phpThumb->debugmessages, true));
     }
     return '';
 }