0; $x--) { $colorBreakdown = imagecolorsforindex($image, (imagecolorat($image, $x, $y))); if ($colorBreakdown['alpha'] < 127) { break; } else { $imagemap[$y]++; } } } } // This second loop generates $sandbag, which is a less perfect // array of the empty space we have detected, and is // based on our specified sandbag height. for($i=0;$i < count($imagemap); $i = $i+$sandbagHeight) { for($x=0;$x < $sandbagHeight; $x++) { $b = $x + $i; if(isset($imagemap[$b])) { $section[$b] = $imagemap[$b]; } } $sandbag[] = min($section); $finalSectionSize = count($section); unset($section); } // Here we specify the template for our sandbags $sandbagTemplate = '
'; // This final loop generates each of our sandbags if($alt != '') { echo '
' . $alt .''; } else { echo '
'; } foreach ($sandbag as $position => $blankPixels) { $sandbagWidth = $width-$blankPixels; $yPos = $position*$sandbagHeight; if($align == 'right') { $xPos = $blankPixels; $sandbagClass = 'sandbag-right'; } else { $sandbagClass = 'sandbag-left'; $xPos = 0; } if ($position == 0) { $sandbagClass .= ' first-sandbag'; } elseif ($position == count($sandbag)-1) { $sandbagClass .= ' last-sandbag'; $sandbagHeight = $finalSectionSize; } printf($sandbagTemplate,$sandbagClass,$imageName,$xPos,$yPos, $sandbagWidth, $sandbagHeight); } echo '
'; } else { echo $alt; } } alignedImage('an_image.png', 'right', 'A right aligned blob',30); ?>