php.ini -Theme-specific settings

I’m wanted to comment rather than answer as I don’t have a solution for you, but I think this is too long 🙂

Hosts vary so widely on how and where they set memory allocation, and whether they allow hosted scripts to set it, that I don’t think there is a bullet-proof solution for you.

I would try and ‘handle’ the situation in a theme settings page; test available memory and if it’s too low, try and enable ini_set on each gallery page that posts large data. If that’s not possible, ask the user to add the WP_MEMORY_LIMIT constant to their wp-config file, or add the php.ini modification, or call their hosts to up their limit. Some hosts allow a php.ini in the web root, but many don’t.