本文整理汇总了PHP中Image::getImageInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::getImageInfo方法的具体用法?PHP Image::getImageInfo怎么用?PHP Image::getImageInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::getImageInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: water
/**
* 图片加水印
* @param type $source 原图文件名。
* @param type $water 水印图片文件名
* @param type $savename 要保存的图片名,如果留空则用source
* @param type $alpha 水印图片的alpha值,默认为80,范围为0~100
* @param type $waterPos 水印位置。
* @param type $quality jpg图片质量
*/
public function water($source, $water = null, $savename = null, $alpha = null, $waterPos = null, $quality = null)
{
import("Image");
//设置默认水印
if ($water == '') {
$water = SITE_PATH . $this->Config['watermarkimg'];
}
//图像信息
$sInfo = Image::getImageInfo($source);
//如果图片小于系统设置,不进行水印添加
if ($sInfo["width"] < (int) $this->Config['watermarkminwidth'] || $sInfo['height'] < (int) $this->Config['watermarkminheight']) {
return false;
}
//水印位置
if (empty($waterPos)) {
$waterPos = (int) $this->Config['watermarkpos'];
}
//水印透明度
if (empty($alpha)) {
$alpha = (int) $this->Config['watermarkpct'];
}
//jpg图片质量
if (empty($quality)) {
$quality = (int) $this->Config['watermarkquality'];
}
return Image::water($source, $water, $savename, $alpha, $waterPos, $quality);
}
示例2: 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;
}
示例3: resizeImage
function resizeImage()
{
//lay duong dan file duoc request
$request = $_SERVER['REQUEST_URI'];
//lay ten file
$tmp_request = explode('/', $request);
$case = count($tmp_request);
$image_name = $tmp_request[$case - 1];
//type resize
$resize_type = $tmp_request[$case - 2];
//echo $image_name;
$resource_img = get_picture_dir($image_name) . '/' . $image_name;
$resource_img = '..' . $resource_img;
if (!file_exists($resource_img)) {
error_404_document();
}
//echo file_get_contents($resource_img);exit();
$images = new Image($resource_img);
$imageinfo = $images->getImageInfo();
if ($imageinfo['height'] == null || $imageinfo['height'] == 0) {
error_404_document();
}
//kich thuoc resize
$array_resize = array('large' => array(480, 360), 'medium' => array(240, 180), 'medium2' => array(145, 95), 'small' => array(106, 80), 'thumb' => array(50, 50), 'mobile' => array(640, 400), 'mobile_medium' => array(320, 200), 'mobile_small' => array(120, 75), 'mobile_low' => array(640, 400, 30), 'mobile_medium_low' => array(320, 200, 30), 'mobile_small_low' => array(120, 75, 30));
if (!isset($array_resize[$resize_type])) {
error_404_document();
}
//image name file no extension
$filesavename = explode('.', $image_name);
$count3 = count($filesavename);
if ($count3 > 1) {
unset($filesavename[$count3 - 1]);
}
$filesavename = implode('.', $filesavename);
$pathsave = '..' . get_picture_dir($image_name, $resize_type);
//nếu thư mục ảnh không tồn tại thì tạo mới
if (!file_exists($pathsave)) {
mkdir($pathsave, 0755, 1);
}
//echo $pathsave;die();
//kich thuoc resize ok -> tao file voi kich thuoc phu hop
$r_width = $array_resize[$resize_type][0];
$r_height = $array_resize[$resize_type][1];
if (isset($array_resize[$resize_type][2])) {
$r_quality = $array_resize[$resize_type][2];
} else {
$r_quality = 100;
}
if ($resize_type == 'organic') {
$images->resize($r_width, $r_height, 'fit', 'c', 'c', $r_quality);
} else {
$images->resize($r_width, $r_height, 'crop', 'c', 'c', $r_quality);
}
$images->save($filesavename, $pathsave);
header("HTTP/1.0 200 OK");
$images->display();
}
示例4: showImg
/**
* 显示服务器图像文件 支持URL方式
* @param string $imgFile 图像文件名
* @param string $text 文字字符串
* @param string $width 图像宽度
* @param string $height 图像高度
* @return void
*/
public static function showImg($imgFile, $text = '', $width = 80, $height = 30)
{
//获取图像文件信息
$info = Image::getImageInfo($imgFile);
if ($info !== false) {
//修改读取bmp图片
$createFun = str_replace('/', 'createfrom', $info['mime']);
if (strrpos($info['mime'], 'bmp')) {
$strImg = "";
$strImg = file_get_contents($imgFile);
header("Content-type: " . $info['mime']);
echo $strImg;
return;
}
$im = $createFun($imgFile);
if ($im) {
$ImageFun = str_replace('/', '', $info['mime']);
if (!empty($text)) {
$tc = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 3, 5, 5, $text, $tc);
}
if ($info['type'] == 'png' || $info['type'] == 'gif') {
imagealphablending($im, false);
//取消默认的混色模式
imagesavealpha($im, true);
//设定保存完整的 alpha 通道信息
}
header("Content-type: " . $info['mime']);
$ImageFun($im);
imagedestroy($im);
return;
}
}
//获取或者创建图像文件失败则生成空白PNG图片
$im = imagecreatetruecolor($width, $height);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 4, 5, 5, "NO PIC", $tc);
Image::output($im);
return;
}
示例5: copyImage
/**
*
* @param $origin_path 原始物理图片地址
* @param array $sizes 缩略图大小信息 为空则取后台设置
可生成多个缩略图
数组 参数1 为宽度,
参数2为高度,
参数3为处理方式:0(缩放,默认),1(剪裁),
参数4为是否水印 默认为 0(不生成水印)
array(
array(300,300,0,0),
array(100,100,0,0),
...
),
* @param $path 存储的路径
* @param $file_name 保存的文件名
* @param $del_temp 是否删除临时文件
* @param $id 关联编号,将根据编号生成目录
*
* 返回 复制成功的信息,如为false则复制失败
* array(
* 'path' => xxx //物理路径
* 'url' => xxx //相对路径
* );
*
* by fzmatthew
*/
function copyImage($origin_path, $sizes = array(), $path = 'share', $del_temp = true, $id = 0)
{
global $_FANWE;
static $size_setting = NULL, $image = NULL;
if ($image === NULL) {
include_once fimport('class/image');
$image = new Image();
}
if ($path == 'temp') {
$dir = './public/upload/temp/' . fToDate(NULL, 'Y/m/d/H');
} else {
if ($id > 0) {
$dir = './public/upload/' . $path . '/' . getDirsById($id);
} else {
$dir = './public/upload/' . $path . '/' . fToDate(NULL, 'Y/m/d');
}
}
makeDir(FANWE_ROOT . $dir);
$file_name = md5(microtime(true)) . random('6') . '.jpg';
$file_path = FANWE_ROOT . $dir . "/" . $file_name;
$bln = false;
if (file_exists($origin_path) && @copy($origin_path, $file_path)) {
$bln = true;
} else {
$data = getUrlContent($origin_path);
if (!empty($data) && @file_put_contents($file_path, $data) > 0) {
$bln = true;
}
}
if ($bln) {
$info = $image->getImageInfo($file_path);
if ($info['type'] != 'jpg' && $info['type'] != 'jpeg') {
if (!$image->convertType($file_path, $file_path)) {
return false;
}
}
$water_image = $_FANWE['setting']['water_image'];
if (!empty($water_image)) {
$water_image = FANWE_ROOT . $water_image;
}
$water_mark = intval($_FANWE['setting']['water_mark']);
$alpha = intval($_FANWE['setting']['water_alpha']);
$place = intval($_FANWE['setting']['water_position']);
if ($sizes !== false && empty($sizes)) {
if ($size_setting === NULL) {
if (!isset($_FANWE['cache']['image_sizes'])) {
FanweService::instance()->cache->loadCache('image_sizes');
}
$size_setting = $_FANWE['cache']['image_sizes'];
}
$sizes = $size_setting;
}
foreach ($sizes as $size) {
if ($size[0] > 0 || $size[1] > 0) {
$thumb_bln = false;
$thumb_type = isset($size[2]) ? intval($size[2]) : 0;
if ($thumb = $image->thumb($file_path, $size[0], $size[1], $thumb_type)) {
if (isset($size[3]) && intval($size[3]) > 0) {
$image->water($thumb['path'], $water_image, $alpha, $place);
}
}
}
}
if ($del_temp) {
@unlink($origin_path);
}
return array('path' => $file_path, 'url' => $dir . "/" . $file_name, 'width' => $info[0], 'height' => $info[1]);
} else {
return false;
}
}
示例6: water
/**
* 用于图片附件上传加水印回调方法
* @param type $_this
* @param type $fileInfo
* @param type $params
*/
public static function water($_this, $fileInfo, $params)
{
//网站拍照
$config = cache('Config');
//是否开启水印
if (empty($config['watermarkenable'])) {
return false;
}
//水印文件
$water = SITE_PATH . $config['watermarkimg'];
//水印位置
$waterPos = (int) $config['watermarkpos'];
//水印透明度
$alpha = (int) $config['watermarkpct'];
//jpg图片质量
$quality = (int) $config['watermarkquality'];
foreach ($fileInfo as $file) {
//原图文件
$source = $file['savepath'] . $file['savename'];
//图像信息
$sInfo = \Image::getImageInfo($source);
//如果图片小于系统设置,不进行水印添加
if ($sInfo["width"] < (int) $config['watermarkminwidth'] || $sInfo['height'] < (int) $config['watermarkminheight']) {
continue;
}
\Image::water($source, $water, $source, $alpha, $waterPos, $quality);
}
}
示例7: ResizeWithCenterCrop
public static function ResizeWithCenterCrop($image, $dir, $filename, $target_w, $target_h)
{
list($curr_w, $curr_h, $type, $attr) = Image::getImageInfo($image);
$ext = 'jpg';
switch ($type) {
// create image
case IMAGETYPE_JPEG:
$ext = 'jpg';
break;
case IMAGETYPE_PNG:
$ext = 'png';
break;
case IMAGETYPE_GIF:
$ext = 'gif';
break;
case 'image/svg+xml':
$ext = 'svg';
break;
default:
return false;
}
$scale_h = $target_h / $curr_h;
$scale_w = $target_w / $curr_w;
$factor_x = $curr_w / $target_w;
$factor_y = $curr_h / $target_h;
if ($factor_x > $factor_y) {
$factor = $factor_y;
} else {
$factor = $factor_x;
}
$up_w = ceil($target_w * $factor);
$up_h = ceil($target_h * $factor);
$x_start = ceil(($curr_w - $up_w) / 2);
$y_start = ceil(($curr_h - $up_h) / 2);
switch ($type) {
// create image
case IMAGETYPE_JPEG:
$n_img = imagecreatefromjpeg($image);
break;
case IMAGETYPE_PNG:
$n_img = imagecreatefrompng($image);
break;
case IMAGETYPE_GIF:
$n_img = imagecreatefromgif($image);
break;
case 'image/svg+xml':
break;
default:
return false;
}
$dst_img = ImageCreateTrueColor($target_w, $target_h);
switch ($type) {
// fix for transparency issues
case IMAGETYPE_PNG:
imagealphablending($dst_img, true);
imagesavealpha($dst_img, true);
$transparent_color = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
imagefill($dst_img, 0, 0, $transparent_color);
break;
case IMAGETYPE_GIF:
$transparency_index = imagecolortransparent($dst_img);
if ($transparency_index >= 0) {
$transparent_color = imagecolorsforindex($dst_img, $transparency_index);
$transparency_index = imagecolorallocate($dst_img, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($dst_img, 0, 0, $transparency_index);
imagecolortransparent($dst_img, $transparency_index);
}
break;
default:
break;
}
// (for testing) die('curr_w='.$curr_w.' curr_h='.$curr_h.' x_start='.$x_start.' y_start='.$y_start.' target_w='.$target_w.' target_h='.$target_h.' up_w='.$up_w.' up_h='.$up_h);
if ($type != 'image/svg+xml') {
imagecopyresampled($dst_img, $n_img, 0, 0, $x_start, $y_start, $target_w, $target_h, $up_w, $up_h);
}
//return $dst_img;
$full = $dir . $filename;
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
switch ($ext) {
case 'jpg':
imagejpeg($dst_img, $full, 100);
$size = filesize($full);
return $size;
break;
case 'png':
imagepng($dst_img, $full);
$size = filesize($full);
return $size;
break;
case 'gif':
imagegif($dst_img, $full);
$size = filesize($full);
return $size;
break;
case 'svg':
copy($image, $full);
// we just copy it, SVG is vectorized it scales directly in browser
$size = filesize($full);
//.........这里部分代码省略.........
示例8: uploadImg
public function uploadImg()
{
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', '52', '53'));
$setInfo = $this->uploadSet->where($where)->select();
$imgAllowExts = explode(',', $setInfo[2]['value']);
$thumbMax = explode('x', $setInfo[5]['value']);
$imageMax = explode('x', $setInfo[4]['value']);
$bthumbMax = explode('x', $setInfo[14]['value']);
$sthumbMax = explode('x', $setInfo[15]['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'];
$imgInfo = $image->getImageInfo($imgPath);
$thumb = $info[0]['savepath'] . 'thumb_' . $info[0]['savename'];
if ($imageMax[0] < $imgInfo['width'] || $imageMax[1] < $imgInfo['height']) {
$image->thumb($imgPath, $imgPath, '', $imageMax[0], $imageMax[1]);
}
$image->thumb($imgPath, $info[0]['savepath'] . 'bthumb_' . $info[0]['savename'], '', $bthumbMax[0], $bthumbMax[1]);
$image->thumb($imgPath, $info[0]['savepath'] . 'sthumb_' . $info[0]['savename'], '', $sthumbMax[0], $sthumbMax[1]);
if (2 == $setInfo[6]['value']) {
import(APP_NAME . ".Action.WaterMask");
$water = new WaterMask($imgPath);
$water->waterType = 0;
//水印类型:0为文字水印、1为图片水印
$water->pos = $setInfo[7]['value'];
//水印位置
$water->transparent = $setInfo[10]['value'] * 10;
//水印透明度
$water->waterStr = $setInfo[11]['value'];
//水印文字
$water->fontFile = "./Public/font/" . $setInfo[12]['value'] . ".ttf";
//字体名称
$water->fontSize = $setInfo[13]['value'];
//字体大小
$water->fontColor = array(255, 0, 255);
//水印文字颜色(RGB值)
$water->output();
//输出水印图片
} elseif (3 == $setInfo[6]['value']) {
import(APP_NAME . ".Action.WaterMask");
$water = new WaterMask($imgPath);
$water->waterType = 1;
//水印类型:0为文字水印、1为图片水印
$water->pos = $setInfo[7]['value'];
//水印位置
$water->transparent = $setInfo[10]['value'] * 10;
//水印透明度
$water->waterStr = $setInfo[11]['value'];
//水印文字
$water->fontFile = "./Public/font/" . $setInfo[12]['value'] . ".ttf";
//字体名称
$water->fontSize = $setInfo[13]['value'];
//字体大小
$water->fontColor = array(255, 0, 255);
//水印文字颜色(RGB值)
$water->waterImg = "./Public/waterImg/" . $setInfo[9]['value'];
//水印图片
$water->output();
//输出水印图片
} else {
}
//写入登录日志
$l = M('managerlog');
$data['user_id'] = $_SESSION['userID'];
$data['user_name'] = $_SESSION['userName'];
$data['action_type'] = "uploadImg";
$data['remark'] = "上传图片";
$data['user_ip'] = $_SERVER["REMOTE_ADDR"];
$data['add_time'] = date('y-m-d h:i:s', time());
$data['time'] = time();
$flag = $l->add($data);
if ($flag) {
print_r("{\"status\": 1,\"thumb\":\"" . substr($thumb, 1) . "\", \"path\": \"" . substr($imgPath, 1) . "\"}");
//.........这里部分代码省略.........
示例9: save
/**
+----------------------------------------------------------
* 上传一个文件
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param mixed $name 数据
* @param string $value 数据表名
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
private function save($file)
{
$filename = $file['savepath'] . $file['savename'];
if (!$this->uploadReplace && is_file($filename)) {
// 不覆盖同名文件
$this->error = '文件已经存在!' . $filename;
return false;
}
if (!move_uploaded_file($file['tmp_name'], auto_charset($filename, 'utf-8', 'gbk'))) {
$this->error = '文件上传保存错误!';
return false;
}
if ($this->thumb) {
// 生成图像缩略图
import("@.ORG.Image");
$image = Image::getImageInfo($filename);
if (false !== $image) {
//是图像文件生成缩略图
$thumbWidth = explode(',', $this->thumbMaxWidth);
$thumbHeight = explode(',', $this->thumbMaxHeight);
$thumbPrefix = explode(',', $this->thumbPrefix);
$thumbSuffix = explode(',', $this->thumbSuffix);
$thumbFile = explode(',', $this->thumbFile);
$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->thumbRemoveOrigin) {
// 生成缩略图之后删除原图
unlink($filename);
}
}
}
if ($this->zipImags) {
// TODO 对图片压缩包在线解压
}
return true;
}
示例10: die
$path = $_GET['path'];
} else {
die(IMG_GEN_IMG_NOT_EXISTS);
}
require_once CLASS_HISTORY;
$history = new History($path, $session);
if (CONFIG_SYS_DEMO_ENABLE) {
$sessionImageInfo = $history->getLastestRestorable();
$originalSessionImageInfo = $history->getOriginalImage();
if (sizeof($originalSessionImageInfo)) {
$path = backslashToSlash($session->getSessionDir() . $originalSessionImageInfo['info']['name']);
}
}
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "class.image.php";
$image = new Image();
$imageInfo = $image->getImageInfo($path);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Logan Cai" />
<meta name="website" content="http://www.phpletter.com" />
<script type="text/javascript" src="js/ajaximageeditor_c.js"></script>
<!--<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/select.js"></script>
<script type="text/javascript" src="js/jqModal.js"></script>
<script type="text/javascript" src="js/rotate.js"></script>
<script type="text/javascript" src="js/interface.js"></script>-->
示例11: thumb
function thumb($image, $type = '', $filename = '', $maxWidth = 200, $maxHeight = 50, $warterMark = '', $interlace = true, $suffix = '_thumb')
{
// 获取原图信息
$info = Image::getImageInfo($image);
if ($info !== false) {
$srcWidth = $info['width'];
$srcHeight = $info['height'];
$pathinfo = pathinfo($image);
$type = $pathinfo['extension'];
$type = empty($type) ? $info['type'] : $type;
$type = strtolower($type);
$interlace = $interlace ? 1 : 0;
unset($info);
$scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
// 计算缩放比例
// 缩略图尺寸
$width = (int) ($srcWidth * $scale);
$height = (int) ($srcHeight * $scale);
// 载入原图
$createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
$srcImg = $createFun($image);
//创建缩略图
if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
$thumbImg = imagecreatetruecolor($width, $height);
} else {
$thumbImg = imagecreate($width, $height);
}
// 复制图片
if (function_exists("ImageCopyResampled")) {
ImageCopyResampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
} else {
ImageCopyResized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
}
ImageDestroy($srcImg);
/*
//水印开始
//计算水印的位置,默认居中
$textInfo = Image::getImageInfo($warterMark);
$textW = $textInfo["width"];
$textH = $textInfo["height"];
unset($textInfo);
$mark = imagecreatefrompng($warterMark);
$imgW = $width;
$imgH = $width*$textH/$textW;
$y = ($height-$textH)/2;
if(function_exists("ImageCopyResampled")){
ImageCopyResampled($thumbImg,$mark,0,$y,0,0, $imgW,$imgH, $textW,$textH);
}else{
ImageCopyResized($thumbImg,$mark,0,$y,0,0,$imgW,$imgH, $textW,$textH);
}
ImageDestroy($mark);
//水印结束
*/
if ('gif' == $type || 'png' == $type) {
imagealphablending($thumbImg, FALSE);
//取消默认的混色模式
imagesavealpha($thumbImg, TRUE);
//设定保存完整的 alpha 通道信息
$background_color = ImageColorAllocate($thumbImg, 0, 255, 0);
// 指派一个绿色
imagecolortransparent($thumbImg, $background_color);
// 设置为透明色,若注释掉该行则输出绿色的图
}
if ('jpg' == $type || 'jpeg' == $type) {
imageinterlace($thumbImg, $interlace);
// 对jpeg图形设置隔行扫描
}
// 生成图片
// $imageFun = 'image'.($type=='jpg'?'jpeg':$type);
$imageFun = 'imagepng';
$filename = empty($filename) ? substr($image, 0, strrpos($image, '.')) . $suffix . '.' . $type : $filename;
$imageFun($thumbImg, $filename);
ImageDestroy($thumbImg);
return $filename;
}
return false;
}
示例12: water
/**
* 用于图片附件上传加水印回调方法
* @param type $_this
* @param type $fileInfo
* @param type $params
*/
public static function water($_this, $fileInfo, $params)
{
import("Image");
//水印文件
$water = SITE_PATH . CONFIG_WATERMARKIMG;
//水印位置
$waterPos = (int) CONFIG_WATERMARKPOS;
//水印透明度
$alpha = (int) CONFIG_WATERMARKPCT;
//jpg图片质量
$quality = (int) CONFIG_WATERMARKQUALITY;
foreach ($fileInfo as $file) {
//原图文件
$source = $file['savepath'] . $file['savename'];
//图像信息
$sInfo = Image::getImageInfo($source);
//如果图片小于系统设置,不进行水印添加
if ($sInfo["width"] < (int) CONFIG_WATERMARKMINWIDTH || $sInfo['height'] < (int) CONFIG_WATERMARKMINHEIGHT) {
continue;
}
Image::water($source, $water, $source, $alpha, $waterPos, $quality);
}
}
示例13: UploadFile
// 开始上传
$upload = new UploadFile($upload_config);
// 返回结果
$result = array();
if (!$upload->upload()) {
$result = $upload->getErrorMsg();
} else {
$result = $upload->getUploadFileInfo();
}
/**
* die('<script>alert(\''.json_encode($result).'\');</script>');
*/
// 拼装回调参数
$files = array();
foreach ($result as $f) {
$img = Image::getImageInfo($f['savepath'] . $f['savename']);
//图片信息
//die('<script>alert(\''.json_encode($f).'\');</script>');
// $resource_url=$file1['original']='http://'.$_SERVER['HTTP_HOST'].'/upload/'.substr($f['savepath'],2).$f['savename'];
$resource_url = $file1['original'] = SITE_PATH . 'upload/' . substr($f['savepath'], 2) . $f['savename'];
$r_size = $file1['size'] = $f['size'];
$r_width = $file1['width'] = isset($img['width']) ? $img['width'] : 0;
$r_height = $file1['height'] = isset($img['height']) ? $img['height'] : 0;
$r_oname = $file1['oname'] = substr($f['name'], 0, strrpos($f['name'], '.'));
switch ($f['extension']) {
case 'zip':
case 'rar':
$resource_type = 3;
break;
case 'flv':
$resource_type = 2;
示例14: thumb
/**
+----------------------------------------------------------
* 生成缩略图
+----------------------------------------------------------
* @static
* @access public
+----------------------------------------------------------
* @param string $image 原图
* @param string $type 图像格式
* @param string $thumbname 缩略图文件名
* @param string $maxWidth 宽度
* @param string $maxHeight 高度
* @param string $position 缩略图保存目录
* @param boolean $interlace 启用隔行扫描
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
static function thumb($image, $thumbname, $maxWidth, $maxHeight, $type = '', $interlace = true)
{
// 获取原图信息
$info = Image::getImageInfo($image);
if ($info !== false) {
$srcWidth = $info['width'];
$srcHeight = $info['height'];
$type = empty($type) ? $info['type'] : $type;
$type = strtolower($type);
$interlace = $interlace ? 1 : 0;
unset($info);
$scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
// 计算缩放比例
if ($scale >= 1) {
// 超过原图大小不再缩略
$width = $srcWidth;
$height = $srcHeight;
} else {
// 缩略图尺寸
$width = (int) ($srcWidth * $scale);
$height = (int) ($srcHeight * $scale);
}
// 载入原图
$createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
if (!function_exists($createFun)) {
return false;
}
$srcImg = $createFun($image);
//创建缩略图
if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
$thumbImg = imagecreatetruecolor($width, $height);
} else {
$thumbImg = imagecreate($width, $height);
}
//png和gif的透明处理 by luofei614
if ('png' == $type) {
imagealphablending($thumbImg, false);
//取消默认的混色模式(为解决阴影为绿色的问题)
imagesavealpha($thumbImg, true);
//设定保存完整的 alpha 通道信息(为解决阴影为绿色的问题)
} elseif ('gif' == $type) {
$trnprt_indx = imagecolortransparent($srcImg);
if ($trnprt_indx >= 0) {
//its transparent
$trnprt_color = imagecolorsforindex($srcImg, $trnprt_indx);
$trnprt_indx = imagecolorallocate($thumbImg, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
imagefill($thumbImg, 0, 0, $trnprt_indx);
imagecolortransparent($thumbImg, $trnprt_indx);
}
}
// 复制图片
if (function_exists("ImageCopyResampled")) {
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
} else {
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
}
// 对jpeg图形设置隔行扫描
if ('jpg' == $type || 'jpeg' == $type) {
imageinterlace($thumbImg, $interlace);
}
// 生成图片
$imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
$imageFun($thumbImg, $thumbname);
imagedestroy($thumbImg);
imagedestroy($srcImg);
return $thumbname;
}
return false;
}
示例15: event
//.........这里部分代码省略.........
$arr[$i]['showend2'] = date("Y-m-d H:i:s", $time);
$arr[$i]['channel'] = 10;
$l = $sheet->getCellByColumnAndRow(4, $i)->getValue();
$arr[$i]['dir'] = $path . $filename . '/' . $l . '/';
$arr[$i]['writer'] = $sheet->getCellByColumnAndRow(4, $i)->getValue();
$arr[$i]['albumnum'] = $sheet->getCellByColumnAndRow(5, $i)->getValue();
$arr[$i]['typeid'] = $sheet->getCellByColumnAndRow(6, $i)->getValue();
if (empty($arr[$i]['typeid'])) {
unset($arr[$i]);
continue;
}
$msg .= 'typeid ' . $arr[$i]['typeid'] . '___';
$arr[$i]['maps'] = $this->br_or_b($sheet->getCellByColumnAndRow(8, $i)->getValue());
$arr[$i]['event']['detail'] = $this->br_or_b($sheet->getCellByColumnAndRow(7, $i)->getValue());
$kw = str_word_count($arr[$i]['title'], 1);
$keywords = "";
foreach ($kw as $vkw) {
$keywords .= $vkw . ',';
}
$arr[$i]['keywords'] = trim($keywords, ',');
$arr[$i]['my_content'] = strip_tags($arr[$i]['event']['detail']);
$arr[$i]['description'] = $arr[$i]['my_content'];
if ($arr[$i]['albumnum'] || $arr[$i]['albumnum'] == '0') {
$flist = $this->file_list($arr[$i]['dir']);
//dump($flist);
$img = count($flist);
$num = $arr[$i]['albumnum'] + 1;
if ($num != $img) {
$msg .= $l . '图片数量不正确实际图:' . $img . '填写图片:' . $arr[$i]['albumnum'] . "<br>\n";
$errnum++;
} else {
$msg .= $l . "信息图片匹配<br>\n";
foreach ($flist as $v) {
$type = Image::getImageInfo($v);
if ($type['type'] == 'bmp') {
$msg .= '<b>' . $v . '图片格式不能是bmp</b><br>';
$warr++;
} elseif ($act == 'ok' && !empty($filename)) {
//是否确认写入
$filelen = strpos($v, '.');
//获取文件名长度
$filename_name = substr($v, 0, $filelen);
//截取文件名
$filename_name = end(explode("/", $filename_name));
$ext = strtolower(end(explode(".", $v)));
if ($filename_name == '0') {
$width = array('120', '514');
$height = array('140', '600');
$pre = array('s_', 'm_');
$fname = 's_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
$dir = $l . '/' . date("Y_m_d") . '/';
$spath = 'Public/event/exl' . $filename . '/' . $dir;
//dump($spath);
if (in_array($dir . $fname, $img_arr)) {
$arr[$i]['picurl'] = '/' . $spath . $fname;
$arr[$i]['pic'][]['filename'] = '/' . $spath . 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
} else {
$img_arr[$i] = $dir . $fname;
$this->mvimg($v, $spath, md5_file(auto_charset($v, 'utf-8', 'gbk')), $width, $height, $pre);
$arr[$i]['picurl'] = '/' . $spath . $fname;
$arr[$i]['pic'][]['filename'] = '/' . $spath . 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
}
} else {
$width = array('514');
$height = array('600');
$pre = array('m_');