2012-08-10 84 views

回答

0

如果沒有實際的widthheight存儲在數據庫中,你可以使用getimagesize()

<?php 
    $image = base_url().$row1->imgURI; 
    $size = getimagesize($image); 
?> 
<img id="profileImg" alt="" height="<?=$size[1];?>" width="<?=$size[0];?>" src="<?=$image;?>" /> 
+0

感謝的人。你的代碼給我錯誤btw – 2012-08-10 13:40:26

+0

@Dainis Abols編輯。 .. – 2012-08-10 13:43:47

0

這是使用getimagesize功能最簡單的檢索:

list($width, $height, $type, $attr) = getimagesize (base_url() . $row1->imgURI); 
<img id="profileImg" alt="" <?=$attr?> src="<?=base_url().$row1->imgURI?>" /> 
2

隨着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訪問文件。但我會留下來的。

+0

甜。謝啦。也有可能減少一個百分比的大小? – 2012-08-10 13:38:56

+0

'height =「<?= $ height * 0.9?>」width =「<?= $ width * 0.9?>」'for 90% – Peon 2012-08-10 13:41:03

+0

http://stackoverflow.com/questions/8819524/a-very-good -php圖像 - 調整 - 腳本的建議 – 2012-08-10 13:46:08