diff --git a/generate.php b/generate.php index 71466ed..9d74ea7 100755 --- a/generate.php +++ b/generate.php @@ -1,81 +1,6 @@ get_light(); - - $w = 75 + (180 * $light); - $g = 75 + (150 * $light); - - $white = imagecolorallocate($img, $w, $w, $w); - $gray = imagecolorallocate($img, $g, $g, $g); - $dark = imagecolorallocate($img, 75, 75, 75); - - if($i && $i % 2 == 0) - { - $x = 0; - $y += 46; - } - imagettftext($img, $m_size, 0, 10 + $x, 20 + $y, $gray, "fonts/{$city->font}", $city->get_message()); - imagettftext($img, $c_size, 0, 10 + $x, 40 + $y, $dark, "fonts/$light_font", '#'); - imagettftext($img, $c_size, 0, 22 + $x, 40 + $y, $white, "fonts/$bold_font", $city->name); - - $i++; - $x += 140; -} - -// Save - -if(!empty($_GET['path'])) -{ - if(!imagejpeg($img, $_GET['path'], 100)) - { - exit; - } -} - -// Header - -header('Content-Type: image/jpeg'); - -// Print - -imagejpeg($img, null, 100); - -// Destroy - -imagedestroy($img); \ No newline at end of file +$map = new Map; +$map->output(); \ No newline at end of file diff --git a/map.php b/map.php new file mode 100755 index 0000000..22db404 --- /dev/null +++ b/map.php @@ -0,0 +1,110 @@ +cities = City::get('cities.txt'); + + $this->create_image(); + + $this->create_background(); + + $this->create_text(); + } + + public function output($quality = 100) + { + if(!$this->image) + { + $this->generate(); + } + header('Content-Type: image/jpeg'); + + imagejpeg($this->image, null, $quality); + + imagedestroy($this->image); + } + + public function save($path, $quality = 100) + { + if(!$this->image) + { + $this->generate(); + } + return imagejpeg($this->image, $path, $quality); + } + + private function create_image() + { + $this->image = imagecreatetruecolor + ( + 300, ceil(count($this->cities) / 2) * 46 + 6 + ); + } + + private function create_background() + { + $bg = imagecolorallocate($this->image, 10, 10, 10); + + imagefill($this->image, 0, 0, $bg); + } + + private function create_text() + { + $x = 10; + $y = 20; + + foreach($this->cities as $k => $city) + { + $light = $city->get_light(); + + $g = 75 + (150 * $light); + $w = 75 + (180 * $light); + + $dark = imagecolorallocate($this->image, 75, 75, 75); + $medium = imagecolorallocate($this->image, $g, $g, $g); + $light = imagecolorallocate($this->image, $w, $w, $w); + + if($k && $k % 2 == 0) + { + $x = 10; + $y += 46; + } + $this->write + ( + $city->get_message(), $city->font, $this->small, $medium, $x, $y + ); + $this->write + ( + '#', $this->light, $this->big, $dark, $x, $y + 20 + ); + $this->write + ( + $city->name, $this->bold, $this->big, $light, $x + 12, $y + 20 + ); + $x += 140; + } + } + + private function write($text, $font, $size, $color, $x, $y) + { + imagettftext + ( + $this->image, $size, 0, $x, $y, $color, "fonts/$font", $text + ); + } +} \ No newline at end of file diff --git a/upload.php b/upload.php index 3866995..4750694 100755 --- a/upload.php +++ b/upload.php @@ -1,9 +1,11 @@ save($path) || !$path = realpath($path)) { exit; }