Skip to content

Instantly share code, notes, and snippets.

@JohannesFischer
Created February 18, 2016 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesFischer/2597e8e9e676d5767b8d to your computer and use it in GitHub Desktop.
Save JohannesFischer/2597e8e9e676d5767b8d to your computer and use it in GitHub Desktop.
Average color
<?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