Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$img = imagecreatefromjpeg();
- $imgw = imagesx($img);
- $imgh = imagesy($img);
- $ratio = $imgw/$imgh;
- $newh = floor(sqrt(800 / $ratio));
- $neww = floor($ratio * $newh);
- $newimg = imagecreatetruecolor($neww, $newh);
- imagecopyresampled($newimg, $img, 0, 0, 0, 0, $neww, $newh, $imgw, $imgh);
- imagedestroy($img);
- $prev_color = false;
- $openned_tag = false;
- $max = 0;
- $colors = array();
- for($j = 0; $j < $newh; $j++) {
- for ($i = 0; $i < $neww; $i++) {
- $color = imagecolorat($newimg, $i, $j);
- $colors[$color] += 1;
- if($max < $colors[$color]) {
- $max = $colors[$color];
- $max_color = $color;
- }
- }
- }
- $out = '<font size="1"><font color="#'.strtoupper(dechex($max_color)).'"><u>';
- for($j = 0; $j < $newh; $j++) {
- for ($i = 0; $i < $neww; $i++) {
- $color = imagecolorat($newimg, $i, $j);
- if($prev_color !== $color) {
- $prev_color = $color;
- if($openned_tag) {
- $out .= '</font>';
- $openned_tag = false;
- }
- if ($color != $max_color) {
- $color = strtoupper(dechex($color));
- $out .= '<font color="#'.$color.'">';
- $openned_tag = true;
- }
- }
- $out .= '███';
- }
- $out .= "\n";
- }
- if($openned_tag) {
- $out .= '</font>';
- $openned_tag = false;
- }
- $out .= '</u></font></font>';
- echo $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement