I have an image and want to draw six equal rectangles across it side by side. Starting at the top left 0,0 and full height.
This sort of works but has a major problem; if I write $i++ anywhere it uses that instead of $i through the rest of the code!
This means it misses out rectangles - only creats 0 2 4 6
$result = '';
$value='';
$size = getimagesize('600438_l.jpg');
$column = $size[0]/6;
$i = 0;
while( $i < 7) {
ECHO $i.'<br>';
$j = $i++;
$result = ($column*$i).',0 '.($column*$j).','.$size[1].'<br>';
$value = $value.$result;
echo $value.'<br>';
$i++;
}
0
590.5,0 0,3543
2
590.5,0 0,3543
1771.5,0 1181,3543
4
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
6
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
This works better but includes data twice:
$result = '';
$value='';
$size = getimagesize('600438_l.jpg');
$column = $size[0]/6;
$i = 0;
$j = 0;
while( $i < 7) {
echo $i.'<br>';
$j = $i+$i;
$result = ($column*$i).',0 '.($column*$j).','.$size[1].'<br>';
$value = $value.$result;
echo $value.'<br>';
$i++;
}
0
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
1
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
590.5,0 1181,3543
2
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
590.5,0 1181,3543
1181,0 2362,3543
3
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
590.5,0 1181,3543
1181,0 2362,3543
1771.5,0 3543,3543
4
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
590.5,0 1181,3543
1181,0 2362,3543
1771.5,0 3543,3543
2362,0 4724,3543
5
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
590.5,0 1181,3543
1181,0 2362,3543
1771.5,0 3543,3543
2362,0 4724,3543
2952.5,0 5905,3543
6
590.5,0 0,3543
1771.5,0 1181,3543
2952.5,0 2362,3543
4133.5,0 3543,3543
0,0 0,3543
590.5,0 1181,3543
1181,0 2362,3543
1771.5,0 3543,3543
2362,0 4724,3543
2952.5,0 5905,3543
3543,0 7086,3543
Please can somebody point out where I am going wrong.