and adapted function calcSandbags() { $serverRoot = $_SERVER['DOCUMENT_ROOT']; $lineHeight = $_POST['lineHeight']; $temp = explode(" ", $_POST['imgArray']); for ($i = $j = 0; $i < floor(count($temp) / 4); $i++, $j++) { $images[$i][0] = $temp[$j]; // filename $images[$i][1] = $temp[++$j]; // width $images[$i][2] = $temp[++$j]; // height $images[$i][3] = $temp[++$j]; // float edge } for ($i = 0; $i < count($images); $i++) { $srcImage = imagecreatefromgif($images[$i][0]); $width = imagesx($srcImage); $height = imagesy($srcImage); $newWidth = $images[$i][1]; $newHeight = $images[$i][2]; $destImage = imagecreate($newWidth, $newHeight); imagecopyresized($destImage, $srcImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imagegif($destImage, '/tmp/temp.gif'); imagedestroy($srcImage); for ($j = $y = 0; $j < $newHeight; $j++, $y += $lineHeight) { $imagemap[$j] = 0; for ($x = 0; $x < $newWidth; $x++) { //echo $color['alpha']."
"; $color = imagecolorsforindex($destImage, imagecolorat($destImage, $x, $y)); if ($color['alpha'] < 127) break; else $imagemap[$j]++; } $sandbagTemplate = '
'; foreach ($imagemap as $position => $blankPixels ) { $sandbagWidth = $width - $blankPixels; // printf($sandbagTemplate, $sandbagWidth, $lineHeight); } } imagedestroy($destImage); } } ?>