Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just answered a <a href="https://stackoverflow.com/questions/1746530/get-image-color/1746564#1746564">kinda related SO question yesterday</a>. Some of the concepts there, along with the resulting <a href="http://gist.github.com/237185" rel="nofollow noreferrer">test code (on git hub)</a> could be a good start.</p> <p>As <a href="https://stackoverflow.com/users/158557/evolve">evolve</a> mentions, scanning every pixel in an image (or even just the border) can be resource intensive. However, in this case (since you want to identify far more than just average color) it may be the way to go. Resizing the logo to a sane size would help reduce the server load, and shouldn't really effect the output.</p> <p><strong>Update</strong>: <em>For these examples assume an image object has been created and <code>$width</code> and <code>$height</code> have been determined using <code>imagesx()</code>, <code>getimagesize()</code>, etc.</em></p> <p><strong>Background Color</strong></p> <blockquote> <p>The first thing we needed to do was figure out the logo’s background color. And that’s all the first version did, by using the corner pixels.</p> </blockquote> <p>Here use <code>imagecolorat()</code> to find the corner colors. Alternatively, use the average border color method from the referenced answer at the top.</p> <pre><code>$color = imagecolorat($image, 0, 0); //do this for each corner $rgb = imagecolorsforindex($image, $color); //convert each color to a RGB array //average colors </code></pre> <p><strong>Saturation</strong></p> <blockquote> <p>It turns out color theory has a way of measuring interestingness: saturation. So we pulled out an interesting color from the logo. Using the same color for the border and the text made things a bit more monotone than we wanted, so finally we decided to try and grab two interesting colors if they’re present.</p> </blockquote> <p>You can use the RGB to HSL functions at the <a href="http://www.php.net/manual/en/function.imagecolorsforindex.php" rel="nofollow noreferrer"><code>imagecolorsforindex()</code> manual page</a> along with the <a href="http://gist.github.com/237185" rel="nofollow noreferrer">pixel scanning code</a> mentioned at the top to find color values with high saturation.</p> <p><strong>Luminance</strong></p> <blockquote> <p>We turned again to color theory and realized we could use the border color’s luminance to decide whether black or white text was more suitable.</p> </blockquote> <p>This <a href="https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color">SO thread</a> lists different RGB to luminance calculations. I'm not certain what method is best (or technically correct) to convert 0-255 RGB images. But for what this is accomplishing (should the text be dark or light), I don't think it'll matter <em>that</em> much.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload