Home  >  Article  >  php教程  >  php 获取图片尺寸的方法

php 获取图片尺寸的方法

WBOY
WBOYOriginal
2016-06-08 17:22:251805browse

在php中获取图片大小我们可以使用getimagesize函数,这个函数是用于获取图像的尺寸的函数,下面我们一起来看例子。

<script>ec(2);</script>

利用getimagesize函数就可以获取

 代码如下 复制代码

/*

    
php 获取图片尺寸的方法

*/

$url='/images/201203/08/1331189004_28093400.jpg';
 
$imageInfo=getimagesize($url);
print_r($imageInfo);
/*

 
Array

(

    
[0] => 139

    
[1] => 162

    
[2] => 2

    
[3] => width="139" height="162"

    
[bits] => 8

    
[channels] => 3

    
[mime] => image/jpeg

)

 
*/

利用我们获取的宽度与高度我们对图片进行设置

 代码如下 复制代码

$arr = getimagesize("1.jpg");
/**
 * 这里$arr为一个数组类型
 * $arr[0] 为图像的宽度
 * $arr[1] 为图像的高度
 * $arr[2] 为图像的格式,包括jpg、gif和png等
 * $arr[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy"
 */
/* 以下两行代码输出的内容都是一样的 */
echo "";
echo "";
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn