📄 phpthumb.class.php
字号:
<?php
ob_start();
if (!include_once(dirname(__FILE__).'/phpthumb.functions.php')) {
ob_end_flush();
die('failed to include_once("'.realpath(dirname(__FILE__).'/phpthumb.functions.php').'")');
}
ob_end_clean();
class phpthumb {
var $src = null; // SouRCe filename
var $new = null; // NEW image (phpThumb.php only)
var $w = null; // Width
var $h = null; // Height
var $wp = null; // Width (Portrait Images Only)
var $hp = null; // Height (Portrait Images Only)
var $wl = null; // Width (Landscape Images Only)
var $hl = null; // Height (Landscape Images Only)
var $ws = null; // Width (Square Images Only)
var $hs = null; // Height (Square Images Only)
var $f = null; // Format
var $q = 75; // jpeg output Quality
var $sx = null; // Source crop top-left X position
var $sy = null; // Source crop top-left Y position
var $sw = null; // Source crop Width
var $sh = null; // Source crop Height
var $zc = null; // Zoom Crop
var $bc = null; // Border Color
var $bg = null; // BackGround color
var $fltr = array(); // FiLTeRs
var $goto = null; // GO TO url after processing
var $err = null; // default ERRor image filename
var $xto = null; // extract eXif Thumbnail Only
var $ra = null; // Rotate by Angle
var $ar = null; // Auto Rotate
var $aoe = null; // Allow Output Enlargement
var $far = null; // Fixed Aspect Ratio
var $iar = null; // Ignore Aspect Ratio
var $maxb = null; // MAXimum Bytes
var $down = null; // DOWNload thumbnail filename
var $md5s = null; // MD5 hash of Source image
var $file = null; // >>deprecated, do not use<<
var $phpThumbDebug = null;
// END PARAMETERS
// public:
// START CONFIGURATION OPTIONS (for object mode only)
// See phpThumb.config.php for descriptions of what each of these settings do
// * Directory Configuration
var $config_cache_directory = null;
var $config_cache_disable_warning = true;
var $config_cache_source_enabled = false;
var $config_cache_source_directory = null;
var $config_temp_directory = null;
var $config_document_root = null;
// * Default output configuration:
var $config_output_format = 'jpeg';
var $config_output_maxwidth = 0;
var $config_output_maxheight = 0;
var $config_output_interlace = true;
// * Error message configuration
var $config_error_image_width = 400;
var $config_error_image_height = 100;
var $config_error_message_image_default = '';
var $config_error_bgcolor = 'CCCCFF';
var $config_error_textcolor = 'FF0000';
var $config_error_fontsize = 1;
var $config_error_die_on_error = false;
var $config_error_silent_die_on_error = false;
var $config_error_die_on_source_failure = true;
// * Anti-Hotlink Configuration:
var $config_nohotlink_enabled = true;
var $config_nohotlink_valid_domains = array();
var $config_nohotlink_erase_image = true;
var $config_nohotlink_text_message = 'Off-server thumbnailing is not allowed';
// * Off-server Linking Configuration:
var $config_nooffsitelink_enabled = false;
var $config_nooffsitelink_valid_domains = array();
var $config_nooffsitelink_require_refer = false;
var $config_nooffsitelink_erase_image = true;
var $config_nooffsitelink_text_message = 'Off-server linking is not allowed';
var $config_cache_differentiate_offsite = true;
// * Border & Background default colors
var $config_border_hexcolor = '000000';
var $config_background_hexcolor = 'FFFFFF';
// * TrueType Fonts
var $config_ttf_directory = '.';
var $config_max_source_pixels = null;
var $config_use_exif_thumbnail_for_speed = false;
var $config_imagemagick_path = null;
var $config_prefer_imagemagick = true;
var $config_cache_maxage = null;
var $config_cache_maxsize = null;
var $config_cache_maxfiles = null;
var $config_cache_source_filemtime_ignore_local = false;
var $config_cache_source_filemtime_ignore_remote = false;
var $config_cache_default_only_suffix = false;
// * MySQL
var $config_mysql_query = null;
var $config_mysql_hostname = null;
var $config_mysql_username = null;
var $config_mysql_password = null;
var $config_mysql_database = null;
// * Security
var $config_high_security_enabled = false;
var $config_config_high_security_password = null;
var $config_disable_debug = false;
var $config_allow_src_above_docroot = false;
var $config_allow_src_above_phpthumb = true;
var $config_allow_parameter_file = false;
var $config_allow_parameter_goto = false;
// END CONFIGURATION OPTIONS
// public: error messages (read-only)
var $debugmessages = array();
var $debugtiming = array();
var $fatalerror = null;
// private: (should not be modified directly)
var $thumbnailQuality = 75;
var $thumbnailFormat = null;
var $sourceFilename = null;
var $rawImageData = null;
var $gdimg_output = null;
var $gdimg_source = null;
var $getimagesizeinfo = null;
var $source_width = null;
var $source_height = null;
var $thumbnailCropX = null;
var $thumbnailCropY = null;
var $thumbnailCropW = null;
var $thumbnailCropH = null;
var $exif_thumbnail_width = null;
var $exif_thumbnail_height = null;
var $exif_thumbnail_type = null;
var $exif_thumbnail_data = null;
var $thumbnail_width = null;
var $thumbnail_height = null;
var $thumbnail_image_width = null;
var $thumbnail_image_height = null;
var $cache_filename = null;
var $is_alpha = false;
var $iswindows = null;
var $osslash = null;
var $phpthumb_version = '1.6.1a-200508261305';
//////////////////////////////////////////////////////////////////////
// public: constructor
function phpThumb() {
$this->DebugTimingMessage('phpThumb() constructor', __FILE__, __LINE__);
$this->config_max_source_pixels = round(max(intval(ini_get('memory_limit')), intval(get_cfg_var('memory_limit'))) * 1048576 * 0.20); // 20% of memory_limit
if (phpthumb_functions::gd_version() < 1) {
die('No GD support detected');
}
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$this->iswindows = true;
$this->osslash = '\\';
} else {
$this->iswindows = false;
$this->osslash = '/';
}
if (@$_SERVER['DOCUMENT_ROOT']) {
$this->config_document_root = $_SERVER['DOCUMENT_ROOT'];
}
}
// public:
function setSourceFilename($sourceFilename) {
$this->rawImageData = null;
$this->sourceFilename = $sourceFilename;
$this->DebugMessage('setSourceFilename('.$sourceFilename.') set $this->sourceFilename to "'.$this->sourceFilename.'"', __FILE__, __LINE__);
return true;
}
// public:
function setSourceData($rawImageData, $sourceFilename='') {
$this->sourceFilename = null;
$this->rawImageData = $rawImageData;
if ($this->config_cache_source_enabled) {
$sourceFilename = ($sourceFilename ? $sourceFilename : md5($rawImageData));
if (!is_dir($this->config_cache_source_directory) && !$this->phpThumbDebug) {
$this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not a directory');
} elseif (!is_writable($this->config_cache_source_directory) && !$this->phpThumbDebug) {
$this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not writable');
}
$this->DebugMessage('setSourceData() attempting to save source image to "'.$this->config_cache_source_directory.$this->osslash.urlencode($sourceFilename).'"', __FILE__, __LINE__);
if ($fp = @fopen($this->config_cache_source_directory.$this->osslash.urlencode($sourceFilename), 'wb')) {
fwrite($fp, $rawImageData);
fclose($fp);
} elseif (!$this->phpThumbDebug) {
$this->ErrorImage('setSourceData() failed to write to source cache ('.$this->config_cache_source_directory.$this->osslash.urlencode($sourceFilename).')');
}
}
return true;
}
// public:
function setSourceImageResource($gdimg) {
$this->gdimg_source = $gdimg;
return true;
}
// public:
function setParameter($param, $value) {
switch ($param) {
case 'src':
$this->setSourceFilename($this->ResolveFilenameToAbsolute($value));
break;
default:
$this->$param = $value;
break;
}
$this->$param = $value;
return true;
}
// public:
function getParameter($param) {
//if (property_exists('phpThumb', $param)) {
return $this->$param;
//}
//$this->DebugMessage('setParameter() attempting to set non-existant parameter "'.$param.'"', __FILE__, __LINE__);
//return false;
}
// public:
function GenerateThumbnail() {
$this->setOutputFormat();
$this->ResolveSource();
$this->SetCacheFilename();
$this->ExtractEXIFgetImageSize();
if (!$this->SourceImageToGD()) {
return false;
}
$this->Rotate();
$this->CreateGDoutput();
switch ($this->far) {
case 'L':
case 'TL':
case 'BL':
$destination_offset_x = 0;
$destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
break;
case 'R':
case 'TR':
case 'BR':
$destination_offset_x = round($this->thumbnail_width - $this->thumbnail_image_width);
$destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
break;
case 'T':
case 'TL':
case 'TR':
$destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
$destination_offset_y = 0;
break;
case 'B':
case 'BL':
case 'BR':
$destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
$destination_offset_y = round($this->thumbnail_height - $this->thumbnail_image_height);
break;
case 'C':
default:
$destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
$destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -