You can do this with an simple sql query in your main.php site.
(or create an new php file and include in your main.php)
Just look at the code how it's done in the index.php of 4images.
P.S.: I didn't searched for it, but i think somebody else will surely asked this question before with an answer he got.