【发布时间】:2012-08-10 13:27:14
【问题描述】:
我在 MySQL 表中有图像位置的 url。我如何检索该图像的高度和宽度并将其插入到下面的 img 标签中?
<img id="profileImg" alt="" height="96" width="87" src="<?=base_url().$row1->imgURI?>" />
【问题讨论】:
标签: php mysql html codeigniter
我在 MySQL 表中有图像位置的 url。我如何检索该图像的高度和宽度并将其插入到下面的 img 标签中?
<img id="profileImg" alt="" height="96" width="87" src="<?=base_url().$row1->imgURI?>" />
【问题讨论】:
标签: php mysql html codeigniter
与http://php.net/manual/en/function.getimagesize.php
<?php
list($width, $height, $type, $attr) = getimagesize(base_url() . $row1->imgURI);
?>
<img id="profileImg" alt="" height="<?=$height?>" width="<?=$width?>" src="<?=base_url().$row1->imgURI?>" />
此外,如果您可以导出图像文件的本地路径以避免必须通过其 url 访问文件,那就太好了。但我会留给它。
【讨论】:
height="<?=$height*0.9?>" width="<?=$width*0.9?>" 为 90%
例如通过使用 GD 库函数 getimagesize():http://php.net/manual/en/function.getimagesize.php
【讨论】:
这是使用getimagesize 函数最简单的检索方法:
list($width, $height, $type, $attr) = getimagesize ( base_url() . $row1->imgURI );
<img id="profileImg" alt="" <?=$attr?> src="<?=base_url().$row1->imgURI?>" />
【讨论】:
如果您没有实际的width 和height 存储在数据库中,您可以使用getimagesize():
<?php
$image = base_url().$row1->imgURI;
$size = getimagesize($image);
?>
<img id="profileImg" alt="" height="<?=$size[1];?>" width="<?=$size[0];?>" src="<?=$image;?>" />
【讨论】: