本文整理汇总了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'));
}