处理存储在MongoDB中的图像

I'm looking for a way to manipulate images stored in mongoDb. My project use Symfony 2 and I use the bundle Imagine/Gmagick to do a rotation for example.

My main issue is how to get file, manipulate, then save it.

Thanks for answer.

[EDIT] I tried something like this (but not working):

$img = new Imagine\GMagick\Image(new Gmagick($rewritten_url));
$img->rotate(90);
$img->save($path_on_mongo);

To be more precise, these variable are something like:

$rewritten_url = http://127.0.0.1/document/(id)/view

$path_on_mongo = /tmp/ok8s4ko

I wanted to try to write in image file which is on Mongo server from my built-in php server. But I don't have enough knowledge on Mongo. Am I following the right track ?