0

Is there any codes or scripts , which will scan a jpeg or gif image and find if that image has colors in it or it is black ?

in my site many users upload lots of files , we can extract icons from some jar and nth files , but some will appear black . So I would like to replace the black icons with file format icon when providing file icon in download page.

Shijil
  • 51
  • 1
  • 7

1 Answers1

0

imagecolorat

Returns the index of the color of the pixel at the specified location in the image specified by image.

If PHP is compiled against GD library 2.0 or higher and the image is a truecolor image, this function returns the RGB value of that pixel as integer. Use bitshifting and masking to access the distinct red, green and blue component values:

  • image

    An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().

  • x

    x-coordinate of the point.

  • y

    y-coordinate of the point.

Example:

<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

var_dump($r, $g, $b);
?>

Also, there are others scripts that do this for example this one.

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474