Cache the calls to the php native getimagesize
Custom thumbnail salt to avoid computing the thumbnail ratio at each request