我拥有MySQL表格中图片位置的url。我将如何检索该图像的高度和宽度并将其插入到下面的img标签中?从MySQL中获取图片的高度和宽度db
<img id="profileImg" alt="" height="96" width="87" src="<?=base_url().$row1->imgURI?>" />
我拥有MySQL表格中图片位置的url。我将如何检索该图像的高度和宽度并将其插入到下面的img标签中?从MySQL中获取图片的高度和宽度db
<img id="profileImg" alt="" height="96" width="87" src="<?=base_url().$row1->imgURI?>" />
例如,通过使用GD库函数和getimagesize():http://php.net/manual/en/function.getimagesize.php
如果没有实际的width
和height
存储在数据库中,你可以使用getimagesize():
<?php
$image = base_url().$row1->imgURI;
$size = getimagesize($image);
?>
<img id="profileImg" alt="" height="<?=$size[1];?>" width="<?=$size[0];?>" src="<?=$image;?>" />
感谢的人。你的代码给我错误btw – 2012-08-10 13:40:26
@Dainis Abols编辑。 .. – 2012-08-10 13:43:47
这是使用getimagesize功能最简单的检索:
list($width, $height, $type, $attr) = getimagesize (base_url() . $row1->imgURI);
<img id="profileImg" alt="" <?=$attr?> src="<?=base_url().$row1->imgURI?>" />
随着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访问文件。但我会留下来的。
甜。谢啦。也有可能减少一个百分比的大小? – 2012-08-10 13:38:56
'height =“<?= $ height * 0.9?>”width =“<?= $ width * 0.9?>”'for 90% – Peon 2012-08-10 13:41:03
http://stackoverflow.com/questions/8819524/a-very-good -php图像 - 调整 - 脚本的建议 – 2012-08-10 13:46:08
谢谢你。我会阅读它。 – 2012-08-10 13:39:40