本文整理匯總了PHP中Image::thumb方法的典型用法代碼示例。如果您正苦於以下問題:PHP Image::thumb方法的具體用法?PHP Image::thumb怎麽用?PHP Image::thumb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Image
的用法示例。
在下文中一共展示了Image::thumb方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: upload
function upload()
{
$path = "./uploads/";
//設置圖片上傳路徑
$up = new FileUpload($path);
//創建文件上傳類對象
if ($up->upload('pic')) {
//上傳圖片
$filename = $up->getFileName();
//獲取上傳後的圖片名
$img = new Image($path);
//創建圖像處理類對象
$img->thumb($filename, 300, 300, "");
//將上傳的圖片都縮放至在300X300以內
$img->thumb($filename, 80, 80, "icon_");
//縮放一個80x80的圖標,使用icon_作前綴
$img->watermark($filename, "logo.gif", 5, "");
//為上傳的圖片加上圖片水印
return array(true, $filename);
//如果成功返回成功狀態和圖片名稱
} else {
return array(false, $up->getErrorMsg());
//如果失敗返回失敗狀態和錯誤消息
}
}
示例2: index
public function index()
{
echo ROOT_PATH . '/code.jpeg';
$img = new Image('/code.jpeg');
$img->thumb(100, 200);
$img->out();
}
示例3: save
private function save($file)
{
$filename = $file['savepath'] . $file['savename'];
if (!$this->uploadReplace && is_file($filename)) {
$this->error = LParse(L('_FILE_REPLACE_ERROR_'), array($filename));
return false;
}
if (!move_uploaded_file($file['tmp_name'], auto_charset($filename, 'utf-8', 'gbk'))) {
$this->error = L('_FILE_MOVE_ERROR_');
return false;
}
if ($this->thumb) {
import("ORG.Util.Image");
$image = Image::getImageInfo($filename);
if (false !== $image) {
$thumbWidth = explode(',', $this->thumbMaxWidth);
$thumbHeight = explode(',', $this->thumbMaxHeight);
$thumbPrefix = explode(',', $this->thumbPrefix);
$thumbSuffix = explode(',', $this->thumbSuffix);
$thumbPath = $this->thumbPath ? $this->thumbPath : $file['savepath'];
for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) {
$thumbname = $thumbPath . $thumbPrefix[$i] . substr($file['savename'], 0, strrpos($file['savename'], '.')) . $thumbSuffix[$i] . '.' . $file['extension'];
Image::thumb($filename, '', $thumbname, $thumbWidth[$i], $thumbHeight[$i], true);
}
}
}
if ($this->zipImages) {
// TODO Image compression package on-line decompression
}
return true;
}
示例4: thumb_href
private function thumb_href($source_path, $width, $height)
{
if (!file_exists($source_path)) {
return null;
}
$name = 'thumb-' . sha1($source_path) . '-' . $width . 'x' . $height . '.jpg';
$thumb_path = $this->thumbs_path . '/' . $name;
$thumb_href = $this->thumbs_href . '/' . $name;
if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) {
$image = new Image();
$et = false;
if ($this->setup->get('HAS_PHP_EXIF') && $this->context->query_option('thumbnails.exif', false) === true && $height != 0) {
$et = @exif_thumbnail($source_path);
}
if ($et !== false) {
file_put_contents($thumb_path, $et);
$image->set_source($thumb_path);
$image->normalize_exif_orientation($source_path);
} else {
$image->set_source($source_path);
}
$image->thumb($width, $height);
$image->save_dest_jpeg($thumb_path, 80);
}
return file_exists($thumb_path) ? $thumb_href : null;
}
示例5: thumb_href
private function thumb_href($source_abs_path, $mode, $width, $height)
{
if (!file_exists($source_abs_path)) {
return null;
}
if (!is_dir($this->thumbs_path)) {
@mkdir($this->thumbs_path, 0755, true);
}
$name = "thumb-" . sha1("{$source_abs_path}-{$width}-{$height}-{$mode}") . ".jpg";
$thumb_abs_path = $this->thumbs_path . "/" . $name;
$thumb_abs_href = $this->thumbs_href . "/" . $name;
if (!file_exists($thumb_abs_path) || filemtime($source_abs_path) >= filemtime($thumb_abs_path)) {
$image = new Image();
$et = false;
$opts = $this->app->get_options();
if ($opts["thumbnails"]["exif"] === true && function_exists("exif_thumbnail")) {
$et = @exif_thumbnail($source_abs_path);
}
if ($et !== false) {
file_put_contents($thumb_abs_path, $et);
$image->set_source($thumb_abs_path);
$image->normalize_exif_orientation($source_abs_path);
} else {
$image->set_source($source_abs_path);
}
$image->thumb($mode, $width, $height);
$image->save_dest_jpeg($thumb_abs_path, 80);
}
return file_exists($thumb_abs_path) ? $thumb_abs_href : null;
}
示例6: Thumb
function Thumb($img, $width = '', $height = '')
{
$thumb_img = 'Public/thumb.jpg';
if ($img) {
$img = substr($img, 1);
$is_img = GetImageSize('./' . $img);
//設置寬高 生成縮略圖
if (!empty($width) && !empty($height)) {
import('ORG.Util.Image');
$Image = new Image();
$filename = 'Uploads/thumb/' . $width . '_' . $height . '/';
//縮略圖存儲路徑
$new_name = strtr($img, array('/' => '_'));
if (!file_exists($filename)) {
@mkdir($filename, 0755);
}
if ($is_img) {
$is_thumb = GetImageSize('./' . $filename . $new_name);
if ($is_thumb) {
$thumb_img = $filename . $new_name;
} else {
$Image->thumb($img, $filename . $new_name, '', $width, $height);
$thumb_img = $filename . $new_name;
}
}
} else {
if ($is_img) {
$thumb_img = $img;
}
}
}
return '/' . $thumb_img;
}
示例7: upload
public function upload()
{
if (isset($_FILES['userfile']['tmp_name'])) {
switch ($_POST['type']) {
case 'face':
$width = 99;
$height = 100;
$info = '頭像上傳成功';
break;
case 'ok':
$width = 300;
$height = 300;
$info = '圖片上傳成功';
break;
case 'rotator':
$width = 1200;
$height = 530;
$info = '輪播器圖片上傳成功';
break;
default:
exit('非法操作');
}
$upload = new UploadFile('userfile', $_POST['MAX_FILE_SIZE']);
$path = $upload->getPath();
$thumb = new Image($path);
$thumb->thumb($width, $height);
$thumb->outImage();
$upload->alertThumbClose($info, $path);
} else {
Tool::alertBack('警告:未知錯誤');
}
}
示例8: down_img
public function down_img($url, $mid = 'video')
{
$chr = strrchr($url, '.');
$imgUrl = uniqid();
$imgPath = $mid . '/' . date(C('upload_style'), time()) . '/';
$imgPath_s = './' . C('upload_path') . '-s/' . $imgPath;
$filename = './' . C('upload_path') . '/' . $imgPath . $imgUrl . $chr;
$get_file = get_collect_file($url);
if ($get_file) {
write_file($filename, $get_file);
//是否添加水印
if (C('upload_water')) {
import('ORG.Util.Image');
Image::water($filename, C('upload_water_img'), '', C('upload_water_pct'), C('upload_water_pos'));
}
//是否生成縮略圖
if (C('upload_thumb')) {
mkdirss($imgPath_s);
import('ORG.Util.Image');
Image::thumb($filename, $imgPath_s . $imgUrl . $chr, '', C('upload_thumb_w'), C('upload_thumb_h'), true);
}
//是否上傳遠程
if (C('upload_ftp')) {
$this->ftp_upload($imgPath . $imgUrl . $chr);
}
return $imgPath . $imgUrl . $chr;
} else {
return $url;
}
}
示例9: thumb_href
private function thumb_href($source_path, $width, $height)
{
if (!file_exists($source_path)) {
return null;
}
$name = "thumb-" . sha1("{$source_path}") . "-" . $width . "x" . $height . ".jpg";
$thumb_path = $this->thumbs_path . "/" . $name;
$thumb_url = $this->thumbs_href . "/" . $name;
if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) {
$image = new Image();
$et = false;
$opts = $this->app->get_options();
if (HAS_PHP_EXIF && $opts["thumbnails"]["exif"] === true && $height != 0) {
$et = @exif_thumbnail($source_path);
}
if ($et !== false) {
file_put_contents($thumb_path, $et);
$image->set_source($thumb_path);
$image->normalize_exif_orientation($source_path);
} else {
$image->set_source($source_path);
}
$image->thumb($width, $height);
$image->save_dest_jpeg($thumb_path, 80);
}
return file_exists($thumb_path) ? $thumb_url : null;
}
示例10: uploadImg
public function uploadImg()
{
if (!$this->is_login()) {
return;
}
import('ORG.Net.UploadFile');
import('ORG.Util.Image');
$where['id'] = array('in', array('1', '2', '3', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '48'));
$setInfo = $this->uploadSet->where($where)->select();
$imgAllowExts = explode(',', $setInfo[2]['value']);
$thumbMax = explode('x', $setInfo[5]['value']);
$imageMax = explode('x', $setInfo[4]['value']);
if (!file_exists('./' . $setInfo[0]['value'])) {
mkdir('./' . $setInfo[0]['value']);
}
$savepath = './' . $setInfo[0]['value'];
if ('1' == $setInfo[1]['value']) {
$savepath = $savepath . '/' . date('Ymd') . '/';
} else {
if (!file_exists($savepath . '/' . date('Ym'))) {
mkdir($savepath . '/' . date('Ym'));
}
$savepath = $savepath . '/' . date('Ym') . '/' . date('d') . '/';
}
if (!file_exists($savepath)) {
mkdir($savepath);
}
$config = array('maxSize' => $setInfo[3]['value'] * 1024, 'supportMulti' => true, 'allowExts' => $imgAllowExts, 'thumb' => true, 'thumbMaxWidth' => $thumbMax[0], 'thumbMaxHeight' => $thumbMax[1], 'thumbPrefix' => 'thumb_', 'thumbSuffix' => '', 'thumbPath' => $savepath, 'thumbFile' => '', 'thumbExt' => '', 'thumbRemoveOrigin' => false, 'zipImages' => false, 'autoSub' => false, 'subType' => 'hash', 'dateFormat' => 'Ymd', 'hashLevel' => 1, 'savePath' => $savepath, 'autoCheck' => true, 'uploadReplace' => false, 'saveRule' => 'uniqid', 'hashType' => 'md5_file');
$upload = new UploadFile($config);
// 實例化上傳類
$image = new Image();
if (!$upload->upload()) {
// 上傳錯誤提示錯誤信息
$msg = $upload->getErrorMsg();
print_r("{\"status\": 0, \"msg\":\"" . $msg . "\"}");
} else {
// 上傳成功 獲取上傳文件信息
$info = $upload->getUploadFileInfo();
// $imgPath = substr($info[0]['savepath'].$info[0]['savename'],1);
$imgPath = $info[0]['savepath'] . $info[0]['savename'];
$thumb = $info[0]['savepath'] . 'thumb_' . $info[0]['savename'];
$image->thumb($imgPath, $info[0]['savepath'] . 'headb_' . $info[0]['savename'], '', 160, 160);
$image->thumb($imgPath, $info[0]['savepath'] . 'headm_' . $info[0]['savename'], '', 60, 60);
print_r("{\"status\": 1,\"thumb\":\"" . substr($thumb, 1) . "\", \"path\": \"" . substr($imgPath, 1) . "\"}");
}
}
示例11: create
public function create($force = 0)
{
if ($force === 2 || $force === 1 && !file_exists($this->path) || file_exists($this->path) && filemtime($this->srcAbsPath) >= filemtime($this->path)) {
$image = new Image();
$image->setSource($this->srcAbsPath);
$image->thumb($this->mode, $this->width, $this->height);
$image->saveDest($this->path);
}
}
示例12: saveAvatar
function saveAvatar($uid, $faceurl)
{
$this->uid = $uid;
$original = $this->getSavePath() . "/original.jpg";
$big = $this->getSavePath() . "/big.jpg";
$small = $this->getSavePath() . "/small.jpg";
include SITE_PATH . '/addons/libs/Image.class.php';
Image::thumb($faceurl, $original, '', 150, 150);
Image::thumb($faceurl, $big, '', 120, 120);
Image::thumb($faceurl, $small, '', 50, 50);
}
示例13: upload
public function upload()
{
echo '<div style="font-size:12px; height:30px; line-height:30px">';
$uppath = './' . C('upload_path') . '/';
$uppath_s = './' . C('upload_path') . '-s/';
$mid = trim($_POST['mid']);
$fileback = !empty($_POST['fileback']) ? trim($_POST['fileback']) : 'picurl';
if ($mid) {
$uppath .= $mid . '/';
$uppath_s .= $mid . '/';
$backpath = $mid . '/';
}
import("ORG.Net.UploadFile");
$up = new UploadFile();
//$up->maxSize = 3292200;
$up->savePath = $uppath;
$up->saveRule = uniqid;
$up->uploadReplace = true;
$up->allowExts = explode(',', C('cms_exts'));
$up->autoSub = true;
$up->subType = date;
$up->dateFormat = C('upload_style');
if (!$up->upload()) {
$error = $up->getErrorMsg();
if ($error == '上傳文件類型不允許') {
$error .= ',可上傳<font color=red>' . C('cms_exts') . '</font>';
}
exit($error . ' [<a href="?s=Admin/Upload/Show/mid/' . $mid . '/fileback/' . $fileback . '">重新上傳</a>]');
//dump($up->getErrorMsg());
}
$uploadList = $up->getUploadFileInfo();
//是否添加水印
if (C('upload_water')) {
import("ORG.Util.Image");
Image::water($uppath . $uploadList[0]['savename'], C('upload_water_img'), '', C('upload_water_pct'), C('upload_water_pos'));
}
//是否生成縮略圖
if (C('upload_thumb')) {
$thumbdir = substr($uploadList[0]['savename'], 0, strrpos($uploadList[0]['savename'], '/'));
mkdirss($uppath_s . $thumbdir);
import("ORG.Util.Image");
Image::thumb($uppath . $uploadList[0]['savename'], $uppath_s . $uploadList[0]['savename'], '', C('upload_thumb_w'), C('upload_thumb_h'), true);
}
//是否遠程圖片
if (C('upload_ftp')) {
$img = D('Down');
$img->ftp_upload($backpath . $uploadList[0]['savename']);
}
echo "<script type='text/javascript'>parent.document.getElementById('" . $fileback . "').value='" . $backpath . $uploadList[0]['savename'] . "';</script>";
echo '文件<a href="' . $uppath . $uploadList[0]['savename'] . '" target="_blank"><font color=red>' . $uploadList[0]['savename'] . '</font></a>上傳成功 [<a href="?s=Admin/Upload/Show/mid/' . $mid . '/fileback/' . $fileback . '">重新上傳</a>]';
echo '</div>';
}
示例14: upLoad
public function upLoad()
{
if (isset($_POST['send'])) {
$_fileupload = new FileUpload('pic', $_POST['MAX_FILE_SIZE']);
$_path = $_fileupload->getPath();
$_img = new Image($_path);
$_img->thumb(300, 300);
$_img->out();
$_fileupload->alertOpenerClose('圖片上傳成功', '.' . $_path);
} else {
exit('警告:文件過大或者其他未知錯誤導致瀏覽器崩潰');
}
}
示例15: thumb_images
function thumb_images($pic)
{
$array_dir = explode('/', $pic);
$date_dir = $array_dir[3];
$image_name = $array_dir[5];
//組裝縮略圖路徑
$big = C('Goods_image_path') . '/' . $date_dir . '/big/b_' . $image_name;
$middle = C('Goods_image_path') . '/' . $date_dir . '/middle/m_' . $image_name;
$small = C('Goods_image_path') . '/' . $date_dir . '/small/s_' . $image_name;
import("ORG.Util.Image");
Image::thumb($pic, $big, '', C('Goods_big_width'), C('Goods_big_height'));
Image::thumb($pic, $middle, '', C('Goods_middle_width'), C('Goods_middle_width'));
Image::thumb($pic, $small, '', C('Goods_small_width'), C('Goods_small_width'));
}