PhpImagick: getting image RGB color value _ PHP Tutorial

Source: Internet
Author: User
PhpImagick obtains the RGB color of the image. PhpImagick obtains the RGB color value of an image. the main color value of the image is retrieved based on the user-uploaded image, and then the related image is searched based on the color, using the quantizeImage method of Imagick, you can use php Imagick to obtain the RGB color value of an image.

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 value of the image.

Many image sites retrieve the main color values of the image based on the image uploaded by the user, and then search for the relevant image 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.jbxue.com

$ Colorarr [] = $ pixel-> getColor ();

}

}

Return $ colorarr;

}

$ Colorarr = GetImagesColor ($ average );

Foreach ($ colorarr as $ val ){

Echo"

";

Http://www.bkjia.com/PHPjc/852826.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/852826.htmlTechArticlephp Imagick obtains the RGB color value of the image according to the user to upload the image to retrieve the main color value of the image, and then according to the color search related image, the use of the quantizeImage Imagick method can be very...

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.