Ci metterei tutto dentro un array
Codice PHP:
$arr[]="{image: '".$filename."'}"
per poi usare
Codice PHP:
echo implode(','$arr);