'; // Here we actually create the sandbags foreach ($sandbag as $position => $blankPixels) { $sandbagWidth = $width-$blankPixels; $yPos = $position*$sandbagHeight; // the Y position of the background image $xPos = $blankPixels; // the X position of the background image if ($position == 0) { $sandbagClass .= ' first-sandbag'; // this gives the sandbag an extra class if it's the first } elseif ($position == count($sandbag)-1) { $sandbagClass .= ' last-sandbag'; // alternatively gives it an extra class if it's the last } printf($sandbagTemplate,$imageName,$xPos,$yPos,$sandbagWidth,$sandbagHeight); } } // As we've now created a function we need to call that function alignedImage('an_image.png', 15); ?>