[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Диаграмма-пирамида php
Страницы: 1, 2
Pi Patel
Всем привет. Пытаюсь сделать диаграмму-пирамиду такого рода из значений переменных:
user posted image

<?php

$spec1 = 43;
$spec2 = 73;
$spec3 = 22;
$spec4 = 5;
$spec5 = 7;
$spec6 = 14;
$spec7 = 3;

header('Content-type: image/png');

$length = 940;
$height = 118;

$im1 = imagecreatetruecolor("$length", "$height");
$im2 = imagecreatetruecolor("$length", "$height");
$im3 = imagecreatetruecolor("$length", "$height");
$im4 = imagecreatetruecolor("$length", "$height");
$im5 = imagecreatetruecolor("$length", "$height");
$im6 = imagecreatetruecolor("$length", "$height");
$im7 = imagecreatetruecolor("$length", "$height");

$center = $length/2;

$font = '/var/www/html/fonts/arial.ttf';

$color1 = imagecolorallocate ($im1,247,222,111);
$color2 = imagecolorallocate ($im2,255,25,255);
$color3 = imagecolorallocate ($im3,0,165,80);
$color4 = imagecolorallocate ($im4,254,171,133);
$color5 = imagecolorallocate ($im5,253,129,126);
$color6 = imagecolorallocate ($im6,52,198,187);
$color7 = imagecolorallocate ($im7,1,92,85);
$white = imagecolorallocate ($im1,255,255,255);

imagefill($im1, 1, 1, $color1);
imagefill($im2, 1, 1, $color2);
imagefill($im3, 1, 1, $color3);
imagefill($im4, 1, 1, $color4);
imagefill($im5, 1, 1, $color5);
imagefill($im6, 1, 1, $color6);
imagefill($im7, 1, 1, $color7);

// размеры текст по координатам
$box = imagettfbbox(80, 0, $font, "$spec1");
$left = $center-round(($box[2]-$box[0])/2);
imagettftext($im1, 80, 0, $left, 96, $white, $font, "$spec1");

$box = imagettfbbox(80, 0, $font, "$spec2");
$left = $center-round(($box[2]-$box[0])/2);
imagettftext($im2, 80, 0, $left, 96, $white, $font, "$spec2");
// И т.д....

imagepng($im1);

?>

По этим наброскам сделал вот это:
user posted image

Опыта у меня мало к сожалению. Помогите пожалуйста оживить этот код. Хотя бы намекните через какие решения можно осуществить данную пирамиду. Нужно чтобы сравнились все переменные $specX и иерархически выстраивались, ещё у каждого от большего к меньшему переменная $length уменьшалась на -100 пикселей (сокращалась полоса).
Есть идея осуществить через массивы, переменные $specX отсортировать через array_multisort(), но как потом все массивы переменных скрепить для такого результата не знаю.
Помогите пожалуйста советом.
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.