You would move the delete code to the top of the page above the repeat region.
Then use a hidden form element to save the image name and refer to that in the delete code, like:
<?php
$WA_DeleteFileResult1 = false;
if((((isset($_POST["delete_farm_image"]))?$_POST["delete_farm_image"]:"") != "")){
$WA_DeleteFileResult1 = WA_FileAssist_DeleteFile("images_farm/", "".$_POST['imageName'] ."");
}
?>
<?php do { ?>
<div class="col-sm-2">
<form action="" method="post" name="delete_farm_image">
<div style="background-color:#F00;">
<input type="hidden" name="imageName" value="<?php echo $row_pictures['farm_image']; ?>" />
<img src="images_farm/<?php echo $row_pictures['farm_image']; ?>" style="width:128.66px;height:128.66px;"> </div>
<div>
<input class="btn btn-danger btn-sm" style="width:100%;border-radius:0px;" name="delete_farm_image" type="submit" value="DELETE">
</div>
</form>
</div>
<?php } while ($row_pictures = mysql_fetch_assoc($pictures)); ?>