本文整理汇总了PHP中PhpThumbFactory类的典型用法代码示例。如果您正苦于以下问题:PHP PhpThumbFactory类的具体用法?PHP PhpThumbFactory怎么用?PHP PhpThumbFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhpThumbFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create a thumbnail of an image and returns relative path in webroot
* the options array is an associative array which can take the values
* quality (jpg quality) and method (the method for resizing)
*
* @param int $width
* @param int $height
* @param string $img
* @param array $options
* @return string $path
*/
public static function create($width, $height, $img, $options = null)
{
if (!file_exists($img)) {
throw new CException('Image not found');
}
// Defaults for options
$thumbDir = '.tmb';
$jpegQuality = 80;
$resizeMethod = 'adaptiveResize';
if ($options) {
extract($options, EXTR_IF_EXISTS);
}
$pathinfo = pathinfo($img);
$thumbName = 'thumb_' . $resizeMethod . '_' . $width . '_' . $height . '_' . $pathinfo['basename'];
$thumbPath = $pathinfo['dirname'] . '/' . $thumbDir . '/';
if (!file_exists($thumbPath)) {
mkdir($thumbPath);
}
if (!file_exists($thumbPath . $thumbName) || filemtime($thumbPath . $thumbName) < filemtime($img)) {
Yii::import('vendors.image.phpThumb.PhpThumbFactory');
$options = array('jpegQuality' => $jpegQuality);
$thumb = PhpThumbFactory::create($img, $options);
$thumb->{$resizeMethod}($width, $height);
$thumb->save($thumbPath . $thumbName);
}
return '/' . $thumbPath . $thumbName;
}
示例2: thumb
function thumb($images, $pathUpload, $pathThumb, $thumbW, $thumbH = null, $crop = true)
{
//get array of image
$images = unserialize($images);
$thumbFile = array();
$path = '';
foreach ($images as $img) {
$newPathThumb = null;
//explode image by path seperate
$tmp = explode('/', $img);
//remove last element in array
$imgFile = array_pop($tmp);
//re-build path
$path = implode('/', $tmp);
$newPathThumb = $pathThumb . $path;
$thumbFile[] = $path . '/thumbnail-' . $imgFile;
//make dir if not exist
if (!is_dir($newPathThumb)) {
mkdir($newPathThumb, 0777, true);
}
$createThumbFile = $newPathThumb . '/thumbnail-' . $imgFile;
//make thumb
$file = $pathUpload . $img;
if (!file_exists($createThumbFile) && is_file($file)) {
$thumb = PhpThumbFactory::create($file);
$thumb->resize($thumbW);
if ($crop) {
$thumb->crop(0, 0, $thumbW, $thumbH);
}
$thumb->save($createThumbFile);
}
}
return $thumbFile;
}
示例3: _beforeAdd
protected function _beforeAdd(KCommandContext $context)
{
$container = $this->getModel()->container;
if ($container instanceof ComFilesDatabaseRowContainer) {
$size = $container->getParameters()->thumbnail_size;
if (isset($size['x']) && isset($size['y'])) {
$this->setThumbnailSize($size);
}
}
@ini_set('memory_limit', '256M');
$source = $context->data->file;
if ($source) {
try {
$thumb = PhpThumbFactory::create($source);
} catch (Exception $e) {
// GD is not available
return;
}
$thumb_size = $this->getThumbnailSize();
$thumb->resize($thumb_size['x'], $thumb_size['y']);
ob_start();
echo $thumb->getImageAsString();
$str = ob_get_clean();
$str = sprintf('data:%s;base64,%s', 'image/png', base64_encode($str));
$context->data->thumbnail_string = $str;
}
}
示例4: avatarUrl
public function avatarUrl($size = false)
{
if ($size === false) {
$size = Yii::app()->settings->get('users', 'avatar_size');
}
$ava = $this->avatar;
if (!preg_match('/(http|https):\\/\\/(.*?)$/i', $ava)) {
$r = true;
} else {
$r = false;
}
// if (!is_null($this->service)) {
// return $this->avatar;
// }
if ($size !== false && $r !== false) {
$thumbPath = Yii::getPathOfAlias('webroot.assets.user_avatar') . DS . $size;
if (!file_exists($thumbPath)) {
mkdir($thumbPath, 0777, true);
}
// Path to source image
$fullPath = Yii::getPathOfAlias('webroot.uploads.users.avatar') . DS . $ava;
// Path to thumb
$thumbPath = $thumbPath . DS . $ava;
if (!file_exists($thumbPath)) {
// Resize if needed
Yii::import('ext.phpthumb.PhpThumbFactory');
$sizes = explode('x', $size);
$thumb = PhpThumbFactory::create($fullPath);
$thumb->resize($sizes[0], $sizes[1])->save($thumbPath);
}
return empty($ava) ? '/uploads/users/avatars/user.png' : '/assets/user_avatar/' . $size . '/' . $ava;
} else {
return $ava;
}
}
示例5: actionUpload
public function actionUpload()
{
Yii::import("ext.MyAcrop.qqFileUploader");
$folder = 'uploads/tmp';
// folder for uploaded files
// $allowedExtensions = array("jpg","jpeg","gif","png");
$allowedExtensions = array();
$sizeLimit = Yii::app()->params['storeImages']['maxFileSize'];
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit, $this->uploadlogosession);
$uploader->inputName = 'photo';
$result = $uploader->handleUpload($folder);
$datasession = Yii::app()->session->itemAt($this->uploadlogosession);
if (!empty($datasession)) {
end($datasession);
$key = key($datasession);
$result['tmpFile'] = $datasession[$key];
$tmpFile = Yii::getPathOfAlias('webroot') . '/uploads/tmp/' . $result['tmpFile'];
if (file_exists($tmpFile)) {
$thumbTo = array(160, 160);
$folder = Yii::getPathOfAlias('webroot') . '/uploads/tmp/';
$uploadDirectoryUpload = rtrim($folder, '/');
$check = MHelper::File()->getUniqueTargetPath($uploadDirectoryUpload, $result['tmpFile']);
$target = $uploadDirectoryUpload . '/' . $check;
// if (copy($tmpFile, $target)){
Yii::import('ext.phpthumb.PhpThumbFactory');
$thumb = PhpThumbFactory::create($tmpFile);
$sizes = Yii::app()->params['storeImages']['sizes'];
$method = $sizes['resizeThumbMethod'];
$thumb->{$method}($thumbTo[0], $thumbTo[1])->save($target);
if (copy($target, $tmpFile)) {
unlink($target);
//delete tmp file
}
/* $result['tmpFile'] = $check;
$data_sess = array();
if(Yii::app()->session->itemAt($this->uploadlogosession)){
$data = Yii::app()->session->itemAt($this->uploadlogosession);
if(!is_array($data)){
$data_sess[$key] = $check;
} else {
$data[$key] = $check;
$data_sess = $data;
}
} else {
$data_sess[$key] = $check;
}
Yii::app()->session->remove($this->uploadlogosession);
Yii::app()->session->add($this->uploadlogosession, $data_sess);
unlink($tmpFile); //delete tmp file
*/
// }
}
}
$result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;
}
示例6: save
public function save()
{
if ($source = $this->source) {
if (!is_file($source->fullpath) || !$source->isImage()) {
return false;
}
$image = PhpThumbFactory::create($source->fullpath)
->setOptions(array('jpegQuality' => 50))
->adaptiveResize($this->_thumbnail_size, $this->_thumbnail_size);
ob_start();
echo $image->getImageAsString();
$str = ob_get_clean();
$str = sprintf('data:%s;base64,%s', $source->mimetype, base64_encode($str));
$this->setData(array(
'files_container_id' => $source->container->id,
'folder' => '/'.$source->relative_folder,
'filename' => $source->name,
'thumbnail' => $str
));
}
return parent::save();
}
示例7: create_thumb
public static function create_thumb($upload_path, $file_name, $file_ext)
{
$path = $upload_path . $file_name;
$thumb_settings = Config::get('cms::theme.thumb');
$thumb_options = Config::get('cms::settings.thumb_options');
$thumb_path = $upload_path . Config::get('cms::settings.thumb_path');
foreach ($thumb_settings as $setting) {
$thumb = PhpThumbFactory::create(path('public') . $path, $thumb_options);
if ($setting['method'] == 'resize') {
$thumb->resize($setting['width'], $setting['height']);
}
if ($setting['method'] == 'adaptiveResize') {
$thumb->adaptiveResize($setting['width'], $setting['height']);
}
if ($setting['method'] == 'cropFromCenter') {
$thumb->cropFromCenter($setting['width'], $setting['height']);
}
//CREATE SUBDIR IF NOT EXISTS
if (!file_exists(path('public') . $thumb_path)) {
mkdir(path('public') . $thumb_path);
}
//CREATE THUMB FILE NAME
$thumb_name = str_replace('.' . $file_ext, $setting['suffix'] . '.' . $file_ext, $file_name);
$thumb->save(path('public') . $thumb_path . $thumb_name, $file_ext);
}
//return true;
return '/' . $thumb_path . $thumb_name;
}
示例8: getImageUrl
/**
* Get url to product image. Enter $size to resize image.
* @param mixed $attr Model attribute
* @param mixed $size New size of the image. e.g. '150x150'
* @param mixed $dir Folder name upload
* @return string
*/
public function getImageUrl($attr, $dir, $size = false, $resize = 'resize')
{
Yii::import('ext.phpthumb.PhpThumbFactory');
$attrname = $this->{$attr};
if (!empty($attrname)) {
if ($size !== false) {
$thumbPath = Yii::getPathOfAlias('webroot.assets') . DS . $dir . DS . $size;
if (!file_exists($thumbPath)) {
mkdir($thumbPath, 0777, true);
}
// Path to source image
$fullPath = Yii::getPathOfAlias('webroot.uploads') . DS . $dir . DS . $attrname;
// Path to thumb
$thumbPath = $thumbPath . '/' . $attrname;
if (!file_exists($thumbPath)) {
// Resize if needed
$sizes = explode('x', $size);
$thumb = PhpThumbFactory::create($fullPath);
$thumb->{$resize}($sizes[0], $sizes[1])->save($thumbPath);
//resize/adaptiveResize
}
return '/assets/' . $dir . '/' . $size . '/' . $attrname;
}
// return '/uploads/product/' . $attrname;
} else {
return false;
}
}
示例9: resize
function resize($image_url, $width, $height, $photoset_id = '')
{
if ($image_url === FALSE) {
return ar_default($width, $height, $photoset_id);
}
require_once APPPATH . 'third_party/phpthumb/ThumbLib.inc.php';
$CI =& get_instance();
$image_folder = $CI->config->item('RESIZED_IMAGES_PATH') . "{$photoset_id}/";
$resized_images_url = $CI->config->item('RESIZED_IMAGES_URL') . "{$photoset_id}/";
$size_folder = $width . "_" . $height;
$image_name = basename($image_url);
//return $image_folder.$size_folder;
if (!file_exists($image_folder . $size_folder)) {
mkdir($image_folder . $size_folder, 0755, true);
}
if (file_exists($image_folder . $size_folder . "/{$image_name}")) {
return $resized_images_url . $size_folder . "/{$image_name}";
}
try {
$thumb = PhpThumbFactory::create($image_url, array('jpegQuality' => 90));
$thumb->resize($width, $height)->save($image_folder . $size_folder . "/{$image_name}");
return $resized_images_url . $size_folder . "/{$image_name}";
} catch (Exception $e) {
return ar_default($width, $height, $photoset_id);
}
return '';
}
示例10: upload_image
function upload_image($image_field_name, $dir_path, $sizes)
{
require_once 'phpthumb/ThumbLib.inc.php';
$cnt = 1;
$resized_path = $dir_path;
if (!file_exists($dir_path)) {
mkdir($dir_path);
chmod($dir_path, 0755);
}
if (!file_exists($resized_path)) {
mkdir($resized_path);
chmod($resized_path, 0755);
}
if (!empty($_FILES[$image_field_name]['tmp_name'])) {
$info = getimagesize($_FILES[$image_field_name]['tmp_name']);
$originalfilename = basename($_FILES[$image_field_name]['name']);
$imagetarget = resolve_filename_collisions($dir_path, array(basename($_FILES[$image_field_name]['name'])), $format = '%s_%d.%s');
$originalfile = $dir_path . $imagetarget[0];
if (move_uploaded_file($_FILES[$image_field_name]['tmp_name'], $originalfile)) {
foreach ($sizes as $size) {
$destinationfile = $resized_path . 'f' . $cnt++ . '_' . $imagetarget[0];
$thumb = PhpThumbFactory::create($originalfile);
$thumb->resize($size['width'], $size['height']);
$thumb->save($destinationfile);
}
return $imagetarget[0];
} else {
return 0;
}
} else {
return 0;
}
}
示例11: getUrl
/**
* Get url to product image. Enter $size to resize image.
* @param mixed $size New size of the image. e.g. '150x150'
* @param mixed $resizeMethod Resize method name to override config. resize/adaptiveResize
* @param mixed $random Add random number to the end of the string
* @return string
*/
public function getUrl($size = false, $resizeMethod = false, $random = false)
{
if ($size !== false) {
$thumbPath = Yii::getPathOfAlias(EventsImagesConfig::get('thumbPath')) . '/' . $size;
if (!file_exists($thumbPath)) {
mkdir($thumbPath, 0777, true);
}
// Path to source image
$fullPath = Yii::getPathOfAlias(EventsImagesConfig::get('path')) . '/' . $this->image;
// Path to thumb
$thumbPath = $thumbPath . '/' . $this->image;
if (!file_exists($thumbPath)) {
// Resize if needed
Yii::import('ext.phpthumb.PhpThumbFactory');
$sizes = explode('x', $size);
$thumb = PhpThumbFactory::create($fullPath);
if ($resizeMethod === false) {
$resizeMethod = EventsImagesConfig::get('resizeThumbMethod');
}
$thumb->{$resizeMethod}($sizes[0], $sizes[1])->save($thumbPath);
}
return EventsImagesConfig::get('thumbUrl') . $size . '/' . $this->image;
}
if ($random === true) {
return EventsImagesConfig::get('url') . $this->image . '?' . rand(1, 10000);
}
return EventsImagesConfig::get('url') . $this->image;
}
示例12: generateThumbnail
public function generateThumbnail()
{
@ini_set('memory_limit', '256M');
if (($source = $this->getSource()) && $this->_canGenerate())
{
try
{
//Load the library
require_once JPATH_LIBRARIES.'/koowa/components/com_files/helper/phpthumb/phpthumb.php';
//Create the thumb
$image = PhpThumbFactory::create($source->fullpath)
->setOptions(array('jpegQuality' => 50));
$size = $this->getSize();
// Resize then crop to the provided resolution.
$image->adaptiveResize($size['x'], $size['y']);
ob_start();
echo $image->getImageAsString();
$str = ob_get_clean();
$str = sprintf('data:%s;base64,%s', $source->mimetype, base64_encode($str));
return $str;
}
catch (Exception $e) {
return false;
}
}
return false;
}
示例13: getUrl
/**
* Get url to product image. Enter $size to resize image.
* @param mixed $size New size of the image. e.g. '150x150'
* @param mixed $resizeMethod Resize method name to override config. resize/adaptiveResize
* @param mixed $random Add random number to the end of the string
* @return string
*/
public function getUrl($size = false, $resizeMethod = 'resize', $random = false)
{
// $config = Yii::app()->settings->get('shop');
if ($size !== false) {
$thumbPath = Yii::getPathOfAlias('webroot.assets.product') . '/' . $size;
if (!file_exists($thumbPath)) {
mkdir($thumbPath, 0777, true);
}
// Path to source image
$fullPath = Yii::getPathOfAlias('webroot.uploads.product') . '/' . $this->name;
// Path to thumb
$thumbPath = $thumbPath . '/' . $this->name;
if (!file_exists($thumbPath)) {
// Resize if needed
Yii::import('ext.phpthumb.PhpThumbFactory');
$sizes = explode('x', $size);
$thumb = PhpThumbFactory::create($fullPath);
// if ($resizeMethod === false)
// $resizeMethod = 'resize';
$thumb->{$resizeMethod}($sizes[0], $sizes[1])->save($thumbPath);
}
return '/assets/product/' . $size . '/' . $this->name;
}
if ($random === true) {
return '/uploads/product/' . $this->name . '?' . rand(1, 10000);
}
return '/uploads/product/' . $this->name;
}
示例14: generateThumbnail
public function generateThumbnail()
{
@ini_set('memory_limit', '256M');
$source = $this->source;
if ($source && !$source->isNew()) {
try {
//Load the library
$this->getService('koowa:loader')->loadIdentifier('com://admin/files.helper.phpthumb.phpthumb');
//Create the thumb
$image = PhpThumbFactory::create($source->fullpath)->setOptions(array('jpegQuality' => 50));
if ($this->_thumbnail_size['x'] && $this->_thumbnail_size['y']) {
// Resize then crop to the provided resolution.
$image->adaptiveResize($this->_thumbnail_size['x'], $this->_thumbnail_size['y']);
} else {
$width = isset($this->_thumbnail_size['x']) ? $this->_thumbnail_size['x'] : 0;
$height = isset($this->_thumbnail_size['y']) ? $this->_thumbnail_size['y'] : 0;
// PhpThumb will calculate the missing side while preserving the aspect ratio.
$image->resize($width, $height);
}
ob_start();
echo $image->getImageAsString();
$str = ob_get_clean();
$str = sprintf('data:%s;base64,%s', $source->mimetype, base64_encode($str));
return $str;
} catch (Exception $e) {
return false;
}
}
return false;
}
示例15: showImage
function showImage()
{
global $manager;
$manager->load_helper("ThumbLib.inc");
$thumb = PhpThumbFactory::create($_GET['mmfile']);
$thumb->resize(100, 0);
$thumb->show();
}