magnars / optimus-img-transform

An Optimus image transformation middleware.
6 stars 4 forks source link

Considering image size during transform-images #2

Open BorisKourt opened 9 years ago

BorisKourt commented 9 years ago

Back at working with stasis, I have the following functioning:

(defn optimize [assets options]
  (-> assets
      (transform-images {:regexp #"/assets/.*\.(jpg|png)"
                         :quality 0.7
                         :width 860
                         :prefix "860-"
                         :progressive true})
      (transform-images {:regexp #"/assets/.*\.(jpg|png)"
                         :quality 0.7
                         :width 400
                         :prefix "400-"
                         :progressive true})
      (transform-images {:regexp #"/assets/.*\.(jpg|png)"
                         :quality 0.7
                         :width 200
                         :prefix "200-"
                         :progressive true})))

This works well for images that are above 860px in width. But results in, for this case, undesired upscaled versions of smaller images. Do you know of a good way to prevent transformation if an image is smaller than the specified transform width?

Thank you.

magnars commented 9 years ago

There is no such option at this time, but it should be doable.

If you look at transform-image-1, it loads the image before doing any transformations on it. This image has .getWidth and .getHeight methods. The options are also passed in.

Maybe you would like to give it a go?