This code was moved to lib/images.php