本文整理汇总了PHP中phpThumb::setSourceFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP phpThumb::setSourceFileName方法的具体用法?PHP phpThumb::setSourceFileName怎么用?PHP phpThumb::setSourceFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpThumb
的用法示例。
在下文中一共展示了phpThumb::setSourceFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_thumb
function generate_thumb($path, $prefix, $type = THUMB_SMALL)
{
global $config;
global $thumbnail_config;
// for relative paths assume that they are relative to images directory,
// otherwise just use the given pat
if (file_exists($path)) {
$source_file_name = $path;
} else {
$source_file_name = $config['basedir'] . 'images/' . SmartStripSlashes($path);
}
// the file might have been deleted and since phpThumb dies in that case
// try to do something sensible so that the rest of the images can still be seen
// there is a problem in safe mode - if the script and picture file are owned by
// different users, then the file can not be read.
if (!is_readable($source_file_name)) {
return false;
}
$imgdata = @getimagesize($source_file_name);
if (!$imgdata) {
// unknown image format, bail out
return false;
}
// attributes of original image
$orig_width = $imgdata[0];
$orig_height = $imgdata[1];
// XXX: food for thought - maybe we can return URL to some kind of error image
// if this function fails?
$base_filename = sanitize_filename(basename($path));
$thumb_config = $thumbnail_config[$type];
if (1 == $thumb_config['disabled']) {
return $config['baseurl'] . '/images/' . $path;
}
$prefix = $thumb_config['filename_prefix'] . $prefix . "-";
$thumbpath = $config['basedir'] . 'thumbs/' . $prefix . $base_filename;
$thumburl = $config['gallery_url'] . 'thumbs/' . $prefix . $base_filename;
// if thumbnail file already exists and is generated after data for a thumbnail type
// has been changed, then we assume that the thumbnail is valid.
$thumbnail_timestamp = @filemtime($thumbpath);
if (file_exists($thumbpath) && $thumb_config['timestamp'] < $thumbnail_timestamp) {
return $thumburl;
}
// if dimensions of source image are smaller than those of the requested
// thumbnail, then use the original image as thumbnail
if ($orig_width <= $thumb_config['size'] && $orig_height <= $thumb_config['size']) {
copy($source_file_name, $thumbpath);
return $thumburl;
}
// no existing thumbnail found or thumbnail config has changed,
// generate new thumbnail file
list($width, $height, $thumb_type, $attr) = @getimagesize($thumbpath);
require_once $config['basedir'] . 'lib/phpthumb/phpthumb.class.php';
$phpThumb = new phpThumb();
// set data
$phpThumb->setSourceFileName($source_file_name);
if ($imgdata[0] > $imgdata[1]) {
$phpThumb->w = $thumb_config['size'];
} else {
$phpThumb->h = $thumb_config['size'];
}
$phpThumb->q = $config['compression'];
// set zoom crop flag to get image squared off
if ($type == THUMB_SMALL && $config['square_thumbs']) {
$phpThumb->zc = 1;
$phpThumb->h = $thumb_config['size'];
$phpThumb->w = $thumb_config['size'];
}
$phpThumb->config_use_exif_thumbnail_for_speed = false;
// Set image height instead of width if not using square thumbs
if ($type == THUMB_SMALL && !$config['square_thumbs']) {
$phpThumb->h = $thumb_config['size'];
$phpThumb->w = '';
}
if ($type == THUMB_NAV) {
$phpThumb->zc = 1;
$phpThumb->h = $thumb_config['size'];
$phpThumb->w = $thumb_config['size'];
}
// set options (see phpThumb.config.php)
// here you must preface each option with "config_"
// Set error handling (optional)
$phpThumb->config_error_die_on_error = false;
// generate & output thumbnail
if ($phpThumb->GenerateThumbnail()) {
$phpThumb->RenderToFile($thumbpath);
} else {
// do something with debug/error messages
die('Failed: ' . implode("\n", $phpThumb->debugmessages));
}
return $thumburl;
}
示例2: generate_thumb
function generate_thumb($path, $prefix, $type = THUMB_SMALL)
{
global $config, $thumbnail_config;
$thumb_config = $thumbnail_config[$type];
// For relative paths assume that they are relative to 'plog-content/images/' directory,
// otherwise just use the given path
if (file_exists($path)) {
$source_file_name = $path;
if ($type == THUMB_THEME) {
$cache_path = 'themes/';
} else {
$cache_path = 'uploads/';
}
} else {
$source_file_name = $config['basedir'] . 'plog-content/images/' . SmartStripSlashes($path);
$cache_path = dirname(SmartStripSlashes($path)) . '/' . $thumb_config['type'] . '/';
}
// The file might have been deleted and since phpThumb dies in that case
// try to do something sensible so that the rest of the images can still be seen
// There is a problem in safe mode - if the script and picture file are owned by
// different users, then the file cannot be read.
if (!is_readable($source_file_name)) {
return false;
}
$imgdata = @getimagesize($source_file_name);
if (!$imgdata) {
// Unknown image format, bail out
// Do we want to have video support in the Plogger core?
//return 'plog-graphics/thumb-video.gif';
return false;
}
// Attributes of original image
$orig_width = $imgdata[0];
$orig_height = $imgdata[1];
// XXX: food for thought - maybe we can return URL to some kind of error image
// if this function fails?
$base_filename = sanitize_filename(basename($path));
if ($thumb_config['disabled']) {
return $config['gallery_url'] . 'plog-content/images/' . $path;
}
$prefix = $prefix . '-';
$thumbpath = $config['basedir'] . 'plog-content/thumbs/' . $cache_path . $prefix . $base_filename;
$thumburl = $config['gallery_url'] . 'plog-content/thumbs/' . $cache_path . $prefix . $base_filename;
// If thumbnail file already exists and is generated after data for a thumbnail type
// has been changed, then we assume that the thumbnail is valid.
if (file_exists($thumbpath)) {
$thumbnail_timestamp = @filemtime($thumbpath);
if ($thumb_config['timestamp'] < $thumbnail_timestamp) {
return $thumburl;
}
}
// Create the same directory structure as the image under plog-content/thumbs/
include_once PLOGGER_DIR . 'plog-admin/plog-admin-functions.php';
if (!makeDirs(dirname($thumbpath))) {
return sprintf(plog_tr('Error creating path %s'), dirname($thumbpath));
}
// If dimensions of source image are smaller than those of the requested
// thumbnail, then use the original image as thumbnail unless fullsize images are disabled
if ($orig_width <= $thumb_config['size'] && $orig_height <= $thumb_config['size']) {
// if fullsize image access is disabled, copy the file to the thumbs folder
if ($config['allow_fullpic'] == 0) {
copy($source_file_name, $thumbpath);
return $thumburl;
// otherwise return the original file path
} else {
return $config['gallery_url'] . 'plog-content/images/' . $path;
}
}
// No existing thumbnail found or thumbnail config has changed,
// generate new thumbnail file
require_once PLOGGER_DIR . 'plog-includes/lib/phpthumb/phpthumb.class.php';
$phpThumb = new phpThumb();
// Set data
$phpThumb->setSourceFileName($source_file_name);
switch ($thumb_config['resize_option']) {
// Resize to width
case 0:
$phpThumb->w = $thumb_config['size'];
break;
// Resize to height
// Resize to height
case 1:
$phpThumb->h = $thumb_config['size'];
break;
// Use square thumbnails
// Use square thumbnails
case 3:
$phpThumb->zc = 1;
$phpThumb->h = $thumb_config['size'];
$phpThumb->w = $thumb_config['size'];
break;
// Resize to longest side
// Resize to longest side
case 2:
default:
if ($imgdata[0] > $imgdata[1]) {
$phpThumb->w = $thumb_config['size'];
} else {
$phpThumb->h = $thumb_config['size'];
}
//.........这里部分代码省略.........