本文整理汇总了PHP中phpThumb::RenderToFile方法的典型用法代码示例。如果您正苦于以下问题:PHP phpThumb::RenderToFile方法的具体用法?PHP phpThumb::RenderToFile怎么用?PHP phpThumb::RenderToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpThumb
的用法示例。
在下文中一共展示了phpThumb::RenderToFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateThumbnail
private function generateThumbnail($destination, $filename, $size)
{
$thumbDestination = $destination . $size . DS;
if (!is_dir($thumbDestination)) {
mkdir($thumbDestination, 0777, true);
}
$imageSettings = $this->getConfig();
if (sizeof($imageSettings) == 0) {
return false;
}
$thumb = new phpThumb();
foreach ($imageSettings[$size] as $key => $value) {
$thumb->setParameter($key, $value);
}
$thumb->setSourceData(file_get_contents($destination . $filename));
if ($thumb->GenerateThumbnail()) {
// this line is VERY important, do not remove it!
if ($thumb->RenderToFile($thumbDestination . $filename)) {
return true;
} else {
throw new Exception("Nie udało mi się wygenerować miniaturki o rozmiarze - {$size} Ponieważ:\n {$thumb->debugmessages}");
}
} else {
throw new Exception("Błąd generatora\n {$thumb->debugmessages}");
}
return false;
}
示例2: 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;
}
}
示例3: 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;
}
示例4: thumb
function thumb()
{
if (empty($_GET['src'])) {
die("No source image");
}
//width
$width = !isset($_GET['w']) ? 100 : $_GET['w'];
//height
$height = !isset($_GET['h']) ? 150 : $_GET['h'];
//quality
$quality = !isset($_GET['q']) ? 75 : $_GET['q'];
$sourceFilename = WWW_ROOT . IMAGES_URL . $_GET['src'];
if (is_readable($sourceFilename)) {
App::import('Vendor', 'Phpthumb', array('file' => 'phpthumb' . DS . 'phpthumb.class.php'));
$phpThumb = new phpThumb();
$phpThumb->src = $sourceFilename;
$phpThumb->w = $width;
$phpThumb->h = $height;
$phpThumb->q = $quality;
$phpThumb->config_imagemagick_path = '/usr/bin/convert';
$phpThumb->config_prefer_imagemagick = false;
$phpThumb->config_output_format = 'png';
$phpThumb->config_error_die_on_error = true;
$phpThumb->config_document_root = '';
$phpThumb->config_temp_directory = APP . 'tmp';
$phpThumb->config_cache_directory = CACHE . 'thumbs' . DS;
$phpThumb->config_cache_disable_warning = true;
$cacheFilename = md5($_SERVER['REQUEST_URI']);
$phpThumb->cache_filename = $phpThumb->config_cache_directory . $cacheFilename;
// Check if image is already cached.
if (!is_file($phpThumb->cache_filename)) {
if ($phpThumb->GenerateThumbnail()) {
$phpThumb->RenderToFile($phpThumb->cache_filename);
} else {
die('Failed: ' . $phpThumb->error);
}
}
if (is_file($phpThumb->cache_filename)) {
// If thumb was already generated we want to use cached version
$cachedImage = getimagesize($phpThumb->cache_filename);
header('Content-Type: ' . $cachedImage['mime']);
readfile($phpThumb->cache_filename);
exit;
}
} else {
// Can't read source
die("Couldn't read source image " . $sourceFilename);
}
}
示例5: 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;
}
示例6: 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;
}
示例7: chmod
////////////////////////////////////////////////////////////////
$phpThumb->GenerateThumbnail();
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[8]', __FILE__, __LINE__);
if (isset($_GET['phpThumbDebug']) && $_GET['phpThumbDebug'] == '8') {
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
if (!empty($PHPTHUMB_CONFIG['high_security_enabled']) && !empty($_GET['nocache'])) {
// cache disabled, don't write cachefile
} else {
phpthumb_functions::EnsureDirectoryExists(dirname($phpThumb->cache_filename));
if (is_writable(dirname($phpThumb->cache_filename)) || file_exists($phpThumb->cache_filename) && is_writable($phpThumb->cache_filename)) {
$phpThumb->CleanUpCacheDirectory();
if ($phpThumb->RenderToFile($phpThumb->cache_filename) && is_readable($phpThumb->cache_filename)) {
chmod($phpThumb->cache_filename, 0644);
RedirectToCachedFile();
} else {
$phpThumb->DebugMessage('Failed: RenderToFile(' . $phpThumb->cache_filename . ')', __FILE__, __LINE__);
}
} else {
$phpThumb->DebugMessage('Cannot write to $phpThumb->cache_filename (' . $phpThumb->cache_filename . ') because that directory (' . dirname($phpThumb->cache_filename) . ') is not writable', __FILE__, __LINE__);
}
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[9]', __FILE__, __LINE__);
if (isset($_GET['phpThumbDebug']) && $_GET['phpThumbDebug'] == '9') {
$phpThumb->phpThumbDebug();
}
示例8: dirname
}
$mw = $mw / $cr_f;
$mh = $mh / $cr_f;
include dirname(__FILE__) . '/../phpThumb/phpthumb.class.php';
$phpThumb = new phpThumb();
$phpThumb->src = $s;
if ($sizes[0] < $sizes[1]) {
// portrait
$phpThumb->h = $cr_mh;
} else {
// landscape
$phpThumb->w = $cr_mw;
}
$phpThumb->config_output_format = 'jpg';
if ($phpThumb->GenerateThumbnail()) {
$phpThumb->RenderToFile($d);
$s = addslashes($d);
} else {
// do something with debug/error messages
echo 'error_uploading';
return false;
}
}
}
if ($r == 1) {
$r = 'SCALABLE';
} else {
$r = 'RESIZABLE';
}
error_reporting(E_ALL ^ E_NOTICE);
require dirname(__FILE__) . '/class.cropinterface.php';
示例9: phpThumb
/**
* This function will do the actual work of creating a thumbnail image.
*
* @param $width The maximum width of the thumbnail.
* @param $height The maximum height of the thumbnail.
* @param $cache (optional) Indicate if the thumbnails should be cached. By default, caching is turned off.
*
* @internal
*/
function &_createThumbnail($width, $height, $cache = true)
{
// Check if the GD library is loaded.
if (!extension_loaded('gd')) {
$this->_error('YD_gd_not_installed');
}
// Include phpThumb
require_once 'phpThumb/phpthumb.class.php';
// Create a new thumbnail object
$thumb = new phpThumb();
$thumb->src = $this->getAbsolutePath();
// Set the options for the creation of thumbnails
$thumb->config_nohotlink_enabled = false;
$thumb->config_cache_directory = YD_DIR_TEMP;
// Set the width and the height
$thumb->w = $width;
$thumb->h = $height;
// Create the cached thumbnail
$cacheFName = $thumb->GenerateCachedFilename();
$cacheFName .= $this->getLastModified();
$cacheFName .= $this->getAbsolutePath();
$cacheFName = YD_TMP_PRE . 'N_' . md5($cacheFName) . '.tmn';
$cacheFName = YD_DIR_TEMP . '/' . $cacheFName;
// Check if caching is enabled
if ($cache == true) {
// Output the cached version if any
if (is_file($cacheFName)) {
$img = new YDFSImage($cacheFName);
header('Content-type: ' . $img->getMimeType());
echo $img->getContents();
die;
}
}
// Width should be positive integer
if ($width < 1) {
$this->_error();
}
// Height should be positive integer
if ($width < 1) {
$this->_error();
}
// Generate the thumbnail
$thumb->GenerateThumbnail();
// Check if caching is enabled
if ($cache == true) {
$thumb->RenderToFile($cacheFName);
}
// Return the thumbnail object
return $thumb;
}
示例10: fixFileName
// file name
$ext = strtolower($tfile['extension']);
// current extension
$path = str_replace('//', '/', $cfg['root_dir'] . $clib);
// remove double slash in path
$nfile = fixFileName($nfile);
// check file name
if (!isset($_REQUEST['nfi'])) {
// if not set, new file will be created, otherwise existing file will be overwritten
$nfile = chkFileName($path, $nfile);
// rename file if new filename already exists
}
//-------------------------------------------------------------------------
// generate & output
if ($phpThumb->GenerateThumbnail()) {
if (!$phpThumb->RenderToFile($path . $nfile)) {
echo 'Failed: ' . implode("\n", $phpThumb->debugmessages);
}
@chmod($path . $nfile, 0755) or die('chmod didn\'t work');
unset($phpThumb);
// free up some memory
} else {
// do something with debug/error messages
echo 'Failed: ' . implode("\n", $phpThumb->debugmessages);
return false;
}
unset($phpThumb);
//-------------------------------------------------------------------------
// escape and clean up file name (only lowercase letters, numbers and underscores are allowed)
function fixFileName($file)
{
示例11: thumb
/**
* Generate a thumbnail of an attachment
* @param $file
* @param $size
* @return bool
* @throws CException
*/
public function thumb($file, $size)
{
if (!$file) {
return false;
}
if (file_exists($file)) {
return true;
}
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
// find the image
$image = $this->getAttachmentFile();
$defaultImage = dirname(Yii::app()->basePath) . '/data/attachment/default.jpg';
if (!$image) {
if (YII_DEBUG) {
throw new CException('Cannot find source image (' . $image . ').');
}
$image = $defaultImage;
}
$fileInfo = pathinfo($image);
if ($fileInfo['extension'] != 'pdf') {
$imageSize = getimagesize($image);
if ($imageSize[0] < $size[0]) {
$size[0] = $imageSize[0];
}
if ($imageSize[1] < $size[1]) {
$size[1] = $imageSize[1];
}
}
require_once Yii::getPathOfAlias('vendor') . DIRECTORY_SEPARATOR . 'phpThumb' . DIRECTORY_SEPARATOR . 'phpThumb.php';
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($image);
$phpThumb->setParameter('config_imagemagick_path', 'convert');
$phpThumb->setParameter('config_allow_src_above_docroot', 'convert');
$phpThumb->setParameter('aoe', false);
$phpThumb->setParameter('w', $size[0]);
$phpThumb->setParameter('h', $size[1]);
$phpThumb->setParameter('f', 'JPG');
// set the output format
$phpThumb->setParameter('far', 'C');
// scale outside
$phpThumb->setParameter('bg', 'FFFFFF');
// scale outside
if (!$phpThumb->GenerateThumbnail()) {
$phpThumb->setSourceFilename($defaultImage);
if (!$phpThumb->GenerateThumbnail()) {
throw new CException('Cannot generate thumbnail from image (' . $image . ').');
}
}
if (!$phpThumb->RenderToFile($file)) {
throw new CException('Cannot save thumbnail (' . $file . ').');
}
return true;
}
示例12: imagePhpThumb
function imagePhpThumb($origpath, $destpath, $prefix, $filename, $ext, $width, $height, $quality, $size, $crop, $usewm, $wmfile, $wmop, $wmpos)
{
$lib = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'phpthumb' . DS . 'phpthumb.class.php';
require_once $lib;
unset($phpThumb);
$phpThumb = new phpThumb();
$filepath = $origpath . $filename;
$phpThumb->setSourceFilename($filepath);
$phpThumb->setParameter('config_output_format', "{$ext}");
//if ( $ext=='gif' ) // Force maximum color for GIF images?
// $phpThumb->setParameter('fltr', 'rcd|256|1');
$phpThumb->setParameter('w', $width);
$phpThumb->setParameter('h', $height);
if ($usewm == 1) {
$phpThumb->setParameter('fltr', 'wmi|' . $wmfile . '|' . $wmpos . '|' . $wmop);
}
$phpThumb->setParameter('q', $quality);
if ($crop == 1) {
$phpThumb->setParameter('zc', 1);
}
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if (in_array($ext, array('png', 'ico', 'gif'))) {
$phpThumb->setParameter('f', $ext);
}
$output_filename = $destpath . $prefix . $filename;
if ($phpThumb->GenerateThumbnail()) {
if ($phpThumb->RenderToFile($output_filename)) {
return true;
} else {
echo 'Failed:<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre><br />';
return false;
}
} else {
echo 'Failed2:<pre>' . $phpThumb->fatalerror . "\n\n" . implode("\n\n", $phpThumb->debugmessages) . '</pre><br />';
return false;
}
}
示例13: run
/**
* Run method with main page logic
*
* Populate template and display form for editing an photo entry. For POST requests,
* check user credentials, check if photo exists and then update entry in database.
* Available to admins only
* @access public
*/
public function run()
{
$session = Session::getInstance();
$user = $session->getUser();
if (!$user || !$user->isAdmin()) {
$session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
header("Location: " . BASE_URL);
return;
}
$photoDAO = PhotoDAO::getInstance();
$albumDAO = AlbumDAO::getInstance();
$photo = null;
$form_errors = array();
$form_values = array("id" => "", "albumid" => "", "title" => "", "description" => "");
if (!empty($_POST)) {
$form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : "";
$form_values["albumid"] = isset($_POST["albumid"]) && is_numeric($_POST["albumid"]) ? intval($_POST["albumid"]) : "";
$form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
$form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : "";
if (empty($form_values["id"])) {
$form_errors["id"] = "No id specified";
}
$photo = $photoDAO->load($form_values["id"]);
if (!$photo) {
$form_errors["id"] = "Photo does not exist";
}
if (empty($form_values["albumid"])) {
$form_errors["albumid"] = "No albumid specified";
} else {
if (!$albumDAO->load($form_values["albumid"])) {
$form_errors["albumid"] = "Album does not exist";
}
}
if (empty($form_values["title"])) {
$form_errors["title"] = "No title specified";
}
if (empty($form_values["description"])) {
$form_errors["description"] = "No description specified";
}
// Check if image will be changed
$upload_path = "";
if (!empty($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] != UPLOAD_ERR_NO_FILE) {
if ($_FILES["imagefile"]["error"] != UPLOAD_ERR_OK) {
$form_errors["imagefile"] = "File upload failed";
} else {
$info = getimagesize($_FILES["imagefile"]["tmp_name"]);
$path = pathinfo($_FILES["imagefile"]["name"]);
$upload_path = joinPath(Photo::UPLOAD_DIR, strftime("%Y_%m"), basename($_FILES['imagefile']['name']));
$thumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb.jpg");
$smallThumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb_small.jpg");
if (!$info || !(strtolower($path["extension"]) != ".png" && strtolower($path["extension"]) != ".jpg" && strtolower($path["extension"]) != ".jpeg")) {
$form_errors["imagefile"] = "An invalid file was uploaded";
} else {
if (file_exists($upload_path)) {
unlink($upload_path);
if (file_exists($thumbLoc)) {
unlink($thumbLoc);
}
if (file_exists($smallThumbLoc)) {
unlink($smallThumbLoc);
}
//$form_errors["imagefile"] = "Filename already exists. Please choose different name or delete file first";
}
}
}
}
if (empty($form_errors)) {
$photo->setAlbumId($form_values["albumid"]);
$photo->setTitle($form_values["title"]);
$photo->setDescription($form_values["description"]);
// New image has been uploaded
if (!empty($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] != UPLOAD_ERR_NO_FILE) {
if (!file_exists(dirname($upload_path))) {
mkdir(dirname($upload_path));
}
if (move_uploaded_file($_FILES["imagefile"]["tmp_name"], $upload_path)) {
$photo->setFileLoc($upload_path);
// Reset thumbnail location in case new image does not need a thumbnail
$photo->setThumbLoc("");
// Create thumbnail
if ($info[0] > Photo::MAX_WIDTH) {
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($photo->getFileLoc());
$phpThumb->setParameter('w', Photo::MAX_WIDTH);
$phpThumb->setParameter('config_output_format', 'jpeg');
if (!file_exists(dirname($thumbLoc))) {
mkdir(dirname($thumbLoc));
}
if ($phpThumb->GenerateThumbnail() && $phpThumb->RenderToFile($thumbLoc)) {
$photo->setThumbLoc($thumbLoc);
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($photo->getFileLoc());
//.........这里部分代码省略.........
示例14: phpThumb
if ($img_upload_status == UPLOAD_SUCCESS) {
$data['label_image'] = $dbs->escape_string($image_upload->new_filename);
// resize the image
if (function_exists('imagecopyresampled')) {
// we use phpthumb class to resize image
include LIB_DIR . 'phpthumb/phpthumb.class.php';
// create phpthumb object
$phpthumb = new phpThumb();
$phpthumb->new = true;
$phpthumb->src = IMAGES_BASE_DIR . 'labels/' . $image_upload->new_filename;
$phpthumb->w = 24;
$phpthumb->h = 24;
$phpthumb->f = 'png';
$phpthumb->GenerateThumbnail();
$temp_file = IMAGES_BASE_DIR . 'labels/' . 'temp-' . $image_upload->new_filename;
$phpthumb->RenderToFile($temp_file);
// remove original file and rename the resized image
@unlink($phpthumb->src);
@rename($temp_file, $phpthumb->src);
unset($phpthumb);
}
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'] . ' upload label image file ' . $image_upload->new_filename);
utility::jsAlert('Label image file successfully uploaded');
} else {
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', 'ERROR : ' . $_SESSION['realname'] . ' FAILED TO upload label image file ' . $image_upload->new_filename . ', with error (' . $image_upload->error . ')');
utility::jsAlert('FAILED to upload label image! Please see System Log for more detailed information');
}
}
$data['input_date'] = date('Y-m-d');
示例15: 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;
}