0

Is there any way to tell if an image is light or dark in ruby?

The use case is as a user uploads an image, the application (e.g. the controller in a rails app) could automatically detect whether an image is light or dark and record that result so the view can place the image on an appropriate background for maximal contrast.

I found similar answers here for python and here for javascript, but couldn't spot the equivalent in ruby

stevec
  • 41,291
  • 27
  • 223
  • 311
  • How do you define "light" and "dark" images? – Stefan Jan 01 '21 at 14:03
  • @Stefan in my use case I have some dark backgrounds and light backgrounds and want to try to give lighter images the darker backgrounds and vice versa. I had no preconceived way of defining which are light and which are dark though. – stevec Jan 01 '21 at 14:08

1 Answers1

3

Well if you want to work with images in Ruby the usual go to gem is RMagick which works on top of ImageMagick. This article might help you with what you need in terms of how to achieve it with RMagick or you can create your own version of a solution.

Daniel Sindrestean
  • 1,153
  • 6
  • 13