本文整理汇总了PHP中image::info方法的典型用法代码示例。如果您正苦于以下问题:PHP image::info方法的具体用法?PHP image::info怎么用?PHP image::info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thumb
function thumb($image, $filename = '', $maxwidth = 200, $maxheight = 200, $suffix='', $autocut = 0, $ftp = 0) {
if(!$this->thumb_enable || !$this->check($image)) return false;
$info = image::info($image);
if($info === false) return false;
$srcwidth = $info['width'];
$srcheight = $info['height'];
$pathinfo = pathinfo($image);
$type = $pathinfo['extension'];
if(!$type) $type = $info['type'];
$type = strtolower($type);
unset($info);
$creat_arr = $this->getpercent($srcwidth,$srcheight,$maxwidth,$maxheight);
$createwidth = $width = $creat_arr['w'];
$createheight = $height = $creat_arr['h'];
$psrc_x = $psrc_y = 0;
if($autocut && $maxwidth > 0 && $maxheight > 0) {
if($maxwidth/$maxheight<$srcwidth/$srcheight && $maxheight>=$height) {
$width = $maxheight/$height*$width;
$height = $maxheight;
}elseif($maxwidth/$maxheight>$srcwidth/$srcheight && $maxwidth>=$width) {
$height = $maxwidth/$width*$height;
$width = $maxwidth;
}
$createwidth = $maxwidth;
$createheight = $maxheight;
}
$createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type);
$srcimg = $createfun($image);
if($type != 'gif' && function_exists('imagecreatetruecolor'))
$thumbimg = imagecreatetruecolor($createwidth, $createheight);
else
$thumbimg = imagecreate($width, $height);
if(function_exists('imagecopyresampled'))
imagecopyresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight);
else
imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight);
if($type=='gif' || $type=='png') {
$background_color = imagecolorallocate($thumbimg, 0, 255, 0); // 指派一个绿色
imagecolortransparent($thumbimg, $background_color); // 设置为透明色,若注释掉该行则输出绿色的图
}
if($type=='jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
$imagefun = 'image'.($type=='jpg' ? 'jpeg' : $type);
if(empty($filename)) $filename = substr($image, 0, strrpos($image, '.')).$suffix.'.'.$type;
$imagefun($thumbimg, $filename);
imagedestroy($thumbimg);
imagedestroy($srcimg);
if($ftp) {
@unlink($image);
}
return $filename;
}
示例2: zoom
static function zoom($picture, $file_name = array('eq80_test.png', 'file/create/'), $length, $is_height = false)
{
$image = image::open($picture);
$start_width = image::info($image, 'width');
$start_height = image::info($image, 'height');
$end_width = $length;
$end_height = round($start_height * $end_width / $start_width);
if ($is_height) {
$end_width = round($start_width * $length / $start_height);
$end_height = $length;
}
$canvas = image::create($end_width, $end_height, 'ffffff', true);
$param = array(0, 0, 0, 0, $end_width, $end_height, $start_width, $start_height);
image::copy($canvas, $image, $param, 4);
image::save($canvas, $file_name[0], $file_name[1]);
return $file_name[1] . $file_name[0];
}
示例3: upload
public function upload()
{
//上传文件
$this->files = $this->upload->save();
//设置错误
if ($this->upload->error()) {
$this->error($this->upload->error(), $this->upload->msg());
}
if (is_array($this->files)) {
//保存文件
$ip = ip::current();
$userid = $this->_user['id'];
$description = (array) $this->description;
foreach ($this->files as $key => $file) {
$file['id'] = $file['id'];
$file['parentid'] = $file['id'];
$file['globalid'] = $this->globalid;
$file['groupid'] = $this->folderid;
$file['field'] = $this->field;
$file['type'] = file::type($file['path']);
$file['description'] = empty($description[$key]) ? $file['description'] : $description[$key];
$file['userid'] = $userid;
$file['status'] = (int) $this->status;
$file['createip'] = $ip;
$file['createtime'] = TIME;
if ($file['type'] == 'image' || preg_match('/^(jpeg|jpeg|png|gif|bmp|ico|tif|tiff|psd|xbm|xcf)$/', $file['ext'])) {
$info = image::info($file['path']);
$file['width'] = (int) $info['width'];
$file['height'] = (int) $info['height'];
}
$this->insert($file);
}
return $this->files;
}
return array();
}