[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/img/ -> mapimage.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  $phpwcms = array();
  24  require_once('../config/phpwcms/conf.inc.php');
  25  require_once ('../include/inc_lib/default.inc.php');
  26  
  27  $img_file        = (isset($_GET['i'])) ? rawurldecode($_GET['i']) : '';
  28  $img_quality    = 87;
  29  $img_info        = @getimagesize(PHPWCMS_TEMPLATE.'inc_cntpart/map/map_img/'.$img_file);
  30  
  31  $img_val        = (isset($_GET['v'])) ? explode(',', $_GET['v']) : array(1,7,7,'FFFFFF','FF4000');
  32  $img_val[0]        = intval($img_val[0]); // border in px
  33  $img_val[1]        = empty($img_val[1]) ? 0 : intval($img_val[1]); // width in px
  34  $img_val[2]        = empty($img_val[2]) ? 0 : intval($img_val[2]); // height in px
  35  $img_val[3]        = empty($img_val[3]) ? hex2rgb('FFFFFF') : hex2rgb($img_val[3]); // background color array RGB
  36  $img_val[4]        = empty($img_val[4]) ? hex2rgb('FF4000') : hex2rgb($img_val[4]); // fill color array RGB
  37  
  38  $img_val[5]        = round($img_val[1]/2); // position -x
  39  $img_val[6]        = round($img_val[2]/2); // position -y
  40  
  41  $img_val[7]        = $img_val[1] - (2 * $img_val[0]); // width inner fill
  42  $img_val[8]        = $img_val[2] - (2 * $img_val[0]); // height inner fill
  43  
  44  
  45  
  46  $do = 0;
  47  
  48  if($img_info) {
  49  
  50      $img_file = PHPWCMS_TEMPLATE.'inc_cntpart/map/map_img/'.$img_file;
  51      
  52      
  53      
  54      switch($img_info[2]) {
  55      
  56          case 1:    // GIF
  57                  if(function_exists('imagegif')) {
  58                      $img_mimetype = 'image/gif';
  59                      $img_target = 'gif';
  60                  } else {
  61                      $img_mimetype = 'image/png';
  62                      $img_target = 'png';
  63                  }
  64                  $img_source = imagecreatefromgif($img_file);
  65                  $do = 1;
  66                  break;
  67          
  68          case 2:    // JPG
  69                  $img_mimetype = 'image/jpeg';
  70                  $img_target = 'jpg';
  71                  $img_source = imagecreatefromjpeg($img_file);
  72                  $do = 1;
  73                  break;
  74          
  75          case 3:    // PNG
  76                  $img_mimetype = 'image/png';
  77                  $img_target = 'png';
  78                  $img_source = imagecreatefrompng($img_file);
  79                  $do = 1;
  80                  break;
  81      
  82      }
  83      
  84      // fill image with points
  85      $img_point = imagecreate($img_val[1], $img_val[2]);
  86      $background_color = imagecolorallocate($img_point, $img_val[3]['r'], $img_val[3]['g'], $img_val[3]['b']);
  87      $fill_color = imagecolorallocate($img_point,  $img_val[4]['r'], $img_val[4]['g'], $img_val[4]['b']);
  88      imagefilledrectangle($img_point,$img_val[0], $img_val[0], $img_val[7], $img_val[8], $fill_color);
  89      
  90      if(isset($_GET['xy'])) {
  91          $points = explode(',', trim($_GET['xy']));
  92          if(count($points)) {
  93              foreach($points as $value) {
  94                  $point = explode('x', $value);
  95                  imagecopymerge($img_source, $img_point, $point[0]-$img_val[5], $point[1]-$img_val[6], 0, 0, $img_val[1], $img_val[2], 100);
  96              }
  97          }
  98      }    
  99      imagedestroy($img_point);
 100  }
 101  
 102  if($do) {
 103      
 104      header('Content-type: '.$img_mimetype);
 105      
 106      switch($img_target) {
 107  
 108          case 'jpg':        imagejpeg($img_source, '', $img_quality);
 109                          break;
 110      
 111          case 'png':        imagepng($img_source, '', 9);
 112                          break;
 113      
 114          case 'gif':        imagegif($img_source);
 115                          break;
 116  
 117      }
 118      
 119      imagedestroy($img_source);
 120      
 121  } else {
 122  
 123      // error / no image
 124      header ('Content-type: image/png');
 125      $new_img = imagecreatetruecolor(75, 20);
 126      $text_color = imagecolorallocate($new_img, 255, 255, 255);
 127      imagestring($new_img, 1, 5, 5,  "Image Error", $text_color);
 128      imagepng($new_img, '', 9);
 129      imagedestroy($new_img);
 130  
 131  }
 132  
 133  function hex2rgb($hex) {
 134    $color = trim(str_replace('#','',$hex));
 135    $rgb = array('r' => intval(hexdec(substr($color,0,2))),
 136                 'g' => intval(hexdec(substr($color,2,2))),
 137                 'b' => intval(hexdec(substr($color,4,2)))
 138                 );
 139    return $rgb;
 140  }
 141  
 142  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7