title: Database design to store image color pattern in MySQL for searching Image by color
body: <p>I am building a image galley using PHP and MySQL where I want to implement <strong>Image search by it's color</strong>. By following <a href="http://php.net/manual/en/imagick.getimagehistogram.php" rel="nofollow">Imagick::getImageHistogram</a> i got the most presented colors from the images. </p>
  
  <pre><code>&lt;?php
  $image = new Imagick("thing.png");
  $pixels=$image-&gt;getImageHistogram();
  foreach($pixels as $p){
   $colors = $p-&gt;getColor();
   foreach($colors as $c){
          print( "$c\t" );
   }
   print( "\t:\t" . $p-&gt;getColorCount() . "\n" );
  }
  ?&gt;
  
  This will print out something like:
  
  Red    Green    Blue       Alpha    :    No of times appeared
  252    250      252        1        :       125
  194    156      182        1        :       126
  109    18       79         1        :       11440
  2      117      162        1        :       12761
  255    255      255        1        :       40769
  </code></pre>
  
  <p>Although I am done with getting the colors, I am stuck with designing the database to store the color information along with image path in the database.</p>
  
  <p>My question is how to design a database (table structure) to store this kind of data where search can query can be applied in an effective manner.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Secondly how can I get the images with a matching color. Let's say user is searching for a color #ff0000, then how can I get all the nearest matched images from the database.</p>
  
  <p>Thank You</p>