PHP選擇具有特定寬度的圖像並構建網格

[英]PHP selecting images with specific width and building a grid


I'm having trouble with building a dynamic grid with PHP like this: grid

我在使用PHP構建動態網格時遇到了麻煩:

I have an array containing images in various sizes, but always either 900 or 1800 in width.

我有一個包含各種尺寸圖像的數組,但寬度始終為900或1800。

Looks like this:

看起來像這樣:

$images = array('img_1_900.jpg', 'img_2_900.jpg', 'img_3_1800.jpg', 'and so on');

Is there any smart way to do this? I'm kind of new to the PHP-thing, so any hints could be nice. Here's what i got so far:

有沒有聰明的方法來做到這一點?我是PHP的新手,所以任何提示都可能很好。這是我到目前為止所得到的:

 $img_count = count($images);
 $i = 1;
 while($i <= $img_count){
    list($width) = getimagesize($images[$i]);
    if($width = 1800){

    }
    $i++;
 }

I know this does nothing, but i simply don't know where to go from here. Hope some kind soul could help me a little along. I can't just float them, because they need to stay on line even after a resize, so some kind of table/table-div has to do it. I guess.

我知道這沒什么,但我根本不知道從哪里開始。希望一些善良的靈魂可以幫助我一點點。我不能只是浮動它們,因為即使在調整大小之后它們也需要保持在線,因此某種表/ table-div必須這樣做。我猜。

Thanks in advance!

提前致謝!

2 个解决方案

#1


0  

if your image array is allway build in the same way... and not getting sorted...

如果你的圖像數組是以相同的方式構建的...而不是排序......

$i = 0;
$html = "<table cellpadding='0' cellspacing='10' border=1>"
foreach($image as $img){
    if($i == 0)
        $html .= "<tr>";
    if($i < 2){
        $html .= "<td><img src='{$img}' /></td>";
        $i++;
    }
    if($i == 2){
      $html .= "</tr><tr>";
      $html .= "<td colspan=2><img src='{$img}' /></td>";
      $i = 0;
    }
}
echo $html;

#2


0  

I can't write full functional code for you but I'll write pseudo code

我不能為你編寫完整的功能代碼,但我會編寫偽代碼

H_MARGIN = // horizontal margin between elements
V_MARGIN = // vertical margin

I_HEIGHT = // Image height

$ImgWidth = 1800 + H_MARGIN
$I1800 = // Number of 1800 images
$I900 = // Number of 900 images
$NRows = $I1800 + ceil($I900 /2);
$ImgHeight = $NRows * I_HEIGHT + V_MARGIN * ($NRows - 1);

 - Create $ImgWidth*$ImgHeight image
*- Blit 900 image then v_margin
 - If still a 900 blit next to the first
 - Else blit a 1800 then h_margin
 - While images left loop back to *

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/08/18/6926bdf31afbb2506e88a7353e400fd1.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com