Created
February 18, 2016 10:33
-
-
Save JohannesFischer/2597e8e9e676d5767b8d to your computer and use it in GitHub Desktop.
Average color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$filename = 'IMAGE_PATH'; | |
$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); | |
?> | |
<html> | |
<head> | |
<title>Test Image Average Color</title> | |
<style> | |
body { | |
background-color: rgb(<?php echo $color['red'] ?>, <?php echo $color['green'] ?>, <?php echo $color['blue'] ?>); | |
} | |
img { | |
display: block; | |
margin: 20% auto; | |
width: 200px; | |
} | |
</style> | |
</head> | |
<body> | |
<img src='<?php echo $filename ?>'> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment