Esempio n. 1
0
 protected function _thumb($sourceFilename, $targetFilename, $params)
 {
     // recursively create folders
     new Folder(dirname($targetFilename), true);
     // Import phpThumb class
     App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($sourceFilename);
     $phpThumb->w = $params['width'];
     $phpThumb->h = $params['height'];
     $phpThumb->setParameter('zc', $params['zoomCrop']);
     $phpThumb->q = $params['quality'];
     $imageArray = explode(".", $source);
     $phpThumb->config_output_format = $imageArray[1];
     unset($imageArray);
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($targetFilename)) {
             trigger_error('Could not render image to: ' . $targetFilename);
         }
     }
 }
Esempio n. 2
0
 function resize($img, $options, $folder = "", $cache = true)
 {
     $hash = md5($img . serialize($options));
     if (!file_exists($img) || is_dir($img)) {
         $img = PATH_DESIGN . "img" . DS . "nophoto.png";
     }
     $ext = "";
     $phpThumb = new \phpthumb();
     $phpThumb->setSourceFilename($img);
     $phpThumb->setParameter("q", IMAGE_QUALITY_DEFAULT);
     foreach ($options as $key => $value) {
         $phpThumb->setParameter($key, $value);
         if ($key == "f") {
             $ext = $value;
         }
     }
     if ($ext == "") {
         $phpThumb->setParameter("f", "jpg");
         $ext = "jpg";
     }
     if ($folder != "") {
         $tree = explode("/", $folder);
         $path = IMAGE_CACHE_PATH;
         if (is_array($tree)) {
             foreach ($tree as $dir) {
                 $mk = $path . DS . $dir;
                 if (!file_exists($mk)) {
                     mkdir($mk);
                     chmod($mk, 0777);
                 }
                 $path .= DS . $dir;
             }
         }
         $folder .= DS;
     }
     $outputFilename = IMAGE_CACHE_PATH . $folder . $hash . "." . $ext;
     if (!$cache && file_exists($outputFilename)) {
         unlink($outputFilename);
     }
     if (!file_exists($outputFilename)) {
         if ($phpThumb->GenerateThumbnail()) {
             $phpThumb->RenderToFile($outputFilename);
         }
     }
     $res = str_replace(ROOT, "", $outputFilename);
     $res = str_replace(DS, "/", $res);
     return $res;
 }
Esempio n. 3
0
 function render($image, $params)
 {
     //Set defaults
     $path = '';
     $width = 150;
     $height = 225;
     $quality = 75;
     //Extract Parameters
     if (isset($params['path'])) {
         $path = $params['path'] . DS;
     }
     if (isset($params['width'])) {
         $width = $params['width'];
     }
     if (isset($params['height'])) {
         $height = $params['height'];
     }
     if (isset($params['quality'])) {
         $quality = $params['quality'];
     }
     //import phpThumb class
     app::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     $thumbNail = new phpthumb();
     $thumbNail->src = WWW_ROOT . 'img' . DS . $path . $image;
     $thumbNail->w = $width;
     $thumbNail->h = $height;
     $thumbNail->q = $quality;
     $thumbNail->config_imagemagick_path = '/usr/bin/convert';
     $thumbNail->config_prefer_imagemagick = true;
     $thumbNail->config_output_format = 'jpg';
     $thumbNail->config_error_die_on_error = true;
     $thumbNail->config_document_root = '';
     $thumbNail->config_temp_directory = APP . 'tmp';
     $thumbNail->config_cache_directory = WWW_ROOT . 'img' . DS . 'thumbs' . DS;
     $thumbNail->config_cache_disable_warning = true;
     $cacheFilename = $image;
     $thumbNail->cache_filename = $thumbNail->config_cache_directory . $cacheFilename;
     if (!is_file($thumbNail->cache_filename)) {
         if ($thumbNail->GenerateThumbnail()) {
             $thumbNail->RenderToFile($thumbNail->cache_filename);
         }
     }
     if (is_file($thumbNail->cache_filename)) {
         return $cacheFilename;
     }
 }
 /**
  * Ajoute un champ
  *
  * @param string  $field      nom du champ
  * @param string  $value      [optional]
  * @param array   $options    [optional]
  * @param boolean $htmlescape [optional]
  *
  * @return void
  */
 function addProperty($field, $value = null, $options = array(), $htmlescape = true)
 {
     if ($htmlescape) {
         $value = CMbString::htmlSpecialChars($value);
     }
     $sec = explode(' - ', $field, 3);
     switch (count($sec)) {
         case 3:
             $section = $sec[0];
             $item = $sec[1];
             $sub_item = $sec[2];
             break;
         case 2:
             $section = $sec[0];
             $item = $sec[1];
             $sub_item = '';
             break;
         default:
             trigger_error("Error while exploding the string", E_USER_ERROR);
             return;
     }
     if (!array_key_exists($section, $this->sections)) {
         $this->sections[$section] = array();
     }
     if ($sub_item != '' && !array_key_exists($item, $this->sections[$section])) {
         $this->sections[$section][$item] = array();
     }
     if ($sub_item == '') {
         $this->sections[$section][$field] = array("view" => CMbString::htmlEntities($item), "field" => $field, "value" => $value, "fieldHTML" => CMbString::htmlEntities("[{$field}]", ENT_QUOTES), "valueHTML" => $value, "shortview" => $section . " - " . $item, "options" => $options);
     } else {
         $this->sections[$section][$item][$sub_item] = array("view" => CMbString::htmlEntities($sub_item), "field" => $field, "value" => $value, "fieldHTML" => CMbString::htmlEntities("[{$field}]", ENT_QUOTES), "valueHTML" => $value, "shortview" => $section . " - " . $item . " - " . $sub_item, "options" => $options);
     }
     // Barcode
     if (isset($options["barcode"])) {
         if ($sub_item) {
             $_field =& $this->sections[$section][$item][$sub_item];
         } else {
             $_field =& $this->sections[$section][$field];
         }
         if ($this->valueMode) {
             $src = $this->getBarcodeDataUri($_field['value'], $options["barcode"]);
         } else {
             $src = $_field['fieldHTML'];
         }
         $_field["field"] = "";
         if ($options["barcode"]["title"]) {
             $_field["field"] .= $options["barcode"]["title"] . "<br />";
         }
         $_field["field"] .= "<img alt=\"{$field}\" src=\"{$src}\" ";
         foreach ($options["barcode"] as $name => $attribute) {
             $_field["field"] .= " {$name}=\"{$attribute}\"";
         }
         $_field["field"] .= "/>";
     }
     // Custom data
     if (isset($options["data"])) {
         $_field =& $this->sections[$section][$item][$sub_item];
         $data = $options["data"];
         $view = $_field['field'];
         $_field["field"] = "[<span data-data=\"{$data}\">{$view}</span>]";
     }
     // Image (from a CFile object)
     if (isset($options["image"])) {
         $_field =& $this->sections[$section][$field];
         $data = "";
         if ($this->valueMode) {
             $file = new CFile();
             $file->load($_field['value']);
             if ($file->_id) {
                 // Resize the image
                 CAppUI::requireLibraryFile("phpThumb/phpthumb.class");
                 include_once "lib/phpThumb/phpThumb.config.php";
                 $thumbs = new phpthumb();
                 $thumbs->setSourceFilename($file->_file_path);
                 $thumbs->w = 640;
                 $thumbs->f = "png";
                 $thumbs->GenerateThumbnail();
                 $data = "data:" . $file->file_type . ";base64," . urlencode(base64_encode($thumbs->IMresizedData));
             }
         }
         $src = $this->valueMode ? $data : $_field['fieldHTML'];
         $_field["field"] = "<img src=\"" . $src . "\" />";
     }
 }
 /**
  * Function to create Thumbnail images
  *
  * @param object $model Reference to model
  * @param string $source File name (without path)
  * @param string $target File name (without path)
  * @param string $fieldName
  * @param array $params
  * @return void
  * @access protected
  */
 function _createThumbnail(&$model, $source, $target, $fieldName, $params = array())
 {
     $params = array_merge(array('thumbWidth' => 150, 'thumbHeight' => 225, 'maxDimension' => '', 'thumbnailQuality' => $this->__fields[$model->alias][$fieldName]['thumbnailQuality'], 'zoomCrop' => false), $params);
     // Import phpThumb class
     $test = App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($source);
     $phpThumb->config_disable_debug = !Configure::read('debug');
     if ($params['maxDimension'] == 'w') {
         $phpThumb->w = $params['thumbWidth'];
     } else {
         if ($params['maxDimension'] == 'h') {
             $phpThumb->h = $params['thumbHeight'];
         } else {
             $phpThumb->w = $params['thumbWidth'];
             $phpThumb->h = $params['thumbHeight'];
         }
     }
     $phpThumb->setParameter('zc', $this->__fields[$model->alias][$fieldName]['zoomCrop']);
     if (isset($params['zoomCrop'])) {
         $phpThumb->setParameter('zc', $params['zoomCrop']);
     }
     if (isset($params['watermark'])) {
         $phpThumb->fltr = array("wmi|" . IMAGES . $params['watermark'] . "|BR|50|5");
     }
     $phpThumb->q = $params['thumbnailQuality'];
     $imageArray = explode(".", $source);
     $phpThumb->config_output_format = $imageArray[1];
     unset($imageArray);
     $phpThumb->config_prefer_imagemagick = $this->__fields[$model->alias][$fieldName]['useImageMagick'];
     $phpThumb->config_imagemagick_path = $this->__fields[$model->alias][$fieldName]['imageMagickPath'];
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($target)) {
             $this->_addError('Could not render image to: ' . $target);
         }
     }
 }
Esempio n. 6
0
 public static function small($file)
 {
     require_once dirname(__FILE__) . '/../phpthumb/phpthumb.class.php';
     $basefile = new File($file);
     $basepath = File::a2r($file);
     $webimg = dirname($basepath) . "/" . $basefile->name . "_small." . $basefile->extension;
     list($x, $y) = getimagesize($file);
     if ($x <= 1200 && $y <= 1200) {
         return $file;
     }
     $path = File::r2a($webimg, Settings::$thumbs_dir);
     /// Create smaller image
     if (!file_exists($path) || filectime($file) > filectime($path)) {
         if (!file_exists(dirname($path))) {
             @mkdir(dirname($path), 0755, true);
         }
         $thumb = new phpthumb();
         $thumb->config_imagemagick_path = Settings::$imagemagick_path;
         $thumb->setSourceData(file_get_contents($file));
         $thumb->CalculateThumbnailDimensions();
         $thumb->w = 1200;
         $thumb->h = 1200;
         $thumb->q = Settings::$quality_small;
         if (File::Type($file) == 'Image' && Provider::get_orientation_degrees($file) != 0) {
             $thumb->SourceImageToGD();
             //$thumb->ra = Provider::get_orientation_degrees($file);
             $thumb->Rotate();
         }
         $thumb->GenerateThumbnail();
         $thumb->RenderToFile($path);
     }
     return $path;
 }
Esempio n. 7
0
if ($ext == "") {
    $phpThumb->setParameter("f", "jpg");
    $ext = "jpg";
}
if ($folder != "") {
    $tree = explode("/", $folder);
    $path = $_SERVER['DOCUMENT_ROOT'] . "/assets/cache/images";
    if (is_array($tree)) {
        foreach ($tree as $dir) {
            $mk = $path . "/" . $dir;
            if (!file_exists($mk)) {
                mkdir($mk);
                chmod($mk, 0777);
            }
            $path .= "/" . $dir;
        }
    }
    $folder .= "/";
}
$outputFilename = $_SERVER['DOCUMENT_ROOT'] . "/assets/cache/images/" . $folder . $filename . "." . $ext;
if ($cache && file_exists($outputFilename)) {
    unlink($outputFilename);
}
if (!file_exists($outputFilename)) {
    if ($phpThumb->GenerateThumbnail()) {
        $phpThumb->RenderToFile($outputFilename);
    }
}
$res = explode("/assets", $outputFilename);
$res = "/assets" . $res[1];
return $res;
Esempio n. 8
0
 /**
  * Function to create Thumbnail images
  *
  * @param object $model
  * @param string $source Source file name (without path)
  * @param string $target Target file name (without path)
  * @param string $fieldName Path to source and destination (no trailing DS)
  * @param array $params
  * @return void
  * @access protected
  */
 function _createThumbnail(&$model, $source, $target, $fieldName, $params = array())
 {
     $params = array_merge(array('thumbnailQuality' => $this->__fields[$model->alias][$fieldName]['thumbnailQuality'], 'zoomCrop' => false), $params);
     // Import phpThumb class
     App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($source);
     $w = isset($params['width']);
     $h = isset($params['height']);
     if ($w && $h) {
         $phpThumb->w = $params['width'];
         $phpThumb->h = $params['height'];
     } elseif ($w && !$h) {
         $phpThumb->w = $params['width'];
     } elseif ($h && !$w) {
         $phpThumb->h = $params['height'];
     } else {
         trigger_error(__d('meio_upload', 'Width and Height of thumbs not specified.', true), E_USER_WARNING);
         return;
     }
     $phpThumb->setParameter('zc', $params['zoomCrop']);
     $phpThumb->q = $params['thumbnailQuality'];
     list(, $phpThumb->config_output_format) = explode('.', $source, 2);
     $phpThumb->config_prefer_imagemagick = $this->__fields[$model->alias][$fieldName]['useImageMagick'];
     $phpThumb->config_imagemagick_path = $this->__fields[$model->alias][$fieldName]['imageMagickPath'];
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($target)) {
             trigger_error(sprintf(__d('meio_upload', 'Could not render image to: %s', true), $target), E_USER_WARNING);
         }
     }
 }
Esempio n. 9
0
 /**
  * Secure PHP Thumb resizing
  */
 public function thumb($img, $properties)
 {
     $file = $img;
     $ext = end(explode('.', $img));
     $kx = '';
     foreach ($properties as $k => $v) {
         $kx .= $k . $v;
     }
     $dir = PUBLIC_DIR . "images/thumbs/";
     $thumb = $dir . hash_hmac('ripemd160', $img . $kx, 'sThumbz1') . '.' . $ext;
     if (!$properties['q']) {
         $properties['q'] = 100;
     }
     if (file_exists($file) && !file_exists($thumb)) {
         if (!is_dir($dir)) {
             mkdir($dir, 0755, true);
         }
         $phpThumb = new phpthumb();
         $PHPTHUMB_CONFIG = array('document_root' => ROOT_DIR, 'cache_directory' => ROOT_DIR . '../application/plugins/phpThumb/cache/', 'imagemagick_path' => 'C:/Program Files (x86)/ImageMagick-6.7.7-Q16/convert.exe', 'disable_debug' => false);
         foreach ($PHPTHUMB_CONFIG as $key => $value) {
             $keyname = 'config_' . $key;
             $phpThumb->setParameter($keyname, $value);
         }
         $phpThumb->setSourceFilename(ROOT_DIR . $file);
         foreach ($properties as $k => $v) {
             $phpThumb->setParameter($k, $v);
         }
         if ($gt = $phpThumb->GenerateThumbnail()) {
             if ($rt = $phpThumb->RenderToFile(ROOT_DIR . $thumb)) {
                 return $thumb;
             } else {
                 return $img;
             }
         } else {
             return $img;
         }
     } elseif (file_exists($thumb)) {
         /*
          * Thumb was already made!
          */
         return $thumb;
     } else {
         /*
          * Return the original input as no file was found in the ul folder
          */
         return $img;
     }
 }
Esempio n. 10
0
 /**
  * Function to create Thumbnail images
  *
  * @param object $model Reference to model
  * @param string $source File name (without path)
  * @param string $target File name (without path)
  * @param string $fieldName
  * @param array $params
  * @return void
  * @access protected
  */
 function _createThumbnail(&$model, $source, $target, $fieldName, $params = array())
 {
     # zuha added to have a setting for whether to resize or crop
     $zoomCrop = defined('__GALLERY_RESIZE_OR_CROP') && __GALLERY_RESIZE_OR_CROP == 'crop' ? true : false;
     $params = array_merge(array('thumbWidth' => 150, 'thumbHeight' => 225, 'maxDimension' => '', 'thumbnailQuality' => $this->__fields[$model->alias][$fieldName]['thumbnailQuality'], 'zoomCrop' => $zoomCrop), $params);
     // Import phpThumb class
     //App::import('Vendor', 'Galleries.phpThumb', array('file' => 'phpThumb'.DS.'phpthumb.class.php'));
     require_once APP . 'Plugin' . DS . 'Galleries' . DS . 'vendors' . DS . 'phpThumb' . DS . 'phpthumb.class.php';
     // @todo import
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($source);
     if ($params['maxDimension'] == 'w') {
         $phpThumb->w = $params['thumbWidth'];
     } else {
         if ($params['maxDimension'] == 'h') {
             $phpThumb->h = $params['thumbHeight'];
         } else {
             $phpThumb->w = $params['thumbWidth'];
             $phpThumb->h = $params['thumbHeight'];
         }
     }
     $phpThumb->setParameter('zc', $this->__fields[$model->alias][$fieldName]['zoomCrop']);
     if (isset($params['zoomCrop'])) {
         $phpThumb->setParameter('zc', $params['zoomCrop']);
     }
     $phpThumb->q = $params['thumbnailQuality'];
     $imageArray = explode(".", $source);
     $phpThumb->config_output_format = $imageArray[1];
     unset($imageArray);
     $phpThumb->config_prefer_imagemagick = $this->__fields[$model->alias][$fieldName]['useImageMagick'];
     $phpThumb->config_imagemagick_path = $this->__fields[$model->alias][$fieldName]['imageMagickPath'];
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($target)) {
             $this->_addError('Could not render image to: ' . $target);
         }
     }
 }
Esempio n. 11
0
 /**
  * Create a thumbnail, and cache.
  *
  * @return mixed Cached filename returned if thumbnailing was successful. False on error.
  */
 public function createThumb($src, $dest)
 {
     App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     if (!class_exists('phpthumb')) {
         trigger_error(__('phpThumb must be installed in the vendors directory: APP/vendors/phpThumb', true), E_USER_ERROR);
     }
     $phpThumb = new phpthumb();
     $phpThumb->setParameter('src', $src);
     foreach ($this->options as $k => $v) {
         if ($k == 'fltr') {
             // Setup the Filtering as string options.
             foreach ($v as $vk => &$vv) {
                 $vv = $vk . '|' . $vv;
             }
             $phpThumb->setParameter($k, $v);
         } else {
             // All non-filter options
             $phpThumb->setParameter($k, $v);
         }
     }
     @ini_set('max_execution_time', 0);
     if ($phpThumb->GenerateThumbnail()) {
         $phpThumb->RenderToFile('img' . DS . $dest);
         return $dest;
     }
     $this->_error = preg_replace('/[^A-Za-z0-9\\/: .]/', '', $phpThumb->fatalerror);
     $this->_error = preg_replace('/phpThumb v[0-9\\.\\-]+/', '', $this->_error);
     return false;
 }
Esempio n. 12
0
 * @version  SVN: $Id:\$
 * @link     http://www.mediboard.org
 */
include_once 'lib/phpThumb/phpThumb.config.php';
CAppUI::requireLibraryFile("phpThumb/phpthumb.class");
$file_id = CValue::get("file_id");
$index = CValue::get("index");
$file = new CFile();
$file->load($file_id);
// Si le pdf a été supprimé ou vidé car on ferme la popup sans enregistrer
// le document, alors on ne génère pas la vignette
if (!$file->_id || !file_exists($file->_file_path) || file_get_contents($file->_file_path) == "") {
    return;
}
// Traitement de la vignette
$thumbs = new phpthumb();
// Il faut inclure manuellement la configuration dans l'objet phpThumbs
if (!empty($PHPTHUMB_CONFIG)) {
    foreach ($PHPTHUMB_CONFIG as $key => $value) {
        $keyname = 'config_' . $key;
        $thumbs->setParameter($keyname, $value);
    }
}
$thumbs->setSourceFilename($file->_file_path);
$vignette = null;
$thumbs->sfn = $index;
$thumbs->w = 138;
$thumbs->f = "png";
$thumbs->GenerateThumbnail();
$vignette = base64_encode($thumbs->IMresizedData);
echo json_encode($vignette);
Esempio n. 13
0
        ob_end_clean();
        if (ini_get('allow_url_fopen')) {
            $phpthumb->ErrorImage('cannot open "' . $HTTPurl . '" - fopen() said: "' . $fopen_error . '"');
        } else {
            $phpthumb->ErrorImage('"allow_url_fopen" disabled');
        }
    }
    ob_end_clean();
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
if (@$_GET['phpthumbDebug'] == '7') {
    $phpthumb->phpthumbDebug();
}
////////////////////////////////////////////////////////////////
$phpthumb->GenerateThumbnail();
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
if (@$_GET['phpthumbDebug'] == '8') {
    $phpthumb->phpthumbDebug();
}
////////////////////////////////////////////////////////////////
if ($phpthumb->file) {
    $phpthumb->RenderToFile($phpthumb->ResolveFilenameToAbsolute($phpthumb->file));
    if ($phpthumb->goto && substr(strtolower($phpthumb->goto), 0, strlen('http://')) == 'http://') {
        // redirect to another URL after image has been rendered to file
        header('Location: ' . $phpthumb->goto);
        exit;
    }
} else {
    if (file_exists($phpthumb->cache_filename) && is_writable($phpthumb->cache_filename) || is_writable(dirname($phpthumb->cache_filename))) {