PhpImagick obtains the RGB color of an image.

Source: Internet
Author: User
Retrieve the main color value of the image based on the uploaded image, and then search for the image based on the color, the quantizeImage method of Imagick can easily obtain the average RGB values of images. many Image sites retrieve the main color values of images based on the images uploaded by users, then, search for related images by color.

Previously, the image was scaled (or mosaic) according to the online method, then each pixel was traversed, and the value of RGB was the most frequently. this was too inefficient and the obtained RGB value was not accurate enough. Then we can find that the average RGB value in the image can be easily obtained using the quantizeImage method of Imagick.

$ Average = new Imagick ("xiaocai.jpg"); $ average-> quantizeImage (10, Imagick: COLORSPACE_RGB, 0, false, false); $ average-> uniqueImageColors (); function GetImagesColor (Imagick $ im) {$ colorarr = array (); $ it = $ im-> getPixelIterator (); $ it-> resetIterator (); while ($ row = $ it-> getNextIteratorRow () {foreach ($ row as $ pixel) {// www.jb51.net $ colorarr [] = $ pixel-> getColor () ;}return $ colorarr ;}$ colorarr = GetImagesColor ($ average ); foreach ($ colorarr as $ val) {echo"

";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.