PHP image color analysis with transparency -


I am currently working on an application for which many images need to be analyzed and find out They are close to what color.

So I got a code snippet that actually does:

  function analysis image coils ($ im, $ xcount = 3, $ yCount = 3) { // get dimension image for $ imWidth = imagesx ($ im); $ ImHeight = Images ($ IM); // Find the dimensions of blocks that we are going to make $ blocks = quart ($ imWidth / $ xCount); $ Blockhit = round ($ imHeight / $ yCount); // Now get image color ... ($ x = 0; $ x & lt; $ xcount; $ x ++) {// X-axis for cycle ($ y = 0; $ y & lt ; $ YCount; $ y ++) {// cycling via y-axis // This is the starting x and y number that will make the block $ blockStartX = ($ x * $ blockWidth); $ BlockStartY = ($ y * $ blockHeight); // Create the image we'll use for block $ block = imagecreatetruecolor (1, 1); // We will put the section of the image that we want to get a color in the block imagecuperatespled ($ block, $ im, 0, 0, $ blockStartX, $ blockStartY, 1, 1, $ blockWidth, $ blockHeight); // The palette is where I will find my color for this block imagetruecolortheette ($ block, true, 1); // I am creating a variable called iDropper to get color info $ eyeDropper = imagecolorat ($ block, 0, 0); $ Palette = imagecolorsforindex ($ block, $ eyeDropper); $ Color $ [$ x] [$ y] ['r'] = $ palette ['red']; $ Color $ [$ x] [$ y] ['g'] = $ palette ['green']; $ Color [$ x] [$ y] ['b'] = $ palette ['blue']; // RGB value also get $ hex = sprintf ("% 02X% 02X% 02X", $ color $ [x] [$ y] ['r'], $ color array [$ x] [$ y] ['g '], $ Color [[x $] [$ y] [' 'b']); $ Color $ [$ x] [$ y] ['RGBHX'] = $ hex; // Block imagedestroy destroyed ($ block); }} // Source image imagedestroy destroyed ($ im); Return $ $ color; } The problem is that whenever I provide an image with transparency, GDLIB has blackened the transparency, thus actually producing a false (more profound) output actually There is a case in  

For example, this icon where the white area around the arrow is actually transparent:

Can someone tell me how it works Do you?

You need imageColorTransparent ().

Transparency is a property of the image, not to color, to see any transparency on your image, use something like $ transparent = imagecolortransparent ($ im) , then Just ignore that color in your $ colorArray or there is some other way to identify the transparent color in it. Returning from your work depends on how you are using the returned data.

- M


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -