/**
  * Attempt to load modPhpThumb
  * 
  * @return bool|modPhpThumb
  */
 public function loadPhpThumb()
 {
     if (!$this->modx->loadClass('modPhpThumb', $this->modx->getOption('core_path') . 'model/phpthumb/', true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not load modPhpThumb class.');
         return false;
     }
     $this->phpThumb = new modPhpThumb($this->modx, $this->getProperties());
     /* do initial setup */
     $this->phpThumb->initialize();
     return $this->phpThumb;
 }
 /**
  * @param array $options
  *
  * @return bool|null
  */
 public function makeThumbnail($options = array())
 {
     $phpThumb = new modPhpThumb($this->xpdo);
     $phpThumb->initialize();
     $tf = tempnam(MODX_BASE_PATH, 'ms_');
     file_put_contents($tf, $this->file['content']);
     $phpThumb->setSourceFilename($tf);
     foreach ($options as $k => $v) {
         $phpThumb->setParameter($k, $v);
     }
     if ($phpThumb->GenerateThumbnail()) {
         ImageInterlace($phpThumb->gdimg_output, true);
         if ($phpThumb->RenderOutput()) {
             @unlink($phpThumb->sourceFilename);
             @unlink($tf);
             return $phpThumb->outputImageData;
         }
     } else {
         $this->xpdo->log(modX::LOG_LEVEL_ERROR, 'Could not generate thumbnail for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1));
     }
     return false;
 }
 /**
  * @param array $options
  * @param array $info
  *
  * @return bool|null
  */
 public function makeThumbnail($options = array(), array $info)
 {
     if (!class_exists('modPhpThumb')) {
         /** @noinspection PhpIncludeInspection */
         require MODX_CORE_PATH . 'model/phpthumb/modphpthumb.class.php';
     }
     /** @noinspection PhpParamsInspection */
     $phpThumb = new modPhpThumb($this->xpdo);
     $phpThumb->initialize();
     $tf = tempnam(MODX_BASE_PATH, 'ms2g_');
     file_put_contents($tf, $info['content']);
     $phpThumb->setSourceFilename($tf);
     foreach ($options as $k => $v) {
         $phpThumb->setParameter($k, $v);
     }
     if ($phpThumb->GenerateThumbnail()) {
         ImageInterlace($phpThumb->gdimg_output, true);
         if ($phpThumb->RenderOutput()) {
             @unlink($phpThumb->sourceFilename);
             @unlink($tf);
             $this->xpdo->log(modX::LOG_LEVEL_INFO, '[ms2Gallery] phpThumb messages for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1));
             return $phpThumb->outputImageData;
         }
     }
     @unlink($phpThumb->sourceFilename);
     @unlink($tf);
     $this->xpdo->log(modX::LOG_LEVEL_ERROR, '[ms2Gallery] Could not generate thumbnail for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1));
     return false;
 }
 /**
  * Creates the thumbnail file provided if it doesn't already exist based on the $options array.
  *
  * @param string $file absolute path to the thumbnail
  * @param array $options key/value options passed to modPhpThumb
  * @return bool true if thumb already exists or gets created, false if there is an error
  */
 protected function create_thumb($file, $options)
 {
     if ($this->check_if_exists($file, $options['src'])) {
         return true;
     }
     if (!$this->check_cache_dir()) {
         return false;
     }
     if (!$this->modx->loadClass('modPhpThumb', $this->modx->getOption('core_path') . 'model/phpthumb/', true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbsUp] Could not load modPhpThumb class.');
         return false;
     }
     // NOTE: there's a bug in modPhpThumb that doesn't generate the path correctly when in the manager
     //       context, so we have to manually prepend a slash to the src path if in the mgr context
     if ($this->modx->context->key == 'mgr') {
         $options['src'] = '/' . $options['src'];
     }
     $pt = new modPhpThumb($this->modx);
     $pt->config = array_merge($pt->config, $options);
     $pt->initialize();
     $pt->GenerateThumbnail();
     $pt->RenderToFile($file);
     return true;
 }
Exemple #5
0
                $src = '/'.$src;
            } else {
                return '';
            }
        }
    }
}

/* load phpThumb */
if (!$modx->loadClass('modPhpThumb',$modx->getOption('core_path').'model/phpthumb/',true,true)) {
    $modx->log(modX::LOG_LEVEL_ERROR,'Could not load modPhpThumb class.');
    return '';
}
$phpThumb = new modPhpThumb($modx,$scriptProperties);
/* do initial setup */
$phpThumb->initialize();
/* set source and generate thumbnail */
$phpThumb->set($src);

/* check to see if there's a cached file of this already */
if ($phpThumb->checkForCachedFile()) {
    $phpThumb->loadCache();
    return '';
}

/* generate thumbnail */
$phpThumb->generate();

/* cache the thumbnail and output */
$phpThumb->cache();
$phpThumb->output();
 /**
  * Generate a thumbnail with a random name for an image.
  *
  * @access public
  * @param array $fileInfo An array of file information.
  * @return string html file list to prefill the template
  */
 public function generateThumbnail($fileInfo = array())
 {
     if (file_exists($fileInfo['path'] . $fileInfo['uniqueName'])) {
         if (!isset($fileInfo['thumbName'])) {
             $path_info = pathinfo($fileInfo['uniqueName']);
             $thumbOptions = array();
             if (in_array(strtolower($path_info['extension']), array('jpg', 'jpeg', 'png', 'gif'))) {
                 $thumbOptions['src'] = $fileInfo['path'] . $fileInfo['uniqueName'];
                 if ($this->config['thumbX']) {
                     $thumbOptions['w'] = $this->config['thumbX'];
                 }
                 if ($this->config['thumbY']) {
                     $thumbOptions['h'] = $this->config['thumbY'];
                 }
                 if ($this->config['thumbX'] && $this->config['thumbY']) {
                     $thumbOptions['zc'] = '1';
                 }
             } else {
                 $thumbOptions['src'] = $this->config['assetsPath'] . '/images/generic.png';
                 $thumbOptions['aoe'] = '1';
                 $thumbOptions['fltr'] = array('wmt|' . strtoupper($path_info['extension']) . '|5|C|000000');
                 if ($this->config['thumbX']) {
                     $thumbOptions['w'] = $this->config['thumbX'];
                 }
                 if ($this->config['thumbY']) {
                     $thumbOptions['h'] = $this->config['thumbY'];
                 }
                 if ($this->config['thumbX'] && $this->config['thumbY']) {
                     $thumbOptions['zc'] = '1';
                 }
                 $thumbOptions['f'] = 'png';
                 $path_info['extension'] = 'png';
             }
             $thumbName = md5($path_info['basename'] . time() . '.thumb') . '.' . $path_info['extension'];
             // generate Thumbnail & save it
             $phpThumb = new modPhpThumb($this->modx, $thumbOptions);
             $phpThumb->initialize();
             if ($phpThumb->GenerateThumbnail()) {
                 if (!$phpThumb->RenderToFile($fileInfo['path'] . $thumbName)) {
                     $this->modx->log(modX::LOG_LEVEL_ERROR, 'Thumbnail generation: Thumbnail not saved.' . "\nDebugmessages:\n" . implode("\n", $phpThumb->debugmessages), '', 'AjaxUpload');
                     $this->debug[] = 'Thumbnail generation: Thumbnail not saved.' . "\nDebugmessaes:\n" . implode("\n", $phpThumb->debugmessages);
                 } else {
                     $filePerm = (int) $this->config['newFilePermissions'];
                     if (!@chmod($fileInfo['path'] . $thumbName, octdec($filePerm))) {
                         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not change the thumbnail file permission.', '', 'AjaxUpload');
                     }
                 }
             } else {
                 $this->modx->log(modX::LOG_LEVEL_ERROR, 'Thumbnail generation: Thumbnail not created.' . "\nDebugmessages:\n" . implode("\n", $phpThumb->debugmessages), '', 'AjaxUpload');
                 $this->debug[] = 'Thumbnail generation: Thumbnail not created.' . "\nDebugmessaes:\n" . implode("\n", $phpThumb->debugmessages);
             }
             $fileInfo['thumbName'] = $thumbName;
         }
         return $fileInfo['thumbName'];
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Thumbnail generation: Original file not found.', '', 'AjaxUpload');
         $this->debug[] = 'Thumbnail generation: Original file not found';
         return false;
     }
 }
 /**
  * Startup the phpThumb service. Must run setInput and setOptions first.
  */
 public function initializeService()
 {
     $this->phpThumb->config = array_merge($this->phpThumb->config, $this->options);
     $this->phpThumb->initialize();
     $this->phpThumb->setParameter('config_cache_directory', $this->config['cachePath']);
     $this->phpThumb->setParameter('config_allow_src_above_phpthumb', true);
     $this->phpThumb->setParameter('allow_local_http_src', true);
     $this->phpThumb->setParameter('config_document_root', $this->modx->context->getOption('base_path', MODX_BASE_PATH, $this->config));
     $this->phpThumb->setCacheDirectory();
     $this->phpThumb->set($this->input);
 }
 /**
  * @param array $options
  * @param null $raw
  *
  * @return bool|null
  */
 protected function _phpThumb(array $options = array(), $raw = null)
 {
     if ($this->get('type') != 'image') {
         return false;
     } elseif (!class_exists('modPhpThumb')) {
         /** @noinspection PhpIncludeInspection */
         require MODX_CORE_PATH . 'model/phpthumb/modphpthumb.class.php';
     }
     if (empty($raw)) {
         $prepare = $this->prepareSource();
         if ($prepare !== true) {
             return $prepare;
         }
         $filename = $this->get('path') . $this->get('file');
         $info = $this->mediaSource->getObjectContents($filename);
         if (!is_array($info)) {
             return "Could not retrieve contents of file {$filename} from media source.";
         } elseif (!empty($this->mediaSource->errors['file'])) {
             return "Could not retrieve file {$filename} from media source: " . $this->mediaSource->errors['file'];
         }
         $raw = $info['content'];
     }
     $phpThumb = new modPhpThumb($this->xpdo);
     $phpThumb->initialize();
     $tmp = tempnam(MODX_BASE_PATH, 'uf_');
     file_put_contents($tmp, $raw);
     $phpThumb->setSourceFilename($tmp);
     foreach ($options as $k => $v) {
         $phpThumb->setParameter($k, $v);
     }
     if ($phpThumb->GenerateThumbnail()) {
         ImageInterlace($phpThumb->gdimg_output, true);
         if ($phpThumb->RenderOutput()) {
             @unlink($phpThumb->sourceFilename);
             @unlink($tmp);
             $this->xpdo->log(modX::LOG_LEVEL_INFO, '[Uploadify] phpThumb messages for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1));
             return $phpThumb->outputImageData;
         }
     }
     @unlink($phpThumb->sourceFilename);
     @unlink($tmp);
     $this->xpdo->log(modX::LOG_LEVEL_ERROR, '[Uploadify] Could not resize "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1));
     return false;
 }