Bug 1065877: prevent OOMs when editing, picking and sharing large images

(cherry picked from commit 63bc9fa28bf457be57613c55c0c52531e5cb612d)