本文整理汇总了PHP中phpThumb::setSourceFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP phpThumb::setSourceFilename方法的具体用法?PHP phpThumb::setSourceFilename怎么用?PHP phpThumb::setSourceFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpThumb
的用法示例。
在下文中一共展示了phpThumb::setSourceFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: spit_phpthumb_image
function spit_phpthumb_image($filepath, $configarray = array())
{
// set up class
global $CFG, $PHPTHUMB_CONFIG;
$phpThumb = new phpThumb();
// import default config
if (!empty($PHPTHUMB_CONFIG)) {
foreach ($PHPTHUMB_CONFIG as $key => $value) {
$keyname = 'config_' . $key;
$phpThumb->setParameter($keyname, $value);
}
}
// import passed params
if (!empty($configarray)) {
foreach ($configarray as $key => $value) {
$keyname = $key;
$phpThumb->setParameter($keyname, $value);
}
}
$phpThumb->setSourceFilename($filepath);
if (!is_file($phpThumb->sourceFilename) && !phpthumb_functions::gd_version()) {
if (!headers_sent()) {
// base64-encoded error image in GIF format
$ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
header('Content-Type: image/gif');
echo base64_decode($ERROR_NOGD);
} else {
echo '*** ERROR: No PHP-GD support available ***';
}
exit;
}
$phpThumb->SetCacheFilename();
if (!file_exists($phpThumb->cache_filename) && is_writable(dirname($phpThumb->cache_filename))) {
// error_log("generating to cache: " . $phpThumb->cache_filename);
$phpThumb->CleanUpCacheDirectory();
$phpThumb->GenerateThumbnail();
$phpThumb->RenderToFile($phpThumb->cache_filename);
}
if (is_file($phpThumb->cache_filename)) {
// error_log("sending from cache: " . $phpThumb->cache_filename);
if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
$mimetype = phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]);
}
spitfile_with_mtime_check($phpThumb->cache_filename, $mimetype);
} else {
// error_log("phpthumb cache file doesn't exist: " . $phpThumb->cache_filename);
$phpThumb->GenerateThumbnail();
$phpThumb->OutputThumbnail();
exit;
}
}
示例2: thumbnail
public static function thumbnail($image_path, $thumb_path, $image_name, $thumbnail_width = 0, $thumbnail_height = 0)
{
require_once JPATH_ROOT . '/jelibs/phpthumb/phpthumb.class.php';
// create phpThumb object
$phpThumb = new phpThumb();
// this is very important when using a single object to process multiple images
$phpThumb->resetObject();
// set data source
$phpThumb->setSourceFilename($image_path . DS . $image_name);
// set parameters (see "URL Parameters" in phpthumb.readme.txt)
if ($thumbnail_width) {
$phpThumb->setParameter('w', $thumbnail_width);
}
if ($thumbnail_height) {
$phpThumb->setParameter('h', $thumbnail_height);
}
$phpThumb->setParameter('zc', 'l');
// set parameters
$phpThumb->setParameter('config_output_format', 'jpeg');
// generate & output thumbnail
$output_filename = str_replace('/', DS, $thumb_path) . DS . 't-' . $thumbnail_width . 'x' . $thumbnail_height . '-' . $image_name;
# .'_'.$thumbnail_width.'.'.$phpThumb->config_output_format;
$capture_raw_data = false;
if ($phpThumb->GenerateThumbnail()) {
// $output_size_x = ImageSX($phpThumb->gdimg_output);
// $output_size_y = ImageSY($phpThumb->gdimg_output);
// if ($output_filename || $capture_raw_data) {
//// if ($capture_raw_data && $phpThumb->RenderOutput()) {
//// // RenderOutput renders the thumbnail data to $phpThumb->outputImageData, not to a file or the browser
//// mysql_query("INSERT INTO `table` (`thumbnail`) VALUES ('".mysql_escape_string($phpThumb->outputImageData)."') WHERE (`id` = '".$id."')");
//// } elseif ($phpThumb->RenderToFile($output_filename)) {
//// // do something on success
//// echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
//// } else {
//// // do something with debug/error messages
//// echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
//// }
// $phpThumb->purgeTempFiles();
// } else {
$phpThumb->RenderToFile($output_filename);
// }
} else {
// do something with debug/error messages
// echo 'Failed (size='.$thumbnail_width.').<br>';
// echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">'.$phpThumb->fatalerror.'</div>';
// echo '<form><textarea rows="10" cols="60" wrap="off">'.htmlentities(implode("\n* ", $phpThumb->debugmessages)).'</textarea></form><hr>';
}
return $output_filename;
}
示例3: resizeImage
/**
* Resize an image
*
* Looks like a private function to me, but could be used as it is
*
* @param $filename String Nom du fichier
* @param $options Array Can override $settings and add these options :
* output : relative to 'folder' output image filename (default : $filename (overwrite))
* delete_source : if output is different from input, this set to true will delete the source file (default : false)
* @return Returns true in case of success, false otherwise ($this->errors[$Model->name] gets populated)
*/
function resizeImage(&$Model, $filepath, $options = array())
{
if (!file_exists($filepath)) {
$this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $filepath . __(' n\'existe pas.', true);
return false;
}
$settings = am(am($this->settings[$Model->name]['default'], array('output' => $filepath, 'delete_source' => false)), $options);
App::import('Vendor', 'phpThumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($filepath);
$phpThumb->setParameter('w', $settings['width']);
$phpThumb->setParameter('h', $settings['height']);
if ($settings['zoomcrop'] === true) {
//$phpThumb->setParameter('zc', 1);
}
if (!(0 == $settings['sx'] && 0 == $settings['sy'] && 0 == $settings['sw'] && 0 == $settings['sh'])) {
$phpThumb->setParameter('sx', $settings['sx']);
$phpThumb->setParameter('sy', $settings['sy']);
$phpThumb->setParameter('sw', $settings['sw']);
$phpThumb->setParameter('sh', $settings['sh']);
if ($settings['aoe']) {
$phpThumb->setParameter('aoe', 1);
}
}
if (isset($settings['f'])) {
$phpThumb->setParameter('f', $settings['f']);
}
if (!$phpThumb->generateThumbnail()) {
/* Woopsy, the image couldn't be resized */
debug($phpThumb->debugmessages);
$this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $filepath . __(' n\'a pas pu être resizé', true);
return false;
}
if (!$phpThumb->RenderToFile($settings['output'])) {
/* File couldn't be created */
$this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $settings['folder'] . $settings['output'] . __(' n\'a pas pu être créé', true);
return false;
}
if ($settings['delete_source'] && $settings['output'] != $filepath) {
if (!unlink($filepath)) {
$this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $filepath . __(' n\'a pas pu être supprimé', true);
return false;
}
}
return true;
}
示例4: image_resize
function image_resize($image, $width, $height, $quality, $input_directory, $output_directory)
{
$cache_dir = 'cache/';
if ($input_directory !== '') {
$source = $input_directory . $image;
} else {
$source = $image;
}
if ($output_directory !== '') {
$target = $output_directory . $image;
} else {
$target = $image;
}
include_once DIR_FS_CATALOG . 'ext/phpthumb/phpthumb.class.php';
// create phpThumb object
$phpThumb = new phpThumb();
// set data source -- do this first, any settings must be made AFTER this call
$phpThumb->setSourceFilename($source);
// set parameters (see "URL Parameters" in phpthumb.readme.txt)
$phpThumb->setParameter('config_cache_directory', $cache_dir);
if ($width !== '') {
$phpThumb->setParameter('w', $width);
} else {
$phpThumb->setParameter('h', $height);
}
if ($quality !== '') {
$phpThumb->setParameter('q', $quality);
}
// generate & output thumbnail
if ($phpThumb->GenerateThumbnail()) {
// this line is VERY important, do not remove it!
if ($phpThumb->RenderToFile($target)) {
// do something on success
// echo 'Successfully rendered to "'.$image.'"';
} else {
// do something with debug/error messages
echo 'Failed:<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
}
} else {
// do something with debug/error messages
echo 'Failed:<pre>' . $phpThumb->fatalerror . "\n\n" . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
}
// return $output;
}
示例5: get_image
function get_image($fieldName, $groupIndex = 1, $fieldIndex = 1, $tag_img = 1)
{
require_once "RCCWP_CustomField.php";
global $wpdb, $post, $FIELD_TYPES;
$fieldID = RCCWP_CustomField::GetIDByName($fieldName);
$fieldObject = GetFieldInfo($fieldID);
$fieldType = $wpdb->get_var("SELECT type FROM " . RC_CWP_TABLE_GROUP_FIELDS . " WHERE id='" . $fieldID . "'");
$single = true;
switch ($fieldType) {
case $FIELD_TYPES["checkbox_list"]:
case $FIELD_TYPES["listbox"]:
$single = false;
break;
}
$fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
if (!empty($fieldValues[0])) {
$fieldValue = $fieldValues[0];
} else {
return "";
}
$url_params = explode("&", $fieldValue, 2);
if (count($url_params) >= 2) {
$fieldObject->properties['params'] .= "&" . $url_params[1];
$fieldValue = $url_params[0];
}
if (substr($fieldObject->properties['params'], 0, 1) == "?") {
$fieldObject->properties['params'] = substr($fieldObject->properties['params'], 1);
}
//check if exist params, if not exist params, return original image
if (empty($fieldObject->properties['params']) && FALSE == strstr($fieldValue, "&")) {
$fieldValue = FLUTTER_FILES_URI . $fieldValue;
} else {
//check if exist thumb image, if exist return thumb image
$md5_params = md5($fieldObject->properties['params']);
if (file_exists(FLUTTER_FILES_PATH . 'th_' . $md5_params . "_" . $fieldValue)) {
$fieldValue = FLUTTER_FILES_URI . 'th_' . $md5_params . "_" . $fieldValue;
} else {
//generate thumb
//include_once(FLUTTER_URI_RELATIVE.'thirdparty/phpthumb/phpthumb.class.php');
include_once dirname(__FILE__) . "/thirdparty/phpthumb/phpthumb.class.php";
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename(FLUTTER_FILES_PATH . $fieldValue);
$create_md5_filename = 'th_' . $md5_params . "_" . $fieldValue;
$output_filename = FLUTTER_FILES_PATH . $create_md5_filename;
$final_filename = FLUTTER_FILES_URI . $create_md5_filename;
$params_image = explode("&", $fieldObject->properties['params']);
foreach ($params_image as $param) {
if ($param) {
$p_image = explode("=", $param);
$phpThumb->setParameter($p_image[0], $p_image[1]);
}
}
if ($phpThumb->GenerateThumbnail()) {
if ($phpThumb->RenderToFile($output_filename)) {
$fieldValue = $final_filename;
}
}
}
}
if ($tag_img) {
$cssClass = $wpdb->get_results("SELECT CSS FROM " . RC_CWP_TABLE_GROUP_FIELDS . " WHERE name='" . $fieldName . "'");
if (empty($cssClass[0]->CSS)) {
$finalString = stripslashes(trim("\\<img src=\\'" . $fieldValue . "\\' /\\>"));
} else {
$finalString = stripslashes(trim("\\<img src=\\'" . $fieldValue . "\\' class=\"" . $cssClass[0]->CSS . "\" \\/\\>"));
}
} else {
$finalString = $fieldValue;
}
return $finalString;
}
示例6: _thumbnail
private function _thumbnail($maxwidth, $maxheight, $crop = false, $quality = 90)
{
$stack = $this->stack ? $this->stack : $this->resultset->get_stack();
if (!isset($this->thumbnails)) {
$this->thumbnails = array();
} else {
if (is_string($this->thumbnails)) {
$this->thumbnails = array_filter(explode(';', $this->thumbnails));
}
}
$slugname = 'slug_' . language();
if (isset($this->{$slugname})) {
$this->slug = $this->{$slugname};
}
$file_path = get_file_directory(str_replace('>', '/', $stack));
$file_url = get_file_url(str_replace('>', '/', $stack));
$target = $this->id . '-' . intval($maxwidth) . 'x' . intval($maxheight);
$extension = strtolower(substr($this->filename, strrpos($this->filename, '.') + 1));
$file = $this->slug . '-' . $this->id . '-' . intval($maxwidth) . '-' . intval($maxheight);
$thumbcheck = language() . intval($maxwidth) . 'x' . intval($maxheight) . ($crop ? 'c' : '');
if ($crop) {
$file .= '-c';
$target .= '-c';
}
$file .= '.' . $extension;
$target .= '.' . $extension;
if (!in_array($thumbcheck, $this->thumbnails)) {
$valid = true;
if (strstr($this->filename, '://')) {
if (!fopen($this->filename, "r")) {
$valid = false;
}
} else {
if (strstr($this->filename, $_SERVER['DOCUMENT_ROOT'])) {
if (!file_exists($this->filename)) {
$valid = false;
}
} else {
if (!$this->filename || !file_exists(FILESPATH . $this->filename)) {
$valid = false;
}
}
}
if (!$valid) {
$this->filename = BASEPATH . 'nopic.jpg';
$file = $this->id . '-nopic-' . intval($maxwidth) . 'x' . intval($maxheight);
$target = $this->id . '-nopic-' . intval($maxwidth) . 'x' . intval($maxheight);
if ($crop) {
$file .= '-c';
$target .= '-c';
}
$file .= '.' . $extension;
$target .= '.' . $extension;
}
require_once 'phpthumb/phpthumb.class.php';
$phpThumb = new phpThumb();
if (strstr($this->filename, '://') || strstr($this->filename, $_SERVER['DOCUMENT_ROOT'])) {
$phpThumb->setSourceFilename($this->filename);
} else {
$phpThumb->setSourceFilename(FILESPATH . $this->filename);
}
$phpThumb->setParameter('w', $maxwidth);
$phpThumb->setParameter('h', $maxheight);
$phpThumb->setParameter('f', strtolower($extension));
if (is_numeric($quality)) {
$phpThumb->setParameter('q', $quality);
} else {
$bytes = intval($quality);
if (stristr($quality, 'mb')) {
$bytes *= 1024 * 1024;
} else {
if (stristr($quality, 'kb')) {
$bytes *= 1024;
}
}
$phpThumb->setParameter('maxb', $bytes);
}
if ($crop) {
$phpThumb->setParameter('zc', true);
$phpThumb->setParameter('aoe', 1);
$phpThumb->setParameter('far', 'C');
}
$output_filename = $file_path . $target;
$success = false;
if (file_exists($output_filename)) {
$success = true;
} else {
if ($phpThumb->GenerateThumbnail()) {
$success = $phpThumb->RenderToFile($output_filename);
}
}
if ($success) {
@symlink($file_path . $target, $file_path . $file);
if (!$this->path && $this->resultset) {
$this->path = $this->resultset->get_stack();
}
if ($this->id && $this->thumbnails_field && $this->path) {
$this->thumbnails[] = $thumbcheck;
where('id = %d', $this->id)->update($this->path, array($this->thumbnails_field => implode(';', $this->thumbnails)));
}
//.........这里部分代码省略.........
示例7: file_cache_save_thumbnail_file
function file_cache_save_thumbnail_file($file_cache_r, &$errors)
{
$file_type_r = fetch_file_type_r($file_cache_r['content_type']);
if ($file_type_r['thumbnail_support_ind'] == 'Y') {
$sourceFile = file_cache_get_cache_file($file_cache_r);
if ($sourceFile !== FALSE) {
$phpThumb = new phpThumb();
// prevent issues with safe mode and /tmp directory
//$phpThumb->setParameter('config_cache_directory', realpath('./itemcache'));
$phpThumb->setParameter('config_error_die_on_error', FALSE);
//$phpThumb->setParameter('config_prefer_imagemagick', FALSE);
$phpThumb->setParameter('config_allow_src_above_docroot', TRUE);
// configure the size of the thumbnail.
if (is_array(get_opendb_config_var('item_display', 'item_image_size'))) {
if (is_numeric(get_opendb_config_var('item_display', 'item_image_size', 'width'))) {
$phpThumb->setParameter('w', get_opendb_config_var('item_display', 'item_image_size', 'width'));
} else {
if (is_numeric(get_opendb_config_var('item_display', 'item_image_size', 'height'))) {
$phpThumb->setParameter('h', get_opendb_config_var('item_display', 'item_image_size', 'height'));
}
}
} else {
$phpThumb->setParameter('h', 100);
}
// input and output format should match
$phpThumb->setParameter('f', $file_type_r['extension']);
$phpThumb->setParameter('config_output_format', $file_type_r['extension']);
$phpThumb->setSourceFilename(realpath($sourceFile));
$directory = realpath(file_cache_get_cache_type_directory($file_cache_r['cache_type']));
$thumbnailFile = $directory . '/' . $file_cache_r['cache_file_thumb'];
if ($phpThumb->GenerateThumbnail() && $phpThumb->RenderToFile($thumbnailFile)) {
opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, 'Thumbnail image saved', array($sequence_number, $cache_type, $file_type_r, $thumbnailFile));
return TRUE;
} else {
// do something with debug/error messages
if (is_not_empty_array($phpThumb->debugmessages)) {
$errors = $phpThumb->debugmessages;
} else {
if (strlen($phpThumb->debugmessages) > 0) {
// single array element
$errors[] = $phpThumb->debugmessages;
}
}
opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, implode(";", $errors), array($file_cache_r, $file_type_r, $file_cache_r['cache_file_thumb']));
return FALSE;
}
} else {
//if(is_file
opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'Source image not found', array($file_cache_r, $file_type_r, $sourceFile));
return FALSE;
}
} else {
opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'Thumbnails not supported by image file type', array($file_cache_r, $file_type_r));
return FALSE;
}
}
示例8: ddCreateThumb
/**
* Делает превьюшку
*
* @param $thumbData {array}
*/
function ddCreateThumb($thumbData)
{
//Вычислим размеры оригинаольного изображения
$originalImg = array();
list($originalImg['width'], $originalImg['height']) = getimagesize($thumbData['originalImage']);
//Если хотя бы один из размеров оригинала оказался нулевым (например, это не изображение) — на(\s?)бок
if ($originalImg['width'] == 0 || $originalImg['height'] == 0) {
return;
}
//Пропрорции реального изображения
$originalImg['ratio'] = $originalImg['width'] / $originalImg['height'];
//Если по каким-то причинам высота не задана
if ($thumbData['height'] == '' || $thumbData['height'] == 0) {
//Вычислим соответственно пропорциям
$thumbData['height'] = $thumbData['width'] / $originalImg['ratio'];
}
//Если по каким-то причинам ширина не задана
if ($thumbData['width'] == '' || $thumbData['width'] == 0) {
//Вычислим соответственно пропорциям
$thumbData['width'] = $thumbData['height'] * $originalImg['ratio'];
}
//Если превьюшка уже есть и имеет нужный размер, ничего делать не нужно
if ($originalImg['width'] == $thumbData['width'] && $originalImg['height'] == $thumbData['height'] && file_exists($thumbData['thumbName'])) {
return;
}
$thumb = new phpThumb();
//зачистка формата файла на выходе
$thumb->setParameter('config_output_format', null);
//Путь к оригиналу
$thumb->setSourceFilename($thumbData['originalImage']);
//Качество (для JPEG) = 100
$thumb->setParameter('q', '100');
//Разрешить ли увеличивать изображение
$thumb->setParameter('aoe', $thumbData['allowEnlargement']);
//Если нужно просто обрезать
if ($thumbData['cropping'] == '1') {
//Ширина превьюшки
$thumb->setParameter('sw', $thumbData['width']);
//Высота превьюшки
$thumb->setParameter('sh', $thumbData['height']);
//Если ширина оригинального изображения больше
if ($originalImg['width'] > $thumbData['width']) {
//Позиция по оси x оригинального изображения (чтобы было по центру)
$thumb->setParameter('sx', ($originalImg['width'] - $thumbData['width']) / 2);
}
//Если высота оригинального изображения больше
if ($originalImg['height'] > $thumbData['height']) {
//Позиция по оси y оригинального изображения (чтобы было по центру)
$thumb->setParameter('sy', ($originalImg['height'] - $thumbData['height']) / 2);
}
} else {
//Ширина превьюшки
$thumb->setParameter('w', $thumbData['width']);
//Высота превьюшки
$thumb->setParameter('h', $thumbData['height']);
//Если нужно уменьшить + отрезать
if ($thumbData['cropping'] == 'crop_resized') {
$thumb->setParameter('zc', '1');
//Если нужно пропорционально уменьшить, заполнив поля цветом
} else {
if ($thumbData['cropping'] == 'fill_resized') {
//Устанавливаем фон (без решётки)
$thumb->setParameter('bg', str_replace('#', '', $thumbData['backgroundColor']));
//Превьюшка должна точно соответствовать размеру и находиться по центру (недостающие области зальются цветом)
$thumb->setParameter('far', 'c');
}
}
}
//Создаём превьюшку
$thumb->GenerateThumbnail();
//Сохраняем в файл
$thumb->RenderToFile($thumbData['thumbName']);
}
示例9: thumbnail
/**
* Create a thumbnail from an image, cache it and output it
*
* @param $imageName File name from webroot/uploads/
*/
function thumbnail($imageName, $width = 120, $height = 120, $crop = 0)
{
$this->autoRender = false;
$imageName = str_replace(array('..', '/'), '', $imageName);
// Don't allow escaping to upper directories
$width = intval($width);
if ($width > 2560) {
$width = 2560;
}
$height = intval($height);
if ($height > 1600) {
$height = 1600;
}
$cachedFileName = join('_', array($imageName, $width, $height, $crop)) . '.jpg';
$cacheDir = Configure::read('Wildflower.thumbnailsCache');
$cachedFilePath = $cacheDir . DS . $cachedFileName;
$refreshCache = false;
$cacheFileExists = file_exists($cachedFilePath);
if ($cacheFileExists) {
$cacheTimestamp = filemtime($cachedFilePath);
$cachetime = 60 * 60 * 24 * 14;
// 14 days
$border = $cacheTimestamp + $cachetime;
$now = time();
if ($now > $border) {
$refreshCache = true;
}
}
if ($cacheFileExists && !$refreshCache) {
return $this->_renderJpeg($cachedFilePath);
} else {
// Create cache and render it
$sourceFile = Configure::read('Wildflower.uploadDirectory') . DS . $imageName;
if (!file_exists($sourceFile)) {
return trigger_error("Thumbnail generator: Source file {$sourceFile} does not exists.");
}
App::import('Vendor', 'phpThumb', array('file' => 'phpthumb.class.php'));
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($sourceFile);
$phpThumb->setParameter('config_output_format', 'jpeg');
$phpThumb->setParameter('w', intval($width));
$phpThumb->setParameter('h', intval($height));
$phpThumb->setParameter('zc', intval($crop));
if ($phpThumb->GenerateThumbnail()) {
$phpThumb->RenderToFile($cachedFilePath);
return $this->_renderJpeg($cachedFilePath);
} else {
return trigger_error("Thumbnail generator: Can't GenerateThumbnail.");
}
}
}
示例10: uploadImages
static function uploadImages($field, $item, $delImage = 0, $itemType = 'albums', $width = 0, $height = 0)
{
$jFileInput = new JInput($_FILES);
$file = $jFileInput->get('jform', array(), 'array');
// If there is no uploaded file, we have a problem...
if (!is_array($file)) {
// JError::raiseWarning('', 'No file was selected.');
return '';
}
// Build the paths for our file to move to the components 'upload' directory
$fileName = $file['name'][$field];
$tmp_src = $file['tmp_name'][$field];
$image = '';
$oldImage = '';
$flagDelete = false;
// $item = $this->getItem();
// if delete old image checked or upload new file
if ($delImage || $fileName) {
$oldImage = JPATH_ROOT . DS . str_replace('/', DS, $item->images);
// unlink file
if (is_file($oldImage)) {
@unlink($oldImage);
}
$flagDelete = true;
$image = '';
}
$date = date('Y') . DS . date('m') . DS . date('d');
$dest = JPATH_ROOT . DS . 'images' . DS . $itemType . DS . $date . DS . $item->id . DS;
// Make directory
@mkdir($dest, 0777, true);
if (isset($fileName) && $fileName) {
$filepath = JPath::clean($dest . $fileName);
/*
if (JFile::exists($filepath)) {
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS')); // File exists
}
*/
// Move uploaded file
jimport('joomla.filesystem.file');
if (!JFile::upload($tmp_src, $filepath)) {
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
// Error in upload
return '';
}
// if upload success, resize image
if ($width) {
require_once JPATH_ROOT . DS . 'jelibs/phpthumb/phpthumb.class.php';
// create phpThumb object
$phpThumb = new phpThumb();
if (include_once JPATH_ROOT . DS . 'jelibs/phpthumb/phpThumb.config.php') {
foreach ($PHPTHUMB_CONFIG as $key => $value) {
$keyname = 'config_' . $key;
$phpThumb->setParameter($keyname, $value);
}
}
// this is very important when using a single object to process multiple images
$phpThumb->resetObject();
$phpThumb->setSourceFilename($filepath);
// set parameters (see "URL Parameters" in phpthumb.readme.txt)
$phpThumb->setParameter('w', $width);
if ($height) {
$phpThumb->setParameter('h', $height);
}
$phpThumb->setParameter('config_output_format', 'jpeg');
// set value to return
$image = 'images/' . $itemType . '/' . str_replace(DS, '/', $date) . '/' . $item->id . '/' . $fileName;
if ($phpThumb->GenerateThumbnail()) {
if ($image) {
if (!$phpThumb->RenderToFile($filepath)) {
// do something on failed
die('Failed (size=' . $width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>');
}
$phpThumb->purgeTempFiles();
}
} else {
// do something with debug/error messages
echo 'Failed (size=' . $width . ').<br>';
echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">' . $phpThumb->fatalerror . '</div>';
echo '<form><textarea rows="100" cols="300" wrap="off">' . htmlentities(implode("\n* ", $phpThumb->debugmessages)) . '</textarea></form><hr>';
die;
}
} else {
// set value to return
$image = 'images/' . $itemType . '/' . str_replace(DS, '/', $date) . '/' . $item->id . '/' . $fileName;
}
} else {
if (!$flagDelete) {
$image = $item->images;
}
}
return $image;
}
示例11: createthumb
/**
* Creation of an image thumbnail
*
* @param $name String File name on server
* @param $filename String Final file name
* @param $new_w Int Width in px
* @param $new_h Int Height in px
* @param $zc Bool "Zoom crop" (if true, cuts the largest possible square from the image center)
*/
function createthumb($name, $filename, $new_w, $new_h, $zc)
{
App::import(array('file' => 'vendors' . DS . 'phpThumb' . DS . 'phpthumb.class.php', 'name' => 'MeioUpload.phpThumb', 'type' => 'file'));
//mod_rewriteが使用できない場合にパスにindex.phpが入ってしまうため
//絶対パスに変更
if (Configure::read('App.baseUrl')) {
$name = WWW_ROOT . $name;
$filename = WWW_ROOT . $filename;
}
$phpThumb = new phpThumb();
$phpThumb->config_allow_src_above_docroot = true;
$phpThumb->setSourceFilename($name);
$phpThumb->setParameter('w', $new_w);
$phpThumb->setParameter('h', $new_h);
$phpThumb->setParameter('zc', $zc);
$parts = pathinfo($filename);
//vd($parts);die();
$phpThumb->setParameter('f', $parts['extension']);
if ($phpThumb->generateThumbnail()) {
$phpThumb->RenderToFile($filename);
} else {
die($phpThumb->fatalerror);
}
}
示例12: aux_image
function aux_image($fieldValue, $params_image)
{
$md5_params = md5($params_image);
if (file_exists(MF_FILES_PATH . 'th_' . $md5_params . "_" . $fieldValue)) {
$fieldValue = MF_FILES_URI . 'th_' . $md5_params . "_" . $fieldValue;
} else {
//generate thumb
include_once dirname(__FILE__) . "/thirdparty/phpthumb/phpthumb.class.php";
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename(MF_FILES_PATH . $fieldValue);
$create_md5_filename = 'th_' . $md5_params . "_" . $fieldValue;
$output_filename = MF_FILES_PATH . $create_md5_filename;
$final_filename = MF_FILES_URI . $create_md5_filename;
$params_image = explode("&", $params_image);
foreach ($params_image as $param) {
if ($param) {
$p_image = explode("=", $param);
$phpThumb->setParameter($p_image[0], $p_image[1]);
}
}
if ($phpThumb->GenerateThumbnail()) {
if ($phpThumb->RenderToFile($output_filename)) {
$fieldValue = $final_filename;
}
}
}
return $fieldValue;
}
示例13: phpThumb
$filepath = JPATH_ROOT . DS . $image;
$thumbImage = JPATH_ROOT . DS . $thumb;
$thumbImageLink = '';
if (false && !file_exists($thumbImage) && file_exists($filepath) && is_file($filepath)) {
require_once JPATH_ROOT . DS . 'jelibs/phpthumb/phpthumb.class.php';
// create phpThumb object
$phpThumb = new phpThumb();
if (include_once JPATH_ROOT . DS . 'jelibs/phpthumb/phpThumb.config.php') {
foreach ($PHPTHUMB_CONFIG as $key => $value) {
$keyname = 'config_' . $key;
$phpThumb->setParameter($keyname, $value);
}
}
// this is very important when using a single object to process multiple images
$phpThumb->resetObject();
$phpThumb->setSourceFilename($filepath);
// set parameters (see "URL Parameters" in phpthumb.readme.txt)
$phpThumb->setParameter('w', CFG_THUMB_SERVICE_IMAGE);
$phpThumb->setParameter('config_output_format', 'jpeg');
// set value to return
if ($phpThumb->GenerateThumbnail()) {
if (!$phpThumb->RenderToFile($thumbImage)) {
// do something on failed
die('Failed (size=' . $width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>');
}
$thumbImageLink = JURI::base() . $thumb;
$phpThumb->purgeTempFiles();
} else {
// do something with debug/error messages
echo 'Failed (size=' . CFG_THUMB_SERVICE_IMAGE . ').<br>';
echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">' . $phpThumb->fatalerror . '</div>';
示例14: phpThumb
}
}
if ($ok == true) {
$imageattr = @getimagesize($templocation);
if ($imageattr == false) {
$ok = false;
$messages[] = "The uploaded icon file was invalid. Please ensure you are using JPEG, GIF or PNG files.";
}
}
if ($ok == true) {
if ($imageattr[0] > 100 || $imageattr[1] > 100) {
// $ok = false;
// $messages[] = "The uploaded icon file was too large. ".tbl_prefix."files.must have maximum dimensions of 100x100.";
require_once path . 'units/phpthumb/phpthumb.class.php';
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($templocation);
$phpThumb->w = 100;
$phpThumb->h = 100;
$phpThumb->config_output_format = 'jpeg';
$phpThumb->config_error_die_on_error = false;
if ($phpThumb->GenerateThumbnail()) {
$phpThumb->RenderToFile($templocation);
$imageattr[2] = "2";
} else {
$ok = false;
$messages[] .= 'Failed: ' . implode("\n", $phpThumb->debugmessages);
}
}
}
if ($ok == true && ($imageattr[2] > 3 || $imageattr[2] < 1)) {
$message[] = "The uploaded icon file was in an image format other than JPEG, GIF or PNG. These are unsupported at present.";
示例15: upload
private function upload($field, $baseDir, $newFileName = false, $deleteOld = false, $oldFilename = '')
{
$jFileInput = new JInput($_FILES);
$fileInput = $jFileInput->get('jform', array(), 'array');
if (empty($fileInput)) {
return false;
}
$field = explode('.', $field);
$uploadFileName = $fileInput['name'];
$uploadFileTemp = $fileInput['tmp_name'];
foreach ($field as $f) {
if (!empty($uploadFileName[$f]) && !empty($uploadFileTemp[$f])) {
$uploadFileName = $uploadFileName[$f];
$uploadFileTemp = $uploadFileTemp[$f];
} else {
$uploadFileName = '';
$uploadFileTemp = '';
break;
}
}
if (empty($uploadFileName)) {
return false;
}
if ($deleteOld && $oldFilename) {
$oldFilename = is_array($oldFilename) ? $oldFilename : array($oldFilename);
foreach ($oldFilename as $key => &$value) {
$value = $baseDir . DS . $oldFilename[$key];
// $oldFilename[$key] = $value;
JFile::delete($value);
}
}
$uploadFileExt = JFile::getExt($uploadFileName);
if (!is_dir($baseDir)) {
if (!mkdir($baseDir, 0777, true)) {
return false;
}
}
$fileName = $newFileName ? $newFileName . '.' . $uploadFileExt : $uploadFileName;
$filePath = $baseDir . DS . $fileName;
$resultUpload = JFile::upload($uploadFileTemp, $filePath);
if ($resultUpload) {
// resize
require_once JPATH_ROOT . '/jelibs/phpthumb/phpthumb.class.php';
// create phpThumb object
$phpThumb = new phpThumb();
if (file_exists(JPATH_ROOT . '/jelibs/phpthumb/phpThumb.config.php') && (include_once JPATH_ROOT . '/jelibs/phpthumb/phpThumb.config.php')) {
foreach ($PHPTHUMB_CONFIG as $key => $value) {
$keyname = 'config_' . $key;
$phpThumb->setParameter($keyname, $value);
}
} else {
echo '<div style="color: red; border: 1px red dashed; font-weight: bold; padding: 10px; margin: 10px; display: inline-block;">Error reading ../phpThumb.config.php</div><br>';
}
// this is very important when using a single object to process multiple images
$phpThumb->resetObject();
// set data source
$phpThumb->setSourceFilename($filePath);
// set parameters (see "URL Parameters" in phpthumb.readme.txt)
$phpThumb->setParameter('w', CFG_BUSINESS_LOGO_WIDTH);
$phpThumb->setParameter('h', CFG_BUSINESS_LOGO_HEIGHT);
$phpThumb->setParameter('zc', 'l');
// set parameters
$phpThumb->setParameter('config_output_format', 'jpeg');
// generate & output thumbnail
//$output_filename = 't-' . CFG_BUSINESS_LOGO_WIDTH . 'x' . CFG_BUSINESS_LOGO_HEIGHT . '-' . $fileName;
$capture_raw_data = false;
if ($phpThumb->GenerateThumbnail()) {
$phpThumb->RenderToFile($filePath);
} else {
// do something with debug/error messages
echo 'Failed (size=' . $thumbnail_width . ').<br>';
echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">' . $phpThumb->fatalerror . '</div>';
echo '<form><textarea rows="40" cols="180" wrap="off">' . htmlentities(implode("\n* ", $phpThumb->debugmessages)) . '</textarea></form><hr>';
die;
}
}
return $fileName;
}