Have you thought of using an ingest processor that checks the value height and width at index time and stores the result in another field? Then you would have fast queries as you do not need to run an expensive script query at all.
Of course this only makes sense if you have a limited number of such checks.
--Alex