Hello Readers! If you are developing the dynamic website in which the image color will be the background color then you can see it doing in PHP :-
<?php
$filename = $_GET['filename'];
$image = imagecreatefromjpeg($filename);
$width = imagesx($image);
$height = imagesy($image);
$pixel = imagecreatetruecolor(1, 1);
imagecopyresampled($pixel, $image, 0, 0, 0, 0, 1, 1, $width, $height);
$rgb = imagecolorat($pixel, 0, 0);
$color = imagecolorsforindex($pixel, $rgb); //you are getting the most common colors in the image
?>
And the html part will go like this:-
<html>
<head>
<title>Getting BG color</title>
</head>
<body style='background-color: rgb(<?php echo $color['red'] ?>, <?php echo $color['green'] ?>, <?php echo $color['blue'] ?>)'>
<form action='' method='get'>
<input type='text' name='filename'><input type='submit'>
</form>
<img src='<?php echo $filename ?>'>
</body>
</html>
By running the code above the color which is most common will be shown in the background.
0 Comment(s)