时间:2021-07-01 10:21:17 帮助过:47人阅读
- <br><?php <br>list($width, $height, $type, $attr) = getimagesize("img/flag.jpg"); <br>echo "<img src=\"img/flag.jpg\" $attr>"; <br>?> <br> <br>URL 支持是 PHP 4.0.5 添加的。 <br>Example #2 getimagesize(URL) <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>$size = getimagesize("//www.gxlcms.com/images/logo.gif"); <br>// if the file name has space in it, encode it properly <br>$size = getimagesize("http://www.example.com/gifs/lo go.gif"); <br>?> <br> <br>对于 JPG 图像,还会多返回两个索引:channels 和 bits。channels 对于 RGB 图像其值为 3,对于 CMYK 图像其值为 4。bits 是每种颜色的位数。 <br>自 PHP 4.3.0 起,bits 和 channels 对于其它图像类型也存在。但是这些值可能会把人搞糊涂。例如,GIF 总是对每个像素使用 3 个 channel,但是对于动画 GIF 来说每个像素的位数无法通过全局颜色表计算出来。 <br>某些格式可能不包含图像或者包含多个图像。此种情况下,getimagesize() 可能不能用来准确测定图像的大小。此时 getimagesize() 将返回零作为宽度和高度。 <br>自 PHP 4.3.0 起,getimagesize() 还会返回额外的参数 mime,符合该图像的 MIME 类型。此信息可以用来在 HTTP Content-type 头信息中发送正确的信息: <br>Example #3 getimagesize() 和 MIME 类型 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>$size = getimagesize($filename); <br>$fp=fopen($filename, "rb"); <br>if ($size && $fp) { <br>header("Content-type: {$size['mime']}"); <br>fpassthru($fp); <br>exit; <br>} else { <br>// error <br>} <br>?> <br> <br>可选的 imageinfo 参数允许从图像文件中提取一些扩展信息。目前,这将以一个关联数组返回不同的 JPG APP 标识。某些程序用这些 APP 标识来在图像中嵌入文本信息。一个非常常见的是 APP13 标识中嵌入的 IPTC » http://www.iptc.org/ 信息。可以用 iptcparse() 函数来将二进制的 APP13 标识解析为可读的信息。 <br>Example #4 getimagesize() 返回 IPTC <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>$size = getimagesize("testimg.jpg", &$info); <br>if (isset($info["APP13"])) { <br>$iptc = iptcparse($info["APP13"]); <br>var_dump($iptc); <br>} <br>?> <br> <br><br>php 有个图片GD库getimagesize()函数。 <br>有个函数是获取图片的基本信息。 <br>getimagesize() <br>$img=getimagesize('图片源'); <br>宽度为=$img[0]; <br>高度为=$img[1]; <br>格式为=$img[2]; <br>如果你要简单的话可以更简单如 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>$picpath = '//www.gxlcms.com/images/logo.gif'; <br>$array = getimagesize($picpath); <br>print_r( $array ); <br>echo '图片宽度为'.$array[0]; <br>echo '图片高度为'.$array[1]; <br>echo '图片格式为'.$array[2]; <br> <br>//再一个利用getimagesize显示缩略图的代码 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>function show_thumbnail($file) <br>{ <br>$max = 200 // Max. thumbnail width and height <br>$size = getimagesize($file); <br>if ( $size[0] <= $max && $size[1] <= $max ) <br>{ <br>$ret = '<img src="'.$file.'" '.$size[3].' border="0">'; <br>} <br>else <br>{ <br>$k = ( $size[0] >= $size[1] ) ? $size[0] / $max : $size[1] / $max; <br>$ret = '<a href="javascript教程:;" onClick="window.open('image.php?img='; <br>$ret .= $file.'','','width='.$size[0]; <br>$ret .= ',height='.$size[1].'')">'; <br>$ret .= '<img src="'.$file.'" width="'.floor($size[0]/$k).'" height="'.floor($size[1]/$k).'" border="0" alt="View full-size image"></a>'; <br>} <br>return $ret; <br>} <br></li><li> </li><li> </li></ol></pre></li></ol></pre></li></ol></pre></li></ol></pre></li></ol></pre>