LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / PHP Codes » Image Color Extract Using Simple PHP Without Composer

Image Color Extract Using Simple PHP Without Composer

Image-Color-Extract-Using-Simple-PHP-Without-Composer
Have you ever wondered what kind of colours you should get to match your logo for your website? Here’s a very simple script that generates a colour palette for an image using the PHP GD library. This will help you find out which colours you can use to improve the quality of your site.

The Image Color Extract PHP class pulls the most common colours out of an image file. The colour values are in hexadecimal. You can try it out below. Upload a file or use the sample image provided. This class was originally written by Csongor Zalatnai. The only requirements are PHP 4.0.2 or higher and GD2 image library

This is a simple frontend utility to help the file-upload process on your website. It is written in pure JavaScript, has no dependencies. You can check out the live demo. For the most part, browsers do a good job of handling image uploads. That being said – we find that the ability to show our users a preview of their upload can go a long way in increasing the confidence in their upload.

Table of Contents

Features:

  1. Light Weight.
  2. Pure PHP.
  3. Cross Browser.
  4. Works with JPEG and PNG
  5. And Best! No Hustle With Composer, Just require_once
  6. Allow you to select the quantization delta. The smaller the delta the more accurate the colour. This also increases the number of similar colours though.
  7. Added a filter to reduce brightness variants of the same colour.
  8. Added a filter to reduce gradient variants ( useful for logos ).
  9. Changed colour counts to percentages.

How To Image Color Extract Using Simple PHP Without Composer?

There are a few easy and understandable steps to achieve your desired functionality using pure Vanilla JavaScript that we are gonna share below. Follow each step perfectly.

PHP:

<?php
/* Get Color Combination Code Of The Image */
$ImgURL= "img/Logo.png";
require_once 'class/colors.inc.php';
$colors = "";
$ex=new GetMostCommonColors();
$num_results=2; // How Many Color Code You Want?
$reduce_brightness=1;
$reduce_gradients=1;
$delta=50;
$colors=$ex->Get_Color( $ImgURL, $num_results, $reduce_brightness, $reduce_gradients, $delta);
//print_r($colors); // Get Full Array

$key = $value = NULL;
foreach ($colors as $key => $value) { // Key = Color Hex Code and Calue = Frequency
if($key != 000000){break;} // Remove Black Color As Transfparent and PNG Image Max Color Ratio And Get First Color Only
}
/* Get Color Combination Code Of The Image*/

?>

Output:

Array ( [3060a8] => 0.55827380952381 [f0a848] => 0.19791666666667 [000000] => 0.069642857142857 [483018] => 0.02047619047619 [786018] => 0.01827380952381 [183060] => 0.01797619047619 [4878a8] => 0.016011904761905 [181800] => 0.015119047619048 [a87830] => 0.014345238095238 [a8c0d8] => 0.011904761904762 [6090c0] => 0.01172619047619 [d89030] => 0.011011904761905 [90a8d8] => 0.0071428571428571 [ffffff] => 0.0070238095238095 [604830] => 0.006547619047619 [f0f0f0] => 0.0063095238095238 [d8d8f0] => 0.005297619047619 [c0d8d8] => 0.0044047619047619 [f0f0ff] => 0.00041666666666667 [181830] => 0.00011904761904762 )

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Recommended For You:
Pure Simple CSS Rating Review Widget For Web And Blog

Troubleshooting the Errors

Do it with concentration and patience. Check your alls steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us or If you have any doubts and problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave your precious feedback in our comment form below. Happy development, See you in the next article.

You Like It, Please Share This Recipe With Your Friends Using...

2 Responses to “Image Color Extract Using Simple PHP Without Composer”

  1. Nice blog, Thanks for sharing.

    • EXEIdeas says:

      Welcome here and thanks for reading our article and sharing your view. This will be very helpful to us to let us motivate to provide you with more awesome and valuable content from a different mind. Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *