php图片上传规格_php检测上传图片的长度和宽度

/*

array getimagesize ( string $filename [, array &$imageinfo ] )

getimagesize()函数将确定任何给定的图像大小的文件,并返回随着文件类型和高度/宽度的文本字符串是在一个正常的HTML IMG标签和相应的HTTP内容类型所使用的尺寸。

The getimagesize() function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML I www.jquerycn.cn MG tag and the correspondant HTTP content type

和getimagesize()也可以返回一些imageinfo参数的更多信息。

注意:请注意,少年警讯和JP2是有不同位深度组件的能力。在这种情况下,为“比特”的价值是最高的位深度的困难。此外,JP2上的JPEG文件可能包含多个2000 codestreams。在这种情况下,和getimagesize()返回第一个码流的价值是在文件的根接触。

注:有关资料检索图标从最高比特率图标。

*/

list($width, $height) = getimagesize($image);

$new_dimensions = resize_dimensions(300,400,$width,$height);

// Calculates restricted dimensions with a maximum of $goal_width by $goal_height

function resize_dimensions($goal_width,$goal_height,$width,$height) {

$return = array('width' => $width, 'height' => $height);

// If the ratio > goal ratio and the width > goal width resize down to goal width

if ($width/$height > $goal_width/$goal_height && $width > $goal_width) {

$return['width'] = $goal_width;

$return['height'] = $goal_width/$width * $height;

}

// Otherwise, if the height > goal, resize down to goal height

else if ($height > $goal_height) {

$return['width'] = $goal_height/$height * $width;

$return['height'] = $goal_height;

}

return $return;

}

/*

上面的函数我们就是利用

php 有个图片GD库getimagesize()函数。

有个函数是获取图片的基本信息。

getimagesize()

$img=getimagesize('图片源');

宽度为=$img[0];

高度为=$img[1];

格式为=$img[2];

如果你要简单的话可以更简单如

*/

$picpath = 'ww.jquerycn.cn.gif';

$array = getimagesize($picpath);

print_r( $array );

echo '图片宽度为'.$array[0];

echo '图片高度为'.$array[1];

echo '图片格式为'.$array[2];

方法四

//renumber

$my_image = array_values(getimagesize('test.jpg'));

//use list on new array

list($width, $height, $type, $attr) = $my_image;

//view new array

print_r($my_image);

//spit out content

echo 'Attribute: '.$attr.'
';

echo 'Width: '.$width.'
';

//这里面就会有图片的宽度与高度了

//再一个利用getimagesize显示缩略图的代码

function show_thumbnail($file)

{

$max = 200 // Max. thumbnail width and height

$size = getimagesize($file);

if ( $size[0] <= $max && $size[1] <= $max )

{

        $ret = ''.%24file.'';

}

else

{

$k = ( $size[0] >= $size[1] ) ? $size[0] / $max : $size[1] / $max;

$ret = '';

        $ret .= 'View full-size image';

}

return $ret;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值