Hi all,
I've been working on getting this right for some time now, but I can't get it to work

I'm trying to get some rectangles filled with a hatching pattern and it just doesn't go the way I want.
The code I have now is the following:
function applyhatch1 ($im, $sxp, $exp, $syp, $eyp) {
// this is the \\\ hatch
$spacing = 25;
// line every 25px
$min_x = ($exp-$sxp)/$spacing;
$min_y = ($eyp-$syp)/$min_x;
// first loop up
for ($q=0; $q<=$min_x; $q++) {
imageline($im, ($sxp+($q*$spacing)), $syp, $exp, ($eyp-($q*$min_y)), IMG_COLOR_STYLED);
}
// first loopdown
for ($q=0; $q<=$min_x; $q++) {
imageline($im, ($sxp), $syp+($q*$min_y), $exp-($q*$spacing), ($eyp), IMG_COLOR_STYLED);
}
return;
}
function applyhatch2 ($im, $sxp, $exp, $syp, $eyp) {
// this is the /// hatch
$spacing = 45;
$min_x = ($exp-$sxp)/$spacing;
$min_y = ($eyp-$syp)/$min_x;
// first loop up
for ($q=0; $q<=$min_x; $q++) {
imageline($im, ($exp-($q*$spacing)), $syp, $sxp, ($eyp-($q*$min_y)), IMG_COLOR_STYLED);
}
// first loopdown
for ($q=0; $q<=$min_x; $q++) {
imageline($im, ($exp), $syp+($q*$min_y), $sxp+($q*$spacing), ($eyp), IMG_COLOR_STYLED);
}
return;
}
If I use applyhatch1 it does give me the hatch I want, but the hatching is not consistent (in spacing) on images of different size.
Somewhere I'm going wrong, but not being able to find out where and why.
Any help on this is appreciated.
(attached a picture so you can see (hopefully) what I'm on about

)