imagefilledrectangle($img,1,1,$x-2,$y-2,$bg);
imagerectangle($img,0,0,$x-1,$y-2,$border);

tradotto in parole povere...sarebbe?

Grazie
Stefano