{"id":41910,"date":"2018-11-19T03:01:22","date_gmt":"2018-11-18T17:01:22","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=41910"},"modified":"2018-11-19T05:54:17","modified_gmt":"2018-11-18T19:54:17","slug":"php-gd-image-colour-count-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-gd-image-colour-count-primer-tutorial\/","title":{"rendered":"PHP GD Image Colour Count Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/image_colours_of.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP GD Image Colour Count Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/image_colours_of.jpg\" title=\"PHP GD Image Colour Count Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">PHP GD Image Colour Count Primer Tutorial<\/p><\/div>\n<p>We&#8217;ve long been interested in the idea of cataloguing the colour makeup of an image, and knew, even with *.bmp images (which are one to one pixel in their makeup) you still have to formulate a method to quickly scan the image pixel by pixel to get anywhere with an overall &#8220;Image Colour Report&#8221; concept.  Even though there is, incredibly enough a &#8230;<\/p>\n<ul>\n<li>PHP GD (image library) <a target=_blank href='http:\/\/php.net\/manual\/en\/function.imagecolorstotal.php'>imagecolorstotal<\/a> method to do just that, it doesn&#8217;t work for every type of image, so we Googled away and got to &#8230;<\/li>\n<li><a target=_blank title='Great coding here, thanks' href='\/\/stackoverflow.com\/questions\/25400805\/how-to-know-howmany-colors-are-exist-in-the-image'>this very useful link<\/a> got us onto some great and fast code to do the job, once the user enters an image URL, to get the ball rolling<\/li>\n<\/ul>\n<p>Also coming into play with this work was the discovery of linear gradient CSS means by which a document.body (or other element, for that matter) background image can be given some transparency independent of the foreground (presumably more opaque) transparency, as we outlined with <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/rainbow-games-background-image-tutorial\/' title='Rainbow Games Background Image Tutorial'>Rainbow Games Background Image Tutorial<\/a>.  Via this technique we can keep all of &#8230;<\/p>\n<ol>\n<li>user defined imagery<\/li>\n<li>webpage header elements<\/li>\n<li>number of colours reporting<\/li>\n<li>prompt for the user for a follow up entry<\/li>\n<\/ol>\n<p> &#8230; all above the fold rather than having to scroll down past an &lt;img&gt;&lt;\/img&gt; element to get to that last idea above.  We also squeeze in an opacity in between the other opacities to a &lt;div&gt;&lt;\/div&gt; to give a nuanced different lighting to the div background encasing the heading and report and prompt parts above.  The woooooorrrrllllddd&#8217;s your oyster!<\/p>\n<p>Just be ready with an image URL of interest and you can try <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/image_colours_of.php_GETME\" title=\"image_colours_of.php\">image_colours_of.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/image_colours_of.php\" title=\"Click picture\">live run<\/a> link to see what we mean here.  We hope it is of interest for you.<\/p>\n<p><p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d41910' onclick='var dv=document.getElementById(\"d41910\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/gd\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d41910' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve long been interested in the idea of cataloguing the colour makeup of an image, and knew, even with *.bmp images (which are one to one pixel in their makeup) you still have to formulate a method to quickly scan &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-gd-image-colour-count-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[224,2743,281,1550,590,2744,2020,932,997,1319],"class_list":["post-41910","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-colour","tag-count","tag-css","tag-gd","tag-image","tag-imagecolorstotal","tag-linear-gradient","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/41910"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=41910"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/41910\/revisions"}],"predecessor-version":[{"id":41913,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/41910\/revisions\/41913"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=41910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=41910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=41910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}