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); } } }
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; }
/** * 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); } } }
function generateThumbnail($saveAs, $options) { $destination = WWW_ROOT . $options['directory'] . DS . basename($saveAs); $ext = substr(basename($saveAs), strrpos(basename($saveAs), '.') + 1); if ($ext == '.jpg' || $ext == '.jpeg') { $format = 'jpeg'; } elseif ($ext == 'png') { $format = 'png'; } elseif ($ext == 'gif') { $format = 'gif'; } else { $format = 'jpeg'; } $phpThumb = new phpthumb(); $phpThumb->setSourceFilename($saveAs); $phpThumb->setCacheDirectory(CACHE); $phpThumb->setParameter('w', $options['width']); if (!empty($option['height'])) { $phpThumb->setParameter('h', $options['height']); } $phpThumb->setParameter('f', $format); if (!empty($options['phpThumb'])) { foreach ($options['phpThumb'] as $name => $value) { if (!empty($value)) { $phpThumb->setParameter($name, $value); } } } if ($phpThumb->generateThumbnail()) { if ($phpThumb->RenderToFile($destination)) { chmod($destination, 0644); return true; } else { return false; } } else { return false; } }
*/ //return $img; $replace = array("," => "&", "_" => "="); $options = strtr($opt, $replace); $filename = md5($img . $options); $cache = isset($cache) ? $cache : false; if ($img[0] != "/") { $img = "/" . $img; } $nophoto = isset($nophoto) ? $nophoto : "logo.png"; if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $img) || is_dir($_SERVER['DOCUMENT_ROOT'] . $img)) { $img = "/images/" . $nophoto; } require_once dirname(__FILE__) . "/phpthumb.class.php"; $phpThumb = new phpthumb(); $phpThumb->setSourceFilename($img); $options = explode("&", $options); foreach ($options as $value) { $thumb = explode("=", $value); $phpThumb->setParameter($thumb[0], $thumb[1]); if ($thumb[0] == "f") { $ext = $thumb[1]; } } if ($ext == "") { $phpThumb->setParameter("f", "jpg"); $ext = "jpg"; } if ($folder != "") { $tree = explode("/", $folder); $path = $_SERVER['DOCUMENT_ROOT'] . "/assets/cache/images";
$tmpImagesFolder = str_replace("assets/images", "", $tmpImagesFolder); $tmpImagesFolder = explode("/", $tmpImagesFolder); $ext = strtolower($path_parts['extension']); $options = 'f=' . (in_array($ext, explode(",", "png,gif")) ? $ext : "jpg&q=96") . '&' . strtr($options, array("," => "&", "_" => "=", '{' => '[', '}' => ']')); parse_str($options, $params); foreach ($tmpImagesFolder as $folder) { if (!empty($folder)) { $cacheFolder .= "/" . $folder; if (!is_dir(MODX_BASE_PATH . $cacheFolder)) { mkdir(MODX_BASE_PATH . $cacheFolder); } } } $fname_preffix = $cacheFolder . "/" . $params['w'] . "x" . $params['h'] . '-'; $fname = $path_parts['filename'] . "." . substr(md5(serialize($params)), 0, 3) . "." . $params['f']; $outputFilename = MODX_BASE_PATH . $fname_preffix . $fname; if (!file_exists($outputFilename)) { require_once MODX_BASE_PATH . 'assets/snippets/phpthumb/phpthumb.class.php'; $phpThumb = new phpthumb(); $phpThumb->config_temp_directory = $tmpFolder; $phpThumb->setSourceFilename(MODX_BASE_PATH . $input); foreach ($params as $key => $value) { $phpThumb->setParameter($key, $value); } if ($phpThumb->GenerateThumbnail()) { $phpThumb->RenderToFile($outputFilename); } else { $modx->logEvent(0, 3, implode('<br/>', $phpThumb->debugmessages), 'phpthumb'); } } return $fname_preffix . rawurlencode($fname);
/** * 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); } } }
/** * 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; } }
* @author Agel_Nash <*****@*****.**> */ if (!defined('MODX_BASE_PATH')) { die('What are you doing? Get out of here!'); } //[[phpthumb? &input=`[+tvimagename+]` &options=`w_255,h=200`]] if ($input == '' || !file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $input)) { return 'assets/snippets/phpthumb/noimage.png'; } else { $replace = array("," => "&", "_" => "="); $options = strtr($options, $replace); $opt = $options; $path_parts = pathinfo($input); require_once MODX_BASE_PATH . "/assets/snippets/phpthumb/phpthumb.class.php"; $phpThumb = new phpthumb(); $phpThumb->setSourceFilename($input); $options = explode("&", $options); $allow = array('f' => 'jpg', 'q' => '96'); $need = array_keys($allow); foreach ($options as $value) { $thumb = explode("=", $value); if (in_array($thumb[0], $need)) { $opt .= "&" . $thumb[0] . "=" . $thumb[1]; unset($allow[$thumb[0]]); } $phpThumb->setParameter($thumb[0], $thumb[1]); $op[$thumb[0]] = $thumb[1]; } foreach ($allow as $key => $value) { $opt .= "&" . $key . "=" . $value; $phpThumb->setParameter($key, $value);
/** * 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); } } }
* @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);
foreach ($config['modphpthumb'] as $param => $value) { // add MODX system settings $phpThumb->{$param} = $value; } foreach ($ptOptions as $param => $value) { // add options passed to the snippet $phpThumb->setParameter($param, $value); } // try to avert problems when $_SERVER['DOCUMENT_ROOT'] is different than MODX_BASE_PATH if (!$phpThumb->config_document_root) { $phpThumb->config_document_root = MODX_BASE_PATH; // default if nothing set from system settings } $phpThumb->config_cache_directory = $assetsPath . 'cache/'; // doesn't matter, but saves phpThumb some frustration $phpThumb->setSourceFilename($src); /* setup cache filename that is unique to this tag */ $inputSanitized = str_replace(array(':', '/'), '_', $src); $cacheFilename = $inputSanitized; $cacheFilename .= '.' . md5(serialize($scriptProperties)); $cacheFilename .= '.' . (!empty($ptOptions['f']) ? $ptOptions['f'] : 'png'); $cacheKey = $assetsPath . 'cache/' . $cacheFilename; /* get cache Url */ $assetsUrl = $modx->getOption('gallery.assets_url', $scriptProperties, $modx->getOption('assets_url') . 'components/gallery/'); $cacheUrl = $assetsUrl . 'cache/' . str_replace($cacheDir, '', $cacheKey); $cacheUrl = str_replace('//', '/', $cacheUrl); /* ensure we have an accurate and clean cache directory */ $phpThumb->CleanUpCacheDirectory(); /* debugging code */ if ($debug) { $mtime = microtime();