(define (image-scale/proportional image #!key max-dimension (max-width max-dimension) (max-height max-dimension)) (let* ((w (image-width image)) (h (image-height image)) (w-proportion (and max-width (/ w max-width))) (h-proportion (and max-height (/ h max-height))) (scale-factor (cond ((and (not h-proportion) (not w-proportion)) (error "Must specify either max-dimension or both max-width and max-height.")) ((not h-proportion) w-proportion) ((not w-proportion) h-proportion) (else (if (> h-proportion w-proportion) h-proportion w-proportion))))) (image-scale image (flonum->fixnum (/ w scale-factor)) (flonum->fixnum (/ h scale-factor)))))