I'm having trouble with building a dynamic grid with PHP like this:
我在使用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!
提前致谢!
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;
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。