예제 #1
0
 public function imgFill($color, $x, $y, $border = null)
 {
     if (!isset($border)) {
         imagefill($this->handle[$this->hname], $x, $y, self::getColor($color));
     } else {
         imagefilltoborder($this->handle[$this->hname], $x, $y, self::getColor($border), self::getColor($color));
     }
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function apply()
 {
     $color = $this->allocateColor($this->color);
     $x = $y = $this->size - 1;
     $w = $this->width - $this->size;
     $h = $this->height - $this->size;
     imagerectangle($this->resource, $x, $y, $w, $h, $color);
     imagefilltoborder($this->resource, 0, 0, $color, $color);
     return $this->resource;
 }
예제 #3
0
 function CreateLine($strconn, $schema, $table, $column, $srid, $largo, $ancho, $r, $g, $b, $trans, $zoom, $despX, $despY)
 {
     $conn = pg_connect($strconn) or die("Error de Conexion con la base de datos");
     $imagen = imagecreatetruecolor($largo, $ancho);
     $transparencia = imagecolorallocatealpha($imagen, 0, 0, 0, 127);
     imagefilltoborder($imagen, 50, 50, $transparencia, $transparencia);
     imagesavealpha($imagen, true);
     $color = imagecolorallocatealpha($imagen, $r, $g, $b, $trans);
     $query = "\n        SELECT  gid, string_agg((cast(((ST_X(ST_GeometryN(geometria.geom,1))-medidas.xinicial)/medidas.factor) as varchar)), ',') x,\n                string_agg((cast(( {$ancho} -(ST_Y(ST_GeometryN(geometria.geom,1))-medidas.yinicial)/medidas.factor) as varchar)),',') y \n        FROM\n          (SELECT min(st_xmin(geom)) xinicial, (max(st_xmax(geom))-min(st_xmin(geom)))/ {$ancho} factor,min(st_ymin(geom)) yinicial \n           FROM \n             (SELECT st_setsrid(Box2D(st_buffer(p.centroide,((375336.1936-(375336.1936 * {$zoom} ))/2))), {$srid}) geom FROM \n                (SELECT ST_GeomFROMText(st_astext(st_point( 470971.458311897-((470971.458311897 * {$despX} )/2) , 1072807.08034292-((470971.458311897 * {$despY} )/2) )), {$srid}) centroide) p\n             ) c \n          ) medidas,\n          (SELECT gid ,((ST_DumpPoints((ST_GeometryN(tab.{$column},1)))).{$column}) geom FROM {$schema}.\"{$table}\" tab\n           WHERE st_intersects(\n                (SELECT st_setsrid(Box2D(st_buffer(p.centroide,((375336.1936-(375336.1936 * {$zoom} ))/2))), {$srid}) geom FROM \n                    (SELECT ST_GeomFROMText(st_astext(st_point( 470971.458311897-((470971.458311897 * {$despX} )/2) , 1072807.08034292-((470971.458311897 * {$despY} )/2) )), {$srid}) centroide) p\n                ), tab.{$column})\n          ) geometria\n        GROUP BY gid\n        ";
     $result = pg_query($conn, $query) or die("Error al ejecutar la consulta");
     while ($row = pg_fetch_row($result)) {
         $x = explode(",", $row[1]);
         $y = explode(",", $row[2]);
         for ($i = 0; $i < count($x) - 1; $i++) {
             imageline($imagen, $x[$i], $y[$i], $x[$i + 1], $y[$i + 1], $color);
         }
     }
     return $imagen;
 }
예제 #4
0
파일: img.php 프로젝트: art-youth/framework
 static function fill($res, $color, $arr, $name = "fill")
 {
     $key = array_keys(self::$element);
     if ($name == $key[6]) {
         return imagefill($res, $arr[0], $arr[1], $color);
     }
     if ($name == $key[2]) {
         return imagefilledarc($res, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $color, $arr[6]);
     }
     if ($name == $key[3] || $name == $key[4]) {
         $act = 'imagefilled' . $name;
         return $act($res, $arr[0], $arr[1], $arr[2], $arr[3], $color);
     }
     if ($name == $key[5]) {
         return imagefilledpolygon($res, $arr, end($arr), $color);
     }
     if ($name == $key[7]) {
         return imagefilltoborder($res, $arr[0], $arr[1], end($arr), $color);
     }
     return 'method error';
 }
예제 #5
0
파일: image.php 프로젝트: mjiong/framework
 static function fill(&$image, $color, $param, $name = 'rectangle')
 {
     switch ($name) {
         case 'fill':
             //填充
             return imagefill($image, $param[0], $param[1], $color);
         case 'arc':
             //弧形填充
             return imagefilledarc($image, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $color, $param[6]);
         case 'polygon':
             //填充多边形
             return imagefilledpolygon($image, $param, count($param) / 2, $color);
         case 'border':
             //区域填充到指定颜色的边界为止
             return imagefilltoborder($image, $param[0], $param[1], $param[2], $color);
         default:
             //填充椭圆、矩形
             $fill = 'imagefilled' . $name;
             //ellipse,rectangle
             return $fill($image, $param[0], $param[1], $param[2], $param[3], $color);
     }
 }
예제 #6
0
파일: img.php 프로젝트: art-youth/framework
 static function fill(&$image, $color, $param, $name = "fill")
 {
     //填充
     if ($name == 'fill') {
         return imagefill($image, $param[0], $param[1], $color);
     }
     //弧形填充
     if ($name == 'arc') {
         return imagefilledarc($image, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $color, $param[6]);
     }
     //填充椭圆、矩形
     if ($name == 'ellipse' || $name == 'rectangle') {
         $fill = 'imagefilled' . $name;
         return $fill($image, $param[0], $param[1], $param[2], $param[3], $color);
     }
     //填充多边形
     if ($name == 'polygon') {
         return imagefilledpolygon($image, $param, count($param) / 2, $color);
     }
     //区域填充到指定颜色的边界为止
     if ($name == 'border') {
         return imagefilltoborder($image, $param[0], $param[1], $param[2], $color);
     }
 }
예제 #7
0
 function create_used_free_chart($width, $height, $used_memory, $free_memory, $title = 'Free & Used Memory (in %)')
 {
     // Check the input parameters to avoid division by zero and weird cases
     if ($free_memory <= 0 && $used_memory <= 0) {
         $free_memory = 1;
         $used_memory = 0;
     }
     $centerX = 120;
     $centerY = 120;
     $diameter = 120;
     $hmargin = 5;
     // left (right) horizontal margin
     $vmargin = 20;
     // top (bottom) vertical margin
     $image = imagecreate($width, $height);
     // colors
     $white = imagecolorallocate($image, 0xff, 0xff, 0xff);
     $black = imagecolorallocate($image, 0x0, 0x0, 0x0);
     $pie_color[1] = imagecolorallocate($image, 0x5c, 0x87, 0xb2);
     $pie_color[2] = imagecolorallocate($image, 0xcb, 0xe1, 0xef);
     $pie_color[3] = imagecolorallocate($image, 0xc0, 0xc0, 0xc0);
     // Label font size
     $labelfont = 2;
     $hfw = imagefontwidth($labelfont);
     $vfw = imagefontheight($labelfont);
     // Border
     imagerectangle($image, $hmargin, $vmargin, $width - $hmargin, $height - $vmargin, $black);
     // Top label
     $titlefont = 3;
     $txtsize = imagefontwidth($titlefont) * strlen($title);
     $hpos = (int) (($width - $txtsize) / 2);
     $vpos = 3;
     // distance from top
     imagestring($image, $titlefont, $hpos, $vpos, $title, $black);
     $total = 0;
     $n = 0;
     $items = array('Used memory' => $used_memory, 'Free memory' => $free_memory);
     //read the arguments into different arrays:
     foreach ($items as $key => $val) {
         $n++;
         $label[$n] = $key;
         $value[$n] = $val;
         $total += $val;
         $arc_dec[$n] = $total * 360;
         $arc_rad[$n] = $total * 2 * pi();
     }
     //the base:
     $arc_rad[0] = 0;
     $arc_dec[0] = 0;
     //count the labels:
     for ($i = 1; $i <= $n; $i++) {
         //calculate the percents:
         $perc[$i] = $value[$i] / $total;
         $percstr[$i] = (string) number_format($perc[$i] * 100, 2) . "%";
         //label with percentage:
         $label[$i] = $percstr[$i];
         //calculate the arc and line positions:
         $arc_rad[$i] = $arc_rad[$i] / $total;
         $arc_dec[$i] = $arc_dec[$i] / $total;
         $hpos = round($centerX + $diameter / 2 * sin($arc_rad[$i]));
         $vpos = round($centerY + $diameter / 2 * cos($arc_rad[$i]));
         imageline($image, $centerX, $centerY, $hpos, $vpos, $black);
         imagearc($image, $centerX, $centerY, $diameter, $diameter, $arc_dec[$i - 1], $arc_dec[$i], $black);
         //calculate the positions for the labels:
         $arc_rad_label = $arc_rad[$i - 1] + 0.5 * $perc[$i] * 2 * pi();
         $hpos = $centerX + 1.1 * ($diameter / 2) * sin($arc_rad_label);
         $vpos = $centerY + 1.1 * ($diameter / 2) * cos($arc_rad_label);
         if ($arc_rad_label > 0.5 * pi() && $arc_rad_label < 1.5 * pi()) {
             $vpos = $vpos - $vfw;
         }
         if ($arc_rad_label > pi()) {
             $hpos = $hpos - $hfw * strlen($label[$i]);
         }
         //display the labels:
         imagestring($image, $labelfont, $hpos, $vpos, $label[$i], $black);
     }
     //fill the parts with their colors:
     for ($i = 1; $i <= $n; $i++) {
         if (round($arc_dec[$i] - $arc_dec[$i - 1]) != 0) {
             $arc_rad_label = $arc_rad[$i - 1] + 0.5 * $perc[$i] * 2 * pi();
             $hpos = $centerX + 0.8 * ($diameter / 2) * sin($arc_rad_label);
             $vpos = $centerY + 0.8 * ($diameter / 2) * cos($arc_rad_label);
             imagefilltoborder($image, $hpos, $vpos, $black, $pie_color[$i]);
         }
     }
     // legend
     $hpos = $centerX + 1.1 * ($diameter / 2) + $hfw * strlen('50.00%');
     $vpos = $centerY - $diameter / 2;
     $i = 1;
     $thumb_size = 5;
     foreach ($items as $key => $value) {
         imagefilledrectangle($image, $hpos, $vpos, $hpos + $thumb_size, $vpos + $thumb_size, $pie_color[$i++]);
         imagestring($image, $labelfont, $hpos + $thumb_size + 5, $vpos, $key, $black);
         $vpos += $vfw + 2;
     }
     return $image;
 }
예제 #8
0
 /**
  * Fills the image with a specified color at the coordinates
  * defined by x and y
  *
  * @param   var col (either an img.Color[] consisting of the flood color and the
  *          border color) or a simple img.Color defining the flood color
  * @param   int x default 0
  * @param   int y default 0
  * @see     php://imagefill
  * @see     php://imagefilltoborder
  */
 public function fill($col, $x = 0, $y = 0)
 {
     if (is_array($col)) {
         imagefilltoborder($this->handle, $x, $y, $col[1]->handle, $col[0]->handle);
     } else {
         imagefill($this->handle, $x, $y, $col->handle);
     }
 }
예제 #9
0
 /**
  * Draw a filled arc. Will use the imagefilledarc() function if available,
  * and otherwise fall back on a custom method of achieving the same
  * result.
  *
  * @see ImageCanvas::drawArc
  * @param int $x X coordinate
  * @param int $y Y coordinate
  * @param int $width The width of the circle
  * @param int $height The height of the circle
  * @param int $start Starting angle, 0 being north
  * @param int $end Ending angle
  * @param Color $color The color
  */
 function drawFilledArc($x, $y, $width, $height, $start, $end, Color $color)
 {
     $sa = ($start - 90) % 360;
     $ea = ($end - 90) % 360;
     if (function_exists('imagefilledarc')) {
         imagefilledarc($this->himage, $x, $y, $width, $height, $sa - 90, $ea - 90, $color->getColor($this->himage), IMG_ARC_PIE);
     } else {
         $ch = $color->getColor($this->himage);
         imagearc($this->himage, $x, $y, $width, $height, $sa, $ea, $ch);
         $p1x = cos($sa * PI / 180);
         $p1y = sin($sa * PI / 180);
         $p2x = cos($ea * PI / 180);
         $p2y = sin($ea * PI / 180);
         imageline($this->himage, $x, $y, $x + $p1x * ($width / 2), $y + $p1y * ($height / 2), $ch);
         imageline($this->himage, $x, $y, $x + $p2x * ($width / 2), $y + $p2y * ($height / 2), $ch);
         $xmin = min($x, $p1x, $p2x);
         $xmax = max($x, $p1x, $p2x);
         $ymin = min($y, $p1y, $p2y);
         $ymax = max($y, $p1y, $p2y);
         $xc = ($xmax + $xmin) / 2;
         $yc = ($ymax + $ymin) / 2;
         // TODO: This fill doesn't work
         imagefilltoborder($this->himage, $xc, $yc, $ch, $ch);
     }
 }
예제 #10
0
 public function roundcorner($sourceImageFile, $outputfile, $radius = '8')
 {
     # test source image
     if (file_exists($sourceImageFile)) {
         $res = is_array($info = getimagesize($sourceImageFile));
     } else {
         $res = false;
     }
     # open image
     if ($res) {
         $w = $info[0];
         $h = $info[1];
         switch ($info['mime']) {
             case 'image/jpeg':
                 $src = imagecreatefromjpeg($sourceImageFile);
                 break;
             case 'image/gif':
                 $src = imagecreatefromgif($sourceImageFile);
                 break;
             case 'image/png':
                 $src = imagecreatefrompng($sourceImageFile);
                 break;
             default:
                 $res = false;
         }
     }
     # create corners
     if ($res) {
         $q = 10;
         # change this if you want
         $radius *= $q;
         # find unique color
         do {
             $r = rand(0, 255);
             $g = rand(0, 255);
             $b = rand(0, 255);
         } while (imagecolorexact($src, $r, $g, $b) < 0);
         $nw = $w * $q;
         $nh = $h * $q;
         $img = imagecreatetruecolor($nw, $nh);
         $alphacolor = imagecolorallocatealpha($img, $r, $g, $b, 127);
         imagealphablending($img, false);
         imagesavealpha($img, true);
         imagefilledrectangle($img, 0, 0, $nw, $nh, $alphacolor);
         imagefill($img, 0, 0, $alphacolor);
         imagecopyresampled($img, $src, 0, 0, 0, 0, $nw, $nh, $w, $h);
         imagearc($img, $radius - 1, $radius - 1, $radius * 2, $radius * 2, 180, 270, $alphacolor);
         imagefilltoborder($img, 0, 0, $alphacolor, $alphacolor);
         imagearc($img, $nw - $radius, $radius - 1, $radius * 2, $radius * 2, 270, 0, $alphacolor);
         imagefilltoborder($img, $nw - 1, 0, $alphacolor, $alphacolor);
         imagearc($img, $radius - 1, $nh - $radius, $radius * 2, $radius * 2, 90, 180, $alphacolor);
         imagefilltoborder($img, 0, $nh - 1, $alphacolor, $alphacolor);
         imagearc($img, $nw - $radius, $nh - $radius, $radius * 2, $radius * 2, 0, 90, $alphacolor);
         imagefilltoborder($img, $nw - 1, $nh - 1, $alphacolor, $alphacolor);
         imagealphablending($img, true);
         imagecolortransparent($img, $alphacolor);
         # resize image down
         $dest = imagecreatetruecolor($w, $h);
         imagealphablending($dest, false);
         imagesavealpha($dest, true);
         imagefilledrectangle($dest, 0, 0, $w, $h, $alphacolor);
         imagecopyresampled($dest, $img, 0, 0, 0, 0, $w, $h, $nw, $nh);
         $res = $dest;
         imagepng($res, $outputfile);
     }
 }
 public function transform(CGImageBase $src)
 {
     $width = $src['width'];
     $height = $src['height'];
     $radius = $this->_radius;
     $type = $src['type'];
     $color = null;
     $r = $g = $b = 255;
     if ($src->supports_transparency() && !$this->_color) {
         $this->_color = 'transparent';
     }
     if ($this->_color == 'transparent') {
         $type = 'image/png';
     }
     $_dest = new CGImageBase(array($type, $width, $height));
     imagecopy($_dest['rsrc'], $src['rsrc'], 0, 0, 0, 0, $width, $height);
     if ($this->_color) {
         if ($this->_color == 'transparent') {
             // get the dest imagages transparent color.
             $color = $_dest['transparent'];
             if (!$color) {
                 list($r, $g, $b) = cgsi_utils::find_unused_color($_dest);
             }
         } else {
             // use the specified rgb.
             list($r, $g, $b) = cgsi_utils::color_to_rgb($this->_color);
         }
     }
     if (!$color) {
         if ($this->_color == 'transparent') {
             $color = imagecolorallocatealpha($_dest['rsrc'], $r, $g, $b, 127);
         } else {
             $color = imagecolorallocate($_dest['rsrc'], $r, $g, $b);
         }
     }
     if ($this->_color == 'transparent') {
         $_dest['transparent'] = $color;
         imagecolortransparent($_dest['rsrc'], $color);
         imagealphablending($_dest['rsrc'], FALSE);
     }
     // round the corners.
     imagearc($_dest['rsrc'], $radius - 1, $radius - 1, $radius * 2, $radius * 2, 180, 270, $color);
     imagefilltoborder($_dest['rsrc'], 0, 0, $color, $color);
     imagearc($_dest['rsrc'], $width - $radius, $radius - 1, $radius * 2, $radius * 2, 270, 0, $color);
     imagefilltoborder($_dest['rsrc'], $width - 1, 0, $color, $color);
     imagearc($_dest['rsrc'], $radius - 1, $height - $radius, $radius * 2, $radius * 2, 90, 180, $color);
     imagefilltoborder($_dest['rsrc'], 0, $height - 1, $color, $color);
     imagearc($_dest['rsrc'], $width - $radius, $height - $radius, $radius * 2, $radius * 2, 0, 90, $color);
     imagefilltoborder($_dest['rsrc'], $width - 1, $height - 1, $color, $color);
     return $_dest;
 }
예제 #12
0
 function makeThumbWatermark($width = 128, $height = 128)
 {
     $this->fileCheck();
     $image_info = $this->getInfo($this->src_image_name);
     if (!$image_info) {
         return false;
     }
     $src_image_type = $image_info["type"];
     $img = $this->createImage($src_image_type, $this->src_image_name);
     if (!$img) {
         return false;
     }
     $width = $width == 0 ? $image_info["width"] : $width;
     $height = $height == 0 ? $image_info["height"] : $height;
     $width = $width > $image_info["width"] ? $image_info["width"] : $width;
     $height = $height > $image_info["height"] ? $image_info["height"] : $height;
     $srcW = $image_info["width"];
     $srcH = $image_info["height"];
     if ($srcH * $width > $srcW * $height) {
         $width = round($srcW * $height / $srcH);
     } else {
         $height = round($srcH * $width / $srcW);
     }
     //*
     $src_image = @imagecreatetruecolor($width, $height);
     $white = @imagecolorallocate($src_image, 0xff, 0xff, 0xff);
     @imagecolortransparent($src_image, $white);
     @imagefilltoborder($src_image, 0, 0, $white, $white);
     if ($src_image) {
         ImageCopyResampled($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     } else {
         $src_image = imagecreate($width, $height);
         ImageCopyResized($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     }
     $src_image_w = ImageSX($src_image);
     $src_image_h = ImageSY($src_image);
     if ($this->wm_image_name) {
         $wm_image_info = $this->getInfo($this->wm_image_name);
         if (!$wm_image_info) {
             return false;
         }
         $wm_image_type = $wm_image_info["type"];
         $wm_image = $this->createImage($wm_image_type, $this->wm_image_name);
         $wm_image_w = ImageSX($wm_image);
         $wm_image_h = ImageSY($wm_image);
         $temp_wm_image = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos, $wm_image);
         if ($this->emboss && function_exists("imagefilter")) {
             imagefilter($wm_image, IMG_FILTER_EMBOSS);
             $bgcolor = imagecolorclosest($wm_image, 0x7f, 0x7f, 0x7f);
             imagecolortransparent($wm_image, $bgcolor);
         }
         if (function_exists("ImageAlphaBlending") && IMAGETYPE_PNG == $wm_image_info['type']) {
             ImageAlphaBlending($src_image, true);
         }
         $wm_image_x = $temp_wm_image["dest_x"];
         $wm_image_y = $temp_wm_image["dest_y"];
         if (IMAGETYPE_PNG == $wm_image_info['type']) {
             imageCopy($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h);
         } else {
             imageCopyMerge($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h, $this->wm_image_transition);
         }
     }
     if ($this->wm_text) {
         $this->wm_text = $this->wm_text;
         $temp_wm_text = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos);
         $wm_text_x = $temp_wm_text["dest_x"];
         $wm_text_y = $temp_wm_text["dest_y"];
         if (preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)) {
             $red = hexdec($color[1]);
             $green = hexdec($color[2]);
             $blue = hexdec($color[3]);
             $wm_text_color = imagecolorallocate($src_image, $red, $green, $blue);
         } else {
             $wm_text_color = imagecolorallocate($src_image, 255, 255, 255);
         }
         imagettftext($src_image, $this->wm_text_size, $this->wm_angle, $wm_text_x, $wm_text_y, $wm_text_color, $this->wm_text_font, $this->wm_text);
     }
     if ($this->save_file) {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     $src_img = ImageGIF($src_image, $this->save_file);
                 } else {
                     $src_img = ImagePNG($src_image, $this->save_file);
                 }
                 break;
             case 2:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
             case 3:
                 $src_img = ImagePNG($src_image, $this->save_file);
                 break;
             default:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
         }
     } else {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     header("Content-type: image/gif");
                     $src_img = ImageGIF($src_image);
                 } else {
                     header("Content-type: image/png");
                     $src_img = ImagePNG($src_image);
                 }
                 break;
             case 2:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
             case 3:
                 header("Content-type: image/png");
                 $src_img = ImagePNG($src_image);
                 break;
             case 6:
                 header("Content-type: image/bmp");
                 $src_img = imagebmp($src_image);
                 break;
             default:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
         }
     }
     imagedestroy($src_image);
     imagedestroy($img);
     return true;
 }
예제 #13
0
<?php

// Create a image
$image = imagecreatetruecolor(100, 100);
// Draw a rectangle
imagefilledrectangle($image, 0, 0, 100, 100, imagecolorallocate($image, 255, 255, 255));
// Draw an ellipse to fill with a black border
imageellipse($image, 50, 50, 50, 50, imagecolorallocate($image, 0, 0, 0));
// Try to fill border
imagefilltoborder($image, 50, 50);
?>
 
예제 #14
0
 private function setBackground()
 {
     $color = imagecolorallocate($this->image, 48, 63, 68);
     imagefilltoborder($this->image, 0, 0, $color, $color);
 }
예제 #15
0
 public function create($text, $font = null, $material = null, $options = null)
 {
     if (!empty($text)) {
         $this->setText($text);
     }
     if (!empty($font)) {
         $this->setFont($font);
     }
     if (!$this->orderData instanceof \Zivsluck\Entity\Laravel\Order && !empty($options['oid'])) {
         $orderData = zbase_entity('custom_orders')->repository()->byId($options['oid']);
         if (empty($orderData)) {
             return zbase_abort(404);
         }
         $this->setOrderData($orderData);
     }
     $tags = [];
     $dealerCopy = !empty($options['dealerCopy']) ? true : false;
     /**
      * <span id="IL_AD8" class="IL_AD">Setup</span> some custom variables for creating our font and image.
      */
     $chain = !empty($options['chain']) ? $options['chain'] : false;
     $chainLength = !empty($options['chainLength']) ? $options['chainLength'] : false;
     $maxLetter = 7;
     $pricePerLetter = 20;
     $boxWidth = 280;
     $boxHeight = 200;
     $brandingHeightPosition = 200;
     $borderWidth = 10;
     $hasBorder = !empty($dealerCopy) ? true : false;
     $hasDetails = false;
     $fontsNotForMaterial = zbase_config_get('zivsluck.chains.' . $material . '.fonts.not', []);
     $fontNotForMaterial = false;
     $posYDiff = 0;
     if (!empty($fontsNotForMaterial)) {
         if (in_array($font, $fontsNotForMaterial)) {
             $fontNotForMaterial = true;
         }
     }
     if (!empty($chain) && !empty($chainLength)) {
         $hasDetails = true;
         $boxWidth = 280;
         $boxHeight = 600;
         $brandingHeightPosition = 600;
         $chainFile = zbase_config_get('zivsluck.chains.' . strtolower($material) . '.' . strtolower($chain) . '.file', false);
         $chainImage = zbase_public_path() . '/zbase/assets/zivsluck/img/chain/' . $chainFile;
         $tags[] = $chain;
     }
     $letterPrice = 0;
     $shippingFee = 0;
     $hasShipping = false;
     $total = 0;
     $courier = !empty($options['courier']) ? $options['courier'] : false;
     if (!empty($courier)) {
         $courier = zbase_config_get('zivsluck.shipping.' . strtolower($courier), false);
         if (!empty($courier)) {
             $deliveryMode = !empty($options['deliveryMode']) ? $options['deliveryMode'] : false;
             $hasShipping = true;
             $courierName = $courier['name'];
             if ($deliveryMode == 'meetup') {
                 $courierText = 'Meet Up';
                 $shippingFee = 0.0;
             } else {
                 $shippingFee = $courier['fee'];
                 $courierText = $courierName . ' - ' . ($deliveryMode == 'doortodoor' ? 'Door-to-Door' : 'PickUp');
             }
             $boxWidth = 280;
             $boxHeight = 800;
             $brandingHeightPosition = 800;
         }
         if (empty($options['shippingSame'])) {
             $options['shippingFirstName'] = $options['first_name'];
             $options['shippingLastName'] = $options['last_name'];
         }
     }
     $customerNote = !empty($options['customerNote']) ? $options['customerNote'] : '';
     $orderData = $this->getOrderData();
     $statusNew = false;
     $statusPaid = false;
     if (!empty($orderData)) {
         $statusPaid = $orderData->status == 2;
         if (!empty($options['download']) && $orderData->status == 1) {
             $boxWidth = 280;
             $boxHeight = 800 + 380;
             $posYDiff = 190;
             $brandingHeightPosition = 800;
             $statusNew = true;
         }
         if (!empty($statusPaid)) {
             $paymentCenterName = zbase_config_get('zivsluck.paymentCenters.' . $orderData->payment_merchant . '.shortName');
             $paymentAmount = $orderData->total;
             if (file_exists(zbase_storage_path() . '/zivsluck/order/receipts/' . $orderData->maskedId() . '.png')) {
                 $paymentDetailsIm = imagecreatefrompng(zbase_storage_path() . '/zivsluck/order/receipts/' . $orderData->maskedId() . '.png');
                 $boxHeight = $boxHeight + imagesy($paymentDetailsIm);
                 $posYDiff = imagesy($paymentDetailsIm) / 2;
                 $brandingHeightPosition = 800;
             }
         }
     }
     $price = zbase_config_get('zivsluck.price.' . $material, false);
     $fontSize = 30;
     // font size
     $chars = 30;
     $fontFile = zbase_public_path() . '/zbase/assets/zivsluck/fonts/deftonestylus.ttf';
     // the text file to be used
     $verdanaFont = zbase_public_path() . '/zbase/assets/zivsluck/fonts/verdana.ttf';
     // the text file to be used
     $textureFile = zivsluck()->path() . 'resources/assets/img/texture/' . strtolower($material) . '.png';
     // the texture file
     $logo = zivsluck()->path() . 'resources/assets/img/texture/logo.png';
     // the texture file
     $paymentDetails = zivsluck()->path() . 'resources/assets/img/payments/bayadCenter.png';
     // the texture file
     $fontDetails = $this->getFontDetails();
     $tags[] = $material;
     $tags[] = $font;
     if (!empty($dealerCopy)) {
         $boxWidth = 280;
         $boxHeight = 500;
         $brandingHeightPosition = 500;
         $posYDiff = 0;
     }
     /**
      * Get text string that is <span id="IL_AD7" class="IL_AD">passed</span> to this file and clean it up.
      */
     $text = $this->getText();
     $text = trim(strip_tags(html_entity_decode($text)));
     // $text = trim(preg_replace('/ss+/', ' ', $text));
     $text = strlen($text) > $chars ? substr($text, 0, $chars) . '..' : $text;
     if (!empty($fontDetails['enable'])) {
         $fontFile = zbase_public_path() . '/zbase/assets/zivsluck/fonts/' . $fontDetails['file'];
         if (!empty($fontDetails['fontsize'])) {
             $fontSize = $fontDetails['fontsize'];
         }
     } else {
         $fontFile = $verdanaFont;
         $text = 'FONT NOT AVAILABLE.';
     }
     if ($fontNotForMaterial) {
         $fontFile = $verdanaFont;
         $fontSize = 14;
         // font size
         $text = wordwrap("ERROR: \nFONT NOT FOR " . strtoupper($material) . ". \nSelect another font.", 20);
         $hasDetails = false;
         $boxWidth = 280;
         $boxHeight = 200;
         $brandingHeightPosition = 200;
     }
     // <editor-fold defaultstate="collapsed" desc="Image Printin">
     /**
      * Read the TTF file and get the width and height of our font.
      */
     $box = imagettfbbox($fontSize, 0, $fontFile, $text);
     $width = abs($box[2] - $box[0]) + 50;
     /**
      * Create <span id="IL_AD2" class="IL_AD">the blank</span> image, alpha channel and colors.
      */
     // http://stackoverflow.com/questions/26288347/php-gd-complex-stacking-multiple-layers
     // $clipart = imagecreatefrompng(zivsluck()->path() . 'resources/assets/img/createBaseImage.png');
     $bgTexture = imagecreatefrompng($textureFile);
     $noBg = !empty(zbase_cookie('nobg')) ? true : false;
     $logo = imagecreatefrompng($logo);
     $white = imagecolorallocate($bgTexture, 255, 255, 255);
     if ($dealerCopy) {
         // Canvass
         $bgTexture = imagecreatetruecolor($boxWidth - $borderWidth * 2, $boxHeight - $borderWidth * 2);
         // Background Color
         $white = imagecolorallocate($bgTexture, 255, 255, 255);
     }
     if (!empty($noBg)) {
         $bgTexture = imagecreatetruecolor($boxWidth, $boxHeight);
     }
     /**
      * Create text on a white background
      */
     imagefill($bgTexture, 0, 0, $white);
     $textColorBlack = imagecolorallocate($bgTexture, 0, 0, 0);
     if (empty($posY)) {
         if ($hasDetails) {
             if ($hasShipping) {
                 $posY = $boxHeight / 2 + 10 - 300 - $posYDiff;
             } else {
                 $posY = $boxHeight / 2 + 10 - 200 - $posYDiff;
             }
         } else {
             $posY = $boxHeight / 2 + 10 - $posYDiff;
         }
         $posX = $boxWidth / 2 - $width / 2 + 10;
         if (!empty($hasBorder)) {
             $posY = $boxHeight / 2 + 10 - 150 - $borderWidth - $posYDiff;
             $posX = $boxWidth / 2 - $width / 2;
         }
     }
     if ($fontNotForMaterial) {
         imagettftext($bgTexture, $fontSize, 0, $posX, 60, $textColorBlack, $fontFile, $text);
     } else {
         imagettftext($bgTexture, $fontSize, 0, $posX, $posY, $textColorBlack, $fontFile, $text);
     }
     $im = imagecreatetruecolor($boxWidth, $boxHeight);
     if (!empty($dealerCopy)) {
         imagecopy($im, $bgTexture, $borderWidth, $borderWidth, 0, 0, $boxWidth, $boxHeight);
     } else {
         imagecopy($im, $bgTexture, 0, 0, 0, 0, $boxWidth, $boxHeight);
     }
     $img = imagecreatetruecolor($boxWidth, $boxHeight);
     imagecopymerge($img, $im, 0, 0, 0, 0, $boxWidth, $boxHeight, 100);
     if ($hasBorder) {
         imagecopy($img, $logo, 234, $brandingHeightPosition - 45, 0, 0, imagesx($logo), imagesy($logo));
     } else {
         imagecopy($img, $logo, 245, $brandingHeightPosition - 35, 0, 0, $boxWidth, $boxHeight);
     }
     if (!empty($dealerCopy)) {
         // Add border
         imagefilltoborder($img, 1, 1, $textColorBlack, $white);
     }
     // </editor-fold>
     // <editor-fold defaultstate="collapsed" desc="ADDON">
     $totalAddon = 0;
     if (!empty($options['addon'])) {
         $addonDroppableTop = zbase_config_get('zivsluck.addons.configuration.droppable.top') - 5;
         $addonDroppableLeft = zbase_config_get('zivsluck.addons.configuration.droppable.left') - 5;
         $addonDroppableHeight = zbase_config_get('zivsluck.addons.configuration.droppable.height');
         $addonDroppableWidth = zbase_config_get('zivsluck.addons.configuration.droppable.width');
         $addons = explode('|', $options['addon']);
         $includedAddons = [];
         foreach ($addons as $addon) {
             if (!empty($addon)) {
                 //					$addon = explode('-', $addon);
                 //					$addonName = !empty($addon[0]) ? $addon[0] : false;
                 //					$addonEnabled = zbase_config_get('zivsluck.addons.' . $addonName . '.enable');
                 //					$addonFile = zivsluck()->path() . 'resources/assets/img/addons/' . zbase_config_get('zivsluck.addons.' . $addonName . '.file');
                 //					$addonPosition = !empty($addon[1]) ? explode(',', $addon[1]) : false;
                 //					$addonSize = !empty($addon[2]) ? explode('x', $addon[2]) : false;
                 //					$addonRotate = intval(!empty($addon[3]) ? $addon[3] : false);
                 $addon = explode('-', $addon);
                 $addonName = !empty($addon[0]) ? $addon[0] : false;
                 $addonEnabled = true;
                 //zbase_config_get('zivsluck.addons.' . $addonName . '.enable');
                 $addonFile = zivsluck()->path() . 'resources/assets/img/addons/' . $addonName . '.png';
                 $addonPosition = !empty($addon[1]) ? explode(',', $addon[1]) : false;
                 $addonSize = !empty($addon[2]) ? explode('x', $addon[2]) : false;
                 $addonRotate = intval(!empty($addon[3]) ? $addon[3] : false);
                 if (!empty($addonEnabled) && file_exists($addonFile)) {
                     if (!in_array($addonName, $tags)) {
                         $tags[] = $addonName;
                     }
                     $includedAddons[] = $addonName;
                     $addonNewImage = imagecreatetruecolor($addonSize[0], $addonSize[1]);
                     $transparent = imagecolorallocatealpha($addonNewImage, 0, 0, 0, 127);
                     $addonFile = imagecreatefrompng($addonFile);
                     if (!empty($addonRotate)) {
                         $addonFile = imagerotate($addonFile, 360 - $addonRotate, imageColorAllocateAlpha($addonFile, 0, 0, 0, 127));
                     }
                     if (empty($addonSize[0])) {
                         $addonSize[0] = imagesx($addonFile);
                     }
                     if (empty($addonSize[1])) {
                         $addonSize[1] = imagesy($addonFile);
                     }
                     imagefill($addonNewImage, 0, 0, $transparent);
                     imagecopyresampled($addonNewImage, $addonFile, 0, 0, 0, 0, $addonSize[0], $addonSize[1], imagesx($addonFile), imagesy($addonFile));
                     $totalAddon++;
                     imagecopy($img, $addonNewImage, $addonPosition[0] + $addonDroppableLeft, $addonPosition[1] + $addonDroppableTop, 0, 0, $addonSize[0], $addonSize[1]);
                 }
             }
         }
     }
     // </editor-fold>
     // <editor-fold defaultstate="collapsed" desc="Checkout Details">
     if ($hasDetails) {
         // <editor-fold defaultstate="collapsed" desc="DISCOUNT">
         $discountInPrice = zbase_config_get('zivsluck.promotion.discount', 0.0);
         if (!empty($orderData) && !empty($options['final'])) {
             $promo = !empty($options['promo_flag']) ? true : false;
             if (!empty($promo)) {
                 $discountInPrice = $options['promo_discountprice'];
                 $shippingFee = $options['promo_shipping_fee'];
                 $associateOrderId = $options['promo_associate_order_id'];
             } else {
                 if (!empty($options['promo_associate_order_id'])) {
                     $associateOrderId = $options['promo_associate_order_id'];
                 }
             }
         } else {
             $promo = $this->_discountOnNextOrder($text, $font, $material, $options);
             $options['promo_flag'] = 0;
             if (!empty($promo)) {
                 $promoOrder = $promo;
                 $promo = true;
                 $options['promo_flag'] = 1;
                 $shippingFee = 0.0;
                 $options['promo_discountprice'] = $discountInPrice;
                 $options['promo_shipping_fee'] = $shippingFee;
                 $options['promo_associate_order_id'] = $promoOrder->id();
                 $associateOrderId = $promoOrder->id();
             }
         }
         // </editor-fold>
         if (empty($dealerCopy)) {
             $chainImage = imagecreatefrompng($chainImage);
             $total = $price;
             $subTotal = $price;
             $letterCount = strlen($text);
             $addonPrice = 0;
             $totalCharacters = $letterCount + $totalAddon;
             if ($totalCharacters > $maxLetter) {
                 if ($letterCount > $maxLetter) {
                     if (!empty($totalAddon)) {
                         $addonCount = $letterCount + $totalAddon - $maxLetter;
                         $addonPrice = $addonCount * 20;
                         $total += $addonPrice;
                         $subTotal += $addonPrice;
                     }
                 } else {
                     $totalAddon = $totalCharacters - $maxLetter;
                     $addonPrice = $totalAddon * 20;
                 }
             }
             //				if($letterCount < $maxLetter)
             //				{
             //					if(!empty($totalAddon))
             //					{
             //						$addonCount = ($letterCount + $totalAddon) - $maxLetter;
             //						$addonPrice = $addonCount * 20;
             //						$total += $addonPrice;
             //						$subTotal += $addonPrice;
             //					}
             //				}
             //				if($letterCount > $maxLetter)
             //				{
             //					$letterPrice = ($letterCount - $maxLetter) * 20;
             //					$total += $letterPrice;
             //					$addonPrice = $totalAddon * 20;
             //					$total += $addonPrice;
             //					$subTotal += $addonPrice;
             //				}
             $total += $shippingFee;
             if (!empty($promo)) {
                 $total -= $discountInPrice;
             }
             if (!empty($orderData)) {
                 imagettftext($img, 12, 0, 15, 180, $textColorBlack, $verdanaFont, 'ORDER ID: ' . $orderData->maskedId());
             }
             imagecopy($img, $chainImage, 15, 295, 0, 0, imagesx($chainImage), imagesy($chainImage));
         }
         if (!empty($dealerCopy)) {
             imagettftext($img, 9, 0, 25, 200, $textColorBlack, $verdanaFont, 'Text: ' . $text);
             imagettftext($img, 9, 0, 25, 220, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']);
             imagettftext($img, 9, 0, 25, 240, $textColorBlack, $verdanaFont, 'Material: ' . ucfirst($material));
             imagettftext($img, 9, 0, 25, 260, $textColorBlack, $verdanaFont, 'Chain: ' . strtoupper($chain));
             imagettftext($img, 9, 0, 25, 280, $textColorBlack, $verdanaFont, 'Chain Length: ' . $chainLength . '"');
             if (!empty($includedAddons)) {
                 imagettftext($img, 8, 0, 25, 300, $textColorBlack, $verdanaFont, 'Included Addons:');
                 imagettftext($img, 8, 0, 25, 320, $textColorBlack, $verdanaFont, wordwrap(implode(', ', $includedAddons), 30));
             }
             if (!empty($customerNote)) {
                 imagettftext($img, 9, 0, 25, 360, $textColorBlack, $verdanaFont, 'Customer Note:');
                 imagettftext($img, 8, 0, 25, 380, $textColorBlack, $verdanaFont, wordwrap($customerNote, 40));
             }
         } else {
             imagettftext($img, 9, 0, 15, 200, $textColorBlack, $verdanaFont, 'Text: ' . $text);
             imagettftext($img, 9, 0, 15, 215, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']);
             imagettftext($img, 9, 0, 15, 230, $textColorBlack, $verdanaFont, 'Character: ' . strlen($text));
             imagettftext($img, 9, 0, 15, 245, $textColorBlack, $verdanaFont, 'Symbols: ' . $totalAddon);
             imagettftext($img, 9, 0, 15, 260, $textColorBlack, $verdanaFont, 'Material: ' . ucfirst($material));
             imagettftext($img, 9, 0, 15, 275, $textColorBlack, $verdanaFont, 'Chain Length: ' . $chainLength . '"');
             imagettftext($img, 9, 0, 15, 290, $textColorBlack, $verdanaFont, 'Chain: ' . strtoupper($chain));
             if (!empty($this->displayPrice)) {
                 imagettftext($img, 9, 0, 15, 430, $textColorBlack, $verdanaFont, ucfirst($material) . ' Price: Php ' . number_format($price, 2));
                 imagettftext($img, 9, 0, 15, 445, $textColorBlack, $verdanaFont, 'Characters: Php ' . number_format($letterPrice, 2));
                 imagettftext($img, 9, 0, 15, 460, $textColorBlack, $verdanaFont, 'Symbols: Php ' . number_format($addonPrice, 2));
             }
             if ($hasShipping) {
                 imagettftext($img, 9, 0, 15, 475, $textColorBlack, $verdanaFont, 'Shipping: Php ' . number_format($shippingFee, 2));
                 imagettftext($img, 9, 0, 15, 490, $textColorBlack, $verdanaFont, 'Courier: ' . $courierText);
                 if (!empty($promo)) {
                     imagettftext($img, 9, 0, 15, 505, $textColorBlack, $verdanaFont, 'Discount: ' . number_format($discountInPrice, 2) . ' (Order#' . $associateOrderId . ')');
                 } else {
                     if (!empty($associateOrderId)) {
                         imagettftext($img, 9, 0, 15, 505, $textColorBlack, $verdanaFont, 'Associate Order Id: ' . $associateOrderId);
                     }
                 }
                 imagettftext($img, 9, 0, 15, 580, $textColorBlack, $verdanaFont, 'Shipping Information:');
                 imagettftext($img, 9, 0, 15, 600, $textColorBlack, $verdanaFont, $options['shippingFirstName'] . ' ' . $options['shippingLastName']);
                 imagettftext($img, 9, 0, 15, 615, $textColorBlack, $verdanaFont, $options['address']);
                 imagettftext($img, 9, 0, 15, 630, $textColorBlack, $verdanaFont, $options['addressb']);
                 imagettftext($img, 9, 0, 15, 645, $textColorBlack, $verdanaFont, $options['city']);
                 imagettftext($img, 8, 0, 15, 665, $textColorBlack, $verdanaFont, 'Ordered By: ' . $options['first_name'] . ' ' . $options['last_name']);
                 imagettftext($img, 8, 0, 15, 680, $textColorBlack, $verdanaFont, $options['fb']);
                 imagettftext($img, 8, 0, 15, 695, $textColorBlack, $verdanaFont, 'Phone: ' . $options['phone']);
                 if (!empty($options['email'])) {
                     imagettftext($img, 8, 0, 15, 710, $textColorBlack, $verdanaFont, 'Email: ' . $options['email']);
                 }
                 if (!empty($options['oid'])) {
                     imagettftext($img, 8, 0, 15, 748, $textColorBlack, $verdanaFont, 'Order Link: ' . zbase_url_create('order', array('id' => $options['oid'])));
                 }
                 imagettftext($img, 8, 0, 15, 760, $textColorBlack, $verdanaFont, 'Date: ' . date('F d, Y h:i A'));
             }
             if (!empty($this->displayPrice)) {
                 imagettftext($img, 18, 0, 15, 540, $textColorBlack, $verdanaFont, 'Total: Php ' . number_format($total, 2));
             }
             if (!empty($statusPaid)) {
                 imagettftext($img, 9, 0, 15, 555, $textColorBlack, $verdanaFont, 'PAID ' . number_format($paymentAmount, 2) . ' via ' . $paymentCenterName . ' (' . $orderData->paid_date_at->format('m/d/Y') . ')');
             }
             if (!empty($orderData) && $orderData->status == 1 && !empty($options['step']) && $options['step'] == 5) {
                 $orderData->total = $total;
                 $orderData->subtotal = $subTotal;
                 $orderData->shipping_fee = $shippingFee;
                 unset($options['step']);
                 $options['final'] = 1;
                 if (!empty($promoOrder)) {
                     $orderData->promo_flag = 1;
                 }
                 $orderData->details = json_encode($options);
                 if (!empty($tags)) {
                     $orderData->tags = implode(', ', $tags);
                 }
                 $orderData->save();
                 if (!empty($promoOrder)) {
                     $promoOrderDetails = (array) $promoOrder->details();
                     $promoOrderDetails['promo_associate_order_id'] = $orderData->id();
                     $promoOrder->details = json_encode($promoOrderDetails);
                     $promoOrder->promo_flag = 1;
                     $promoOrder->save();
                 }
             }
         }
     } else {
         imagettftext($img, 9, 0, 15, 23, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']);
     }
     if (!empty($hasBorder)) {
         imagettftext($img, 7, 0, 15, $brandingHeightPosition - (10 + $borderWidth), $textColorBlack, $verdanaFont, 'Create your necklace at http://zivsluck.com');
     } else {
         imagettftext($img, 7, 0, 15, $brandingHeightPosition - 10, $textColorBlack, $verdanaFont, 'Create your necklace at http://zivsluck.com');
     }
     if (!empty($statusNew)) {
         $paymentDetailsIm = imagecreatefrompng($paymentDetails);
         imagecopy($img, $paymentDetailsIm, 0, 800, 0, 0, $boxWidth, $boxHeight);
     }
     if (!empty($statusPaid) && empty($dealerCopy)) {
         if (!empty($paymentDetailsIm)) {
             imagecopy($img, $paymentDetailsIm, 0, 800, 0, 0, $boxWidth, $boxHeight);
         }
     }
     // </editor-fold>
     /**
      * Label
      */
     $this->_image = $img;
     return $this;
 }
예제 #16
0
<?php

// Create a image
$image = imagecreatetruecolor(100, 100);
// Draw a rectangle
imagefilledrectangle($image, 0, 0, 100, 100, imagecolorallocate($image, 255, 255, 255));
// Draw an ellipse to fill with a black border
imageellipse($image, 50, 50, 50, 50, imagecolorallocate($image, 0, 0, 0));
// Fill border
imagefilltoborder($image, 50, 50, imagecolorallocate($image, 0, 0, 0), imagecolorallocate($image, 255, 0, 0));
ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();
echo md5(base64_encode($img));
?>
 
예제 #17
0
 public function Round($radius = 12, $corners = array(true), $bg = NULL, $img = NULL)
 {
     $orig_dimensions = $this->GetDimensions();
     if (is_null($img)) {
         $img = $this->img;
     } else {
         $orig_dimensions[0] = imagesx($img);
         $orig_dimensions[1] = imagesy($img);
     }
     if (count($corners) == 1) {
         $top_left = $corners[0];
         $top_right = $corners[0];
         $bottom_left = $corners[0];
         $bottom_right = $corners[0];
     } else {
         if (count($corners) == 4) {
             $top_left = $corners[0];
             $top_right = $corners[1];
             $bottom_right = $corners[2];
             $bottom_left = $corners[3];
         } else {
             die('Insufficient Arguments for Corners');
         }
     }
     $this->new_img = imagecreatetruecolor($orig_dimensions[0], $orig_dimensions[1]);
     //get background color
     if (is_null($bg)) {
         $palette = imagecreatetruecolor($orig_dimensions[0], $orig_dimensions[1]);
         $found = false;
         while ($found == false) {
             $r = rand(0, 255);
             $g = rand(0, 255);
             $b = rand(0, 255);
             if (imagecolorexact($img, $r, $g, $b) != -1) {
                 $backcolor = imagecolorallocate($palette, $r, $g, $b);
                 $found = true;
             }
         }
     }
     $endsize = $radius;
     $startsize = $endsize * 3 - 1;
     $arcsize = $startsize * 2 + 1;
     $background = imagecreatetruecolor($orig_dimensions[0], $orig_dimensions[1]);
     imagecopymerge($background, $img, 0, 0, 0, 0, $orig_dimensions[0], $orig_dimensions[1], 100);
     $startx = $orig_dimensions[0] - $startsize;
     $starty = $orig_dimensions[1] - $startsize;
     //echo $startsize;
     imagecopyresampled($this->new_img, $img, 0, 0, 0, 0, $orig_dimensions[0], $orig_dimensions[0], $orig_dimensions[0], $orig_dimensions[1]);
     $bg = imagecolorallocate($this->new_img, hexdec(substr($backcolor, 0, 2)), hexdec(substr($backcolor, 2, 2)), hexdec(substr($backcolor, 4, 2)));
     //$fg = imagecolorallocate($this->new_img, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2)));
     //top-left corner
     if ($top_left == true) {
         imagearc($this->new_img, $startsize, $startsize, $arcsize, $arcsize, 180, 270, $bg);
         imagefilltoborder($this->new_img, 0, 0, $bg, $bg);
     }
     // Bottom-left corner
     if ($bottom_left == true) {
         imagearc($this->new_img, $startsize, $starty, $arcsize, $arcsize, 90, 180, $bg);
         imagefilltoborder($this->new_img, 0, $orig_dimensions[1], $bg, $bg);
     }
     // Bottom-right corner
     if ($bottom_right == true) {
         imagearc($this->new_img, $startx, $starty, $arcsize, $arcsize, 0, 90, $bg);
         imagefilltoborder($this->new_img, $orig_dimensions[0], $orig_dimensions[1], $bg, $bg);
     }
     // Top-right corner
     if ($top_right == true) {
         imagearc($this->new_img, $startx, $startsize, $arcsize, $arcsize, 270, 360, $bg);
         imagefilltoborder($this->new_img, $orig_dimensions[0], 0, $bg, $bg);
     }
     imagecolortransparent($this->new_img, $bg);
 }
예제 #18
0
파일: graidle.php 프로젝트: NickCis/LigaPes
 function create()
 {
     if (in_array("b", $this->type) || in_array("l", $this->type)) {
         for ($bar = $i = 0; $i < count($this->type); $i++) {
             if ($this->type[$i] == 'b') {
                 $bar += 1;
             }
         }
         $this->disbar = $this->larg * $bar;
         $this->ld = $this->larg + $this->disbar;
         # variabile di comodo #
         if (in_array("l", $this->type) && $this->disbar == 0) {
             $this->disbar = 2 * $this->larg;
             $this->ld = $this->disbar;
             # variabile di comodo #
         }
         if (!isset($this->mass)) {
             $this->mass = $this->mx;
         }
         if (!isset($this->mnvs)) {
             $this->mnvs = $this->mn;
         }
         if (isset($this->name)) {
             graidle::setLegend($this->name);
         }
         if (!isset($this->dvx)) {
             if ($this->mass <= 1) {
                 $this->dvx = round($this->mass / 5, 1);
             } else {
                 if ($this->mass > 1 && $this->mass < 10) {
                     $this->dvx = 1;
                 } else {
                     $this->dvx = round($this->mass / 10);
                 }
             }
         }
         if (!isset($this->AA)) {
             $this->AA = 2;
         }
         if ($this->mx > 0) {
             if ($this->mass == $this->mx) {
                 $this->scarmax = 1;
             } else {
                 $this->scarmax = $this->mass - $this->mx;
             }
         }
         $this->scarmin = $this->mn;
         if ($this->mn < 0) {
             if ($this->mnvs > 0 || !isset($this->mnvs)) {
                 $this->scarmin = 0;
             } else {
                 if ($this->mnvs > $this->mn || $this->mnvs < $this->mn) {
                     $this->scarmin = $this->mnvs - $this->mn;
                 } else {
                     $this->scarmin = -1;
                 }
             }
         }
         if (strlen($this->mn) > strlen($this->mx)) {
             $this->y_flag = strlen($this->mn);
         } else {
             $this->y_flag = strlen($this->mx);
         }
         $this->s += $this->font_small * graidle::stringLen($this->mass);
         if (!isset($this->w)) {
             $this->w = $this->ld * $this->cnt + $this->s + $this->d;
             if ($this->w < 640) {
                 while ($this->w < 640) {
                     $this->larg += 0.01;
                     $this->disbar = $this->larg * $bar;
                     $this->ld = $this->larg + $this->disbar;
                     $this->w = round($this->ld * $this->cnt) + $this->s + $this->d;
                 }
             } else {
                 while ($this->w > 641) {
                     $this->larg -= 0.01;
                     $this->disbar = $this->larg * $bar;
                     $this->ld = $this->larg + $this->disbar;
                     $this->w = $this->ld * $this->cnt + $this->s + $this->d;
                 }
             }
         } else {
             while ($this->ld * $this->cnt + $this->s + $this->d >= $this->w) {
                 $this->larg -= 0.01;
                 $this->disbar = $this->larg;
                 $this->ld = $this->larg + $this->disbar;
             }
             while ($this->ld * $this->cnt + $this->s + $this->d <= $this->w) {
                 $this->larg += 0.01;
                 $this->disbar = $this->larg;
                 $this->ld = $this->larg + $this->disbar;
             }
         }
         if (!isset($this->h)) {
             $this->h = round(3 / 4 * $this->w);
         }
         $this->b += 2 * $this->font_small;
         if ($this->mnvs > 0 && $this->mass > 0) {
             $this->mul = ($this->h - $this->a - $this->b) / ($this->mass - $this->mnvs);
         } else {
             $this->mul = ($this->h - $this->a - $this->b) / ($this->mass + $this->scarmax + (abs($this->mn) - $this->scarmin));
         }
         $this->div = $this->dvx * $this->mul;
         $this->im = imagecreatetruecolor($this->w, $this->h);
         $rgb = Color::hex2rgb($this->axis_color);
         $this->axis_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
         $rgb = Color::hex2rgb($this->font_color);
         $this->font_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
         $rgb = Color::hex2rgb($this->bg_color);
         $this->bg_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
         imagefilltoborder($this->im, 1, 1, 1, $this->bg_color);
         if (isset($this->legend) || isset($this->name)) {
             graidle::legend();
         }
         graidle::title($this->title, $this->xAxis, $this->yAxis);
         graidle::gradAxis($this->sx, $this->sy);
         if (in_array("b", $this->type)) {
             include "graidle_histo.ext.php";
             histogram::drawHisto();
         }
         graidle::drawAxis();
         if (in_array("l", $this->type)) {
             include "graidle_line.ext.php";
             line::drawLine();
         }
     } else {
         if (in_array("hb", $this->type)) {
             for ($bar = $i = 0; $i < count($this->type); $i++) {
                 if ($this->type[$i] == 'hb') {
                     $bar += 1;
                 }
             }
             $this->disbar = $this->larg * $bar;
             if (isset($this->name)) {
                 graidle::setLegend($this->name);
             }
             if (!isset($this->mass)) {
                 $this->mass = $this->mx;
             }
             if (!isset($this->mnvs)) {
                 $this->mnvs = $this->mn;
             }
             if (!isset($this->dvx)) {
                 if ($this->mass <= 1) {
                     $this->dvx = round($this->mass / 5, 1);
                 } else {
                     if ($this->mass > 1 && $this->mass < 10) {
                         $this->dvx = 1;
                     } else {
                         $this->dvx = round($this->mass / 10);
                     }
                 }
             }
             if (!isset($this->AA)) {
                 $this->AA = 4;
             }
             $this->b += 5 * $this->font_small;
             $this->d += round(graidle::StringLen($this->mass) * ($this->font_small / 4));
             if (isset($this->vlx)) {
                 for ($maxlen = $i = 0; $i <= count($this->vlx); $i++) {
                     if (isset($this->vlx[$i])) {
                         $curlen = graidle::stringlen($this->vlx[$i]) * $this->font_small;
                         if ($maxlen < $curlen) {
                             $maxlen = $curlen;
                         }
                     }
                 }
                 $this->s += $maxlen + 10;
             } else {
                 $this->s += $this->font_small * 4;
             }
             if (isset($this->yAxis)) {
                 $this->s += 2 * $this->fontsmall;
             }
             $this->ld = $this->larg + $this->disbar;
             # variabile di comodo #
             if (!isset($this->h)) {
                 $this->h = $this->ld * $this->cnt + $this->a + $this->b;
                 if ($this->h < 500) {
                     while ($this->h < 500) {
                         $this->larg += 0.01;
                         $this->disbar = $this->larg * $bar;
                         $this->ld = $this->larg + $this->disbar;
                         $this->h = round($this->ld * $this->cnt) + $this->a + $this->b;
                     }
                 } else {
                     while ($this->h > 501) {
                         $this->larg -= 0.01;
                         $this->disbar = $this->larg * $bar;
                         $this->ld = $this->larg + $this->disbar;
                         $this->h = $this->ld * $this->cnt + $this->a + $this->b;
                     }
                 }
             } else {
                 while ($this->ld * $this->cnt + $this->a + $this->b <= $this->h) {
                     $this->larg += 0.01;
                     $this->disbar = $this->larg * $bar;
                     $this->ld = $this->larg + $this->disbar;
                 }
                 while ($this->ld * $this->cnt + $this->a + $this->b >= $this->h) {
                     $this->larg -= 0.01;
                     $this->disbar = $this->larg * $bar;
                     $this->ld = $this->larg + $this->disbar;
                 }
             }
             if (!isset($this->w)) {
                 $this->w = round(4 / 5 * $this->h);
             }
             if ($this->mnvs > 0 && $this->mass > 0) {
                 $this->mul = ($this->w - $this->s - $this->d) / ($this->mass - $this->mnvs);
             } else {
                 $this->mul = ($this->w - $this->s - $this->d) / ($this->mass + abs($this->mnvs));
             }
             $this->im = imagecreatetruecolor($this->w, $this->h);
             $rgb = Color::hex2rgb($this->axis_color);
             $this->axis_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
             $rgb = Color::hex2rgb($this->font_color);
             $this->font_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
             $rgb = Color::hex2rgb($this->bg_color);
             $this->bg_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
             imagefilltoborder($this->im, 1, 1, 1, $this->bg_color);
             if (isset($this->legend) || isset($this->name)) {
                 graidle::legend();
             }
             include "graidle_horizhisto.ext.php";
             HorizHistogram::gradAxis($this->sx, $this->sy);
             HorizHistogram::drawHorizHisto();
             HorizHistogram::drawAxis();
             graidle::title($this->title, $this->xAxis, $this->yAxis);
         } else {
             if (in_array("p", $this->type)) {
                 include "graidle_pie.ext.php";
                 for ($this->pie = $i = 0; $i < count($this->type); $i++) {
                     if ($this->type[$i] == 'p') {
                         $this->pie += 1;
                     }
                 }
                 if (!isset($this->incl)) {
                     $this->incl = 55;
                 }
                 if (!isset($this->AA)) {
                     $this->AA = 4;
                 }
                 if (!isset($this->w)) {
                     $this->w = 500;
                 }
                 if (!isset($this->h)) {
                     $this->h = 500;
                 }
                 $this->tre_d = 0;
                 if ($this->incl < 90) {
                     $this->tre_d = round($this->incl / 5);
                 }
                 $this->radius = $this->w;
                 $e = sin(deg2rad($this->incl));
                 $rapp = pow($e, 2);
                 $a = $this->radius;
                 $b = $a * $rapp;
                 while ($a >= $this->w - $this->s - $this->d) {
                     $a -= 1;
                     $this->radius = $a;
                     $b = $a * $rapp;
                 }
                 while ($b * $this->pie > $this->h - $this->a - $this->pie * $this->b - $this->pie * $this->tre_d) {
                     $b -= 1;
                     $a = $b / $rapp;
                     $this->radius = $a;
                 }
                 $this->im = imagecreatetruecolor($this->w, $this->h);
                 #<----CREO L'IMMAGINE PER IL GRAFICO A TORTA
                 $rgb = Color::hex2rgb($this->bg_color);
                 $this->bg_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
                 imagefilltoborder($this->im, 1, 1, 1, $this->bg_color);
                 #<---- Creo lo sfondo
                 $rgb = Color::hex2rgb($this->font_color);
                 $this->font_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
                 if (isset($this->legend)) {
                     graidle::legend();
                 }
                 graidle::title($this->title);
                 pie::drawPie($a, $b);
             } else {
                 if (in_array("s", $this->type)) {
                     include "graidle_spider.ext.php";
                     if (!isset($this->mass)) {
                         $this->mass = $this->mx;
                     }
                     if (!isset($this->filled)) {
                         $this->filled = 1;
                     }
                     if (!isset($this->AA)) {
                         $this->AA = 4;
                     }
                     if (!isset($this->w)) {
                         if (isset($this->h)) {
                             $this->w = round($this->h * (5 / 4));
                         } else {
                             $this->w = 500;
                         }
                     }
                     if (!isset($this->h)) {
                         $this->h = round($this->w * (4 / 5));
                     }
                     if (isset($this->name)) {
                         graidle::setLegend($this->name);
                     }
                     if (!isset($this->dvx)) {
                         if ($this->mass / 10 < 1) {
                             $this->dvx = round($this->mass / 5, 1);
                         } else {
                             $this->dvx = round($this->mass / 10);
                         }
                     }
                     $this->radius = $this->w - $this->s - $this->d;
                     while ($this->radius >= $this->h - $this->a - $this->b) {
                         $this->radius -= 1;
                     }
                     $this->radius = round($this->radius / 2);
                     $this->im = imagecreatetruecolor($this->w, $this->h);
                     #<----CREO L'IMMAGINE PER IL GRAFICO A TORTA
                     $rgb = Color::hex2rgb($this->bg_color);
                     $this->bg_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
                     imagefilltoborder($this->im, 1, 1, 1, $this->bg_color);
                     #<---- Creo lo sfondo
                     $rgb = Color::hex2rgb($this->font_color);
                     $this->font_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
                     $rgb = Color::hex2rgb($this->axis_color);
                     $this->axis_color = imagecolorallocate($this->im, $rgb[0], $rgb[1], $rgb[2]);
                     if (isset($this->legend)) {
                         graidle::legend();
                     }
                     graidle::title($this->title);
                     spider::drawSpider();
                 }
             }
         }
     }
 }
예제 #19
0
<?php

// Create a image
$image = imagecreatetruecolor(100, 100);
// Draw a rectangle
imagefilledrectangle($image, 0, 0, 100, 100, imagecolorallocate($image, 255, 255, 255));
// Draw an ellipse to fill with a black border
imageellipse($image, 50, 50, 50, 50, imagecolorallocate($image, 0, 0, 0));
// Try to fill border
imagefilltoborder($image, 50, 50, 'wrong param', imagecolorallocate($image, 255, 0, 0));
?>
 
예제 #20
0
 function DrawPie()
 {
     $fsize = $this->Fsize;
     $image = imagecreate($this->a * 2 + 40, $this->b * 2 + 40);
     $PieCenterX = $this->a + 10;
     $PieCenterY = $this->b + 10;
     $DoubleA = $this->a * 2;
     $DoubleB = $this->b * 2;
     list($R, $G, $B) = getRGB(0);
     $colorBorder = imagecolorallocate($image, $R, $G, $B);
     $DataNumber = count($this->DataArray);
     //$DataTotal
     for ($i = 0; $i < $DataNumber; $i++) {
         $DataTotal += $this->DataArray[$i];
     }
     //算出数据和
     //填充背景
     imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));
     /* 
      ** 画每一个扇形 
      */
     $Degrees = 0;
     for ($i = 0; $i < $DataNumber; $i++) {
         $StartDegrees = round($Degrees);
         $Degrees += $this->DataArray[$i] / $DataTotal * 360;
         $EndDegrees = round($Degrees);
         $percent = number_format($this->DataArray[$i] / $DataTotal * 100, 1);
         if ($this->ColorArray[$i]) {
             $aColor = $this->ColorArray[$i];
         } else {
             $aColor = $this->getRanColor();
         }
         list($R, $G, $B) = getRGB(hexdec($aColor));
         $CurrentColor = imagecolorallocate($image, $R, $G, $B);
         if ($R > 60 and $R < 256) {
             $R = $R - 60;
         }
         if ($G > 60 and $G < 256) {
             $G = $G - 60;
         }
         if ($B > 60 and $B < 256) {
             $B = $B - 60;
         }
         $CurrentDarkColor = imagecolorallocate($image, $R, $G, $B);
         //画扇形弧
         imagearc($image, $PieCenterX, $PieCenterY, $DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentColor);
         //画直线
         list($ArcX, $ArcY) = pie_point($StartDegrees, $this->a, $this->b);
         imageline($image, $PieCenterX, $PieCenterY, floor($PieCenterX + $ArcX), floor($PieCenterY + $ArcY), $CurrentColor);
         //画直线
         list($ArcX, $ArcY) = pie_point($EndDegrees, $this->a, $this->b);
         imageline($image, $PieCenterX, $PieCenterY, ceil($PieCenterX + $ArcX), ceil($PieCenterY + $ArcY), $CurrentColor);
         //填充扇形
         $MidPoint = round(($EndDegrees - $StartDegrees) / 2 + $StartDegrees);
         list($ArcX, $ArcY) = Pie_point($MidPoint, $this->a * 3 / 4, $this->b * 3 / 4);
         //simkai.ttf
         imagefilltoborder($image, floor($PieCenterX + $ArcX), floor($PieCenterY + $ArcY), $CurrentColor, $CurrentColor);
         //imagestring($image,$fsize,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),"中国".$percent."%",$colorBorder);
         //imagettftext ($image,12,0,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),$colorBorder,'simkai.ttf',$this->NameArray[$i]."(".$percent."%)");
         //画阴影
         if ($StartDegrees >= 0 and $StartDegrees <= 180) {
             if ($EndDegrees <= 180) {
                 for ($k = 1; $k < 15; $k++) {
                     imagearc($image, $PieCenterX, $PieCenterY + $k, $DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
                 }
             } else {
                 for ($k = 1; $k < 15; $k++) {
                     imagearc($image, $PieCenterX, $PieCenterY + $k, $DoubleA, $DoubleB, $StartDegrees, 180, $CurrentDarkColor);
                 }
             }
         }
         imagettftext($image, 12, 0, floor($PieCenterX + $ArcX - 5) - 66, floor($PieCenterY + $ArcY - 5), $colorBorder, 'simkai.ttf', $this->NameArray[$i] . "(" . $percent . "%)");
     }
     //输出生成的图片
     imagepng($image);
     imagedestroy($image);
 }
예제 #21
0
 /**
  * 
  */
 public function getImage()
 {
     $width = count($this->_charValues) * ($this->_dotSize + $this->_dotMargin) + $this->_dotMargin;
     $height = ($this->_dotSize + $this->_dotMargin) * 6 + $this->_dotSize;
     $im = imagecreatetruecolor($width, $height);
     imageantialias($im, true);
     $bg = imagecolorallocate($im, ($this->_background & 0xff0000) >> 16, ($this->_background & 0xff00) >> 8, $this->_background & 0xff);
     $fg = imagecolorallocate($im, ($this->_foreground & 0xff0000) >> 16, ($this->_foreground & 0xff00) >> 8, $this->_foreground & 0xff);
     $border = imagecolorallocate($im, ($this->_border & 0xff0000) >> 16, ($this->_border & 0xff00) >> 8, $this->_border & 0xff);
     imagefilltoborder($im, 0, 0, $bg, $bg);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $border);
     foreach ($this->_charValues as $key => $value) {
         imagefilledellipse($im, ($this->_dotSize + $this->_dotMargin) * $key + $this->_dotSize, ($this->_dotSize + $this->_dotMargin) * 2 + $this->_dotSize, $this->_smallDotSize, $this->_smallDotSize, $fg);
         if (0x1 & $value) {
             imagefilledellipse($im, ($this->_dotSize + $this->_dotMargin) * $key + $this->_dotSize, $this->_dotSize, $this->_dotSize, $this->_dotSize, $fg);
         }
         if (0x2 & $value) {
             imagefilledellipse($im, ($this->_dotSize + $this->_dotMargin) * $key + $this->_dotSize, ($this->_dotSize + $this->_dotMargin) * 1 + $this->_dotSize, $this->_dotSize, $this->_dotSize, $fg);
         }
         if (0x4 & $value) {
             imagefilledellipse($im, ($this->_dotSize + $this->_dotMargin) * $key + $this->_dotSize, ($this->_dotSize + $this->_dotMargin) * 3 + $this->_dotSize, $this->_dotSize, $this->_dotSize, $fg);
         }
         if (0x8 & $value) {
             imagefilledellipse($im, ($this->_dotSize + $this->_dotMargin) * $key + $this->_dotSize, ($this->_dotSize + $this->_dotMargin) * 4 + $this->_dotSize, $this->_dotSize, $this->_dotSize, $fg);
         }
         if (0x10 & $value) {
             imagefilledellipse($im, ($this->_dotSize + $this->_dotMargin) * $key + $this->_dotSize, ($this->_dotSize + $this->_dotMargin) * 5 + $this->_dotSize, $this->_dotSize, $this->_dotSize, $fg);
         }
     }
     return $im;
 }
예제 #22
0
 function drawPieChart($img)
 {
     //determine total of all values
     $dataLength = $this->dataSet->getLength();
     $this->chartTotal = $this->dataSet->getValuesSum();
     $this->chartCenterX = $this->chartDiameter / 2 + 10;
     $this->chartCenterY = $this->chartDiameter / 2 + 10;
     //allocate colors
     $colorBody = imagecolorallocate($img, 0xff, 0xff, 0xff);
     $colorBorder = imagecolorallocate($img, 0x0, 0x0, 0x0);
     $colorBorderShadow = imagecolorallocate($img, 0xcc, 0xcc, 0xcc);
     $colorText = imagecolorallocate($img, 0x0, 0x0, 0x0);
     $startColors = array('FF0000', '00FF00', '0000FF', 'FFFF00', 'FF00FF', '00FFFF', '990000', '009900', '000099', '999900', '990099', '009999');
     $endColors = array('FF5151', '86FF87', '7374FF', 'FFFFA2', 'FFA8FF', '93FEFF', 'FF5353', '9FFFA0', '7374FF', 'FEFF71', 'FE57FF', '66FDFF');
     foreach ($startColors as $color) {
         $argghh = $this->getRGBColor($color);
         $colorSlice[] = ImageColorAllocate($img, $argghh['red'], $argghh['green'], $argghh['blue']);
     }
     //fill background
     imagefill($img, 0, 0, $colorBody);
     $this->drawBackgroundFade($img, 0, 0, $this->chartWidth, $this->chartHeight / 2, 'B0C4DE', 'FFFFFF', FADE_HORIZONTAL);
     /*
      ** draw each slice
      */
     $degrees = 0;
     $index = 0;
     $vals = $this->dataSet->values;
     $keys = array_keys($this->dataSet->values);
     while ($index < $dataLength) {
         $startDegrees = round($degrees);
         $degrees += $vals[$keys[$index]] / $this->chartTotal * 360;
         $endDegrees = round($degrees);
         $CurrentColor = $colorSlice[$index % count($colorSlice)];
         //draw arc
         imagearc($img, $this->chartCenterX, $this->chartCenterY, $this->chartDiameter, $this->chartDiameter, $startDegrees, $endDegrees, $colorBorder);
         //draw start line from center
         list($ArcX, $ArcY) = $this->circle_point($startDegrees, $this->chartDiameter);
         imageline($img, $this->chartCenterX, $this->chartCenterY, floor($this->chartCenterX + $ArcX), floor($this->chartCenterY + $ArcY), $colorBorder);
         //draw end line from center
         list($ArcX, $ArcY) = $this->circle_point($endDegrees, $this->chartDiameter);
         imageline($img, $this->chartCenterX, $this->chartCenterY, ceil($this->chartCenterX + $ArcX), ceil($this->chartCenterY + $ArcY), $colorBorder);
         //fill slice
         $MidPoint = round(($endDegrees - $startDegrees) / 2 + $startDegrees);
         list($ArcX, $ArcY) = $this->circle_point($MidPoint, $this->chartDiameter / 2);
         imagefilltoborder($img, floor($this->chartCenterX + $ArcX), floor($this->chartCenterY + $ArcY), $colorBorder, $CurrentColor);
         if ($this->useFade) {
             $this->drawPieFade($img, $this->chartCenterX, $this->chartCenterY, $this->chartDiameter, $this->chartDiameter, $startDegrees, $endDegrees, $startColors[$index % count($colorSlice)], $endColors[$index % count($colorSlice)]);
         }
         // height of key
         $LineY = $this->chartDiameter + 20 + $index * ($this->chartFontHeight + 2);
         //draw color box
         imagerectangle($img, 10, $LineY, 10 + $this->chartFontHeight, $LineY + $this->chartFontHeight, $colorBorder);
         imagefilltoborder($img, 12, $LineY + 2, $colorBorder, $CurrentColor);
         //draw label
         imagestring($img, $this->chartFont, 20 + $this->chartFontHeight, $LineY, $keys[$index] . ': ' . $vals[$keys[$index]], $colorText);
         $index++;
         // loop iterator
     }
     //draw border
     imagearc($img, $this->chartCenterX, $this->chartCenterY, $this->chartDiameter, $this->chartDiameter, 0, 180, $colorBorder);
     imagearc($img, $this->chartCenterX, $this->chartCenterY, $this->chartDiameter, $this->chartDiameter, 180, 360, $colorBorder);
     imagearc($img, $this->chartCenterX, $this->chartCenterY, $this->chartDiameter + 7, $this->chartDiameter + 7, 0, 180, $colorBorder);
     imagearc($img, $this->chartCenterX, $this->chartCenterY, $this->chartDiameter + 7, $this->chartDiameter + 7, 180, 360, $colorBorder);
     imagefilltoborder($img, floor($this->chartCenterX + $this->chartDiameter / 2 + 2), $this->chartCenterY, $colorBorder, $colorBorder);
     //output image
     header("Content-type: image/png");
     imagepng($img);
     imagedestroy($img);
 }
 /**
  *  This function creates the graph and either sends it to the browser
  *  of saves it to a file.
  *
  *  @param  $file   (optional) If specified, the graph will be saved to
  *                  the indicated file. If left as default, the graph
  *                  will be outputted to the browser.
  */
 function plot($file = '')
 {
     // margins
     $margin = $this->m_margin;
     $marginy = $margin;
     $marginx = $margin + 5;
     if ($this->m_title) {
         $marginy += $this->m_fontHeight * 1.5;
     }
     $marginbottom = $margin + 5;
     $height = $this->m_height - $marginy - $marginbottom;
     $width = $this->m_width - $marginx - $margin;
     imagefilledrectangle($this->m_image, $marginx, $marginy, $marginx + $width, $marginy + $height, $this->m_fillColor);
     // plot title
     if ($this->m_title) {
         imagestring($this->m_image, $this->m_font, ($this->m_width - strlen($this->m_title) * $this->m_fontWidth) / 2, $margin, $this->m_title, $this->m_textColor);
     }
     YDGraph::_set_style($this->m_image, SOLID, $this->m_strokeColor, $this->m_fillColor);
     $sum = array_sum($this->m_values);
     $colors = array('#CC3232', '#70DBDB', '#66CD00', '#FF4040', '#8A2BE2', '#5F9F9F', '#EED2EE', '#E9967A', '#6666FF', '#A2C257', '#EEB4B4', '#8F5E99', '#EEC900', '#EE799F', '#B2DFEE', '#70DB93', '#F4A460', '#AAAAFF', '#CC3232', '#70DBDB', '#66CD00', '#FF4040', '#8A2BE2', '#5F9F9F', '#EED2EE', '#E9967A', '#6666FF', '#A2C257', '#EEB4B4', '#8F5E99', '#EEC900', '#EE799F', '#B2DFEE', '#70DB93', '#F4A460', '#AAAAFF');
     // pieces
     $degrees = array();
     for ($i = 0; $i < count($this->m_values); $i++) {
         $value = $this->m_values[$i] / $sum * 360;
         if ($value > 0 && floor($value / 360 * 100) > 0) {
             $degrees[$i] = $value;
         }
     }
     // sizes
     $diamx = $width / 2;
     $diamy = $height;
     if ($diamx > $diamy) {
         $diam = $diamy;
     } else {
         $diam = $diamx;
     }
     $radius = $diam / 2;
     $x = $marginx + $radius;
     $y = $marginy + $radius;
     imagearc($this->m_image, $x, $y, $diam, $diam, 0, 360, $this->m_strokeColor);
     // lines
     $last_angle = 0;
     foreach ($degrees as $i => $deg) {
         $last_angle = $last_angle + $deg;
         $end_x = floor($x + $radius * cos($last_angle * pi() / 180));
         $end_y = floor($y + $radius * sin($last_angle * pi() / 180));
         imageline($this->m_image, $x, $y, $end_x, $end_y, $this->m_strokeColor);
     }
     // colors
     $last_angle = 0;
     $pointer = 0;
     $max_len = 0;
     foreach ($degrees as $i => $deg) {
         $pointer = $last_angle + $deg;
         $this_angle = ($last_angle + $pointer) / 2;
         $last_angle = $pointer;
         $end_x = floor($x + $radius * cos($this_angle * pi() / 180));
         $end_y = floor($y + $radius * sin($this_angle * pi() / 180));
         $mid_x = floor(($x + $end_x) / 2);
         $mid_y = floor(($y + $end_y) / 2);
         $hex_split = YDGraph::_decode_color($colors[$i]);
         if (isset($this->m_colors[$i])) {
             $hex_split = YDGraph::_decode_color($this->m_colors[$i]);
         }
         $piece_color = imagecolorallocate($this->m_image, $hex_split[0], $hex_split[1], $hex_split[2]);
         imagefilltoborder($this->m_image, $mid_x, $mid_y, $this->m_strokeColor, $piece_color);
         $percent = number_format($deg / 360 * 100, $this->m_numberOfDecimals, $this->m_decimalSeparator, $this->m_thousandsSeparator);
         $max_len = strlen($percent) > $max_len ? strlen($percent) : $max_len;
     }
     // labels
     $last_position = $marginy;
     foreach ($degrees as $i => $deg) {
         $percent = number_format($deg / 360 * 100, $this->m_numberOfDecimals, $this->m_decimalSeparator, $this->m_thousandsSeparator);
         $align = 0;
         switch ($this->m_labelsFont) {
             case 1:
                 $align = 1;
                 break;
             case 2:
                 $align = -1;
                 break;
             case 3:
             case 4:
                 $align = -2;
                 break;
             case 5:
             case 6:
             case 7:
             case 8:
                 $align = -3;
                 break;
         }
         if ($this->m_labelsFontHeight + 3 >= 15) {
             $last_position += $this->m_labelsFontHeight + 3;
         } else {
             $last_position += 15;
         }
         $hex_split = YDGraph::_decode_color($colors[$i]);
         if (isset($this->m_colors[$i])) {
             $hex_split = YDGraph::_decode_color($this->m_colors[$i]);
         }
         $piece_color = imagecolorallocate($this->m_image, $hex_split[0], $hex_split[1], $hex_split[2]);
         $w = $x + $radius;
         $h = $last_position;
         imagefilledrectangle($this->m_image, $w + 20, $h, $w + 30, $h + 10, $piece_color);
         imagestring($this->m_image, $this->m_labelsFont, $w + 40, $h + $align, str_repeat(' ', $max_len - strlen($percent)) . $percent . "% " . $this->m_labels[$i], $this->m_labelsTextColor);
     }
     if ($this->m_showtotal) {
         if (isset($this->m_total)) {
             $sum = $this->m_total;
         }
         if ($this->m_formattotal) {
             $sum = number_format($sum, $this->m_numberOfDecimals, $this->m_decimalSeparator, $this->m_thousandsSeparator);
         }
         imagestring($this->m_image, $this->m_labelsFont, $w + 20, $h + 20, $this->m_totalstring . $sum, $this->m_labelsTextColor);
     }
     if (strlen($file) > 0) {
         switch (YDConfig::get('YD_GRAPH_TYPE')) {
             case IMG_GIF:
                 imagegif($this->m_image, $file);
                 break;
             case IMG_JPG:
             case IMG_JPEG:
                 imagejpeg($this->m_image, $file);
                 break;
             default:
                 imagepng($this->m_image, $file);
                 break;
         }
     } else {
         switch (YDConfig::get('YD_GRAPH_TYPE')) {
             case IMG_GIF:
                 header('Content-type: image/gif');
                 imagegif($this->m_image);
                 break;
             case IMG_JPG:
             case IMG_JPEG:
                 header('Content-type: image/jpeg');
                 imagejpeg($this->m_image);
                 break;
             default:
                 header('Content-type: image/png');
                 imagepng($this->m_image);
                 break;
         }
     }
 }
예제 #24
0
function img_resize($img_src_file, $set_w, $set_h, $mode = "s")
{
    list($src_w, $src_h, $src_t, $src_a) = getimagesize($img_src_file);
    $set_tangent = $set_h / $set_w;
    //�ㅼ젙���대�吏�쓽 媛�줈�몃줈 鍮꾩쑉
    $src_tangent = $src_h / $src_w;
    //�뚯뒪�대�吏�쓽 媛�줈�몃줈 鍮꾩쑉
    $img_dst = @imagecreatetruecolor($set_w, $set_h);
    $white = @imagecolorallocate($img_dst, 255, 255, 255);
    @imagefilltoborder($img_dst, 0, 0, $white, $white);
    if ($src_t == "1") {
        //gif �대�吏�씪 寃쎌슦
        $img_src = @imagecreatefromgif($img_src_file);
    } else {
        if ($src_t == "2") {
            //jpg �대�吏�씪 寃쎌슦
            $img_src = @imagecreatefromjpeg($img_src_file);
        } else {
            if ($src_t == "3") {
                //png �대�吏�씪 寃쎌슦
                $img_src = @imagecreatefrompng($img_src_file);
            }
        }
    }
    if ($mode == "c") {
        // �명똿鍮꾩쑉��留욌룄濡��곹븯 �먮뒗 醫뚯슦瑜�而룻듃��
        $cut_x = $src_tangent > $set_tangent ? 0 : ($src_w - $src_h / $set_tangent) / 2;
        $cut_y = $src_tangent > $set_tangent ? ($src_h - $src_w * $set_tangent) / 2 : 0;
        @imagecopyresized($img_dst, $img_src, 0, 0, $cut_x, $cut_y, $set_w, $set_h, $src_w - $cut_x * 2, $src_h - $cut_y * 2);
    } else {
        if ($mode == "s") {
            // �명똿 �ш린��洹몃�濡��먮릺, �ㅼ뼱媛�뒗 �대�吏�쓽 鍮꾩쑉留��뺣�/異뺤냼���ㅼ쓬 �l쓬
            $span_x = $src_tangent > $set_tangent ? $set_h / $src_tangent : $set_w;
            $span_y = $src_tangent > $set_tangent ? $set_h : $set_w * $src_tangent;
            $padding_x = (int) (($set_w - $span_x) / 2);
            $padding_y = (int) (($set_h - $span_y) / 2);
            @imagecopyresized($img_dst, $img_src, $padding_x, $padding_y, 0, 0, $span_x, $span_y, $src_w, $src_h);
        }
    }
    return $img_dst;
}
예제 #25
0
header("Content-type: image/png");
$width = 100;
$height = 100;
$r = 0;
$g = 0;
$b = 255;
//$alpha = 0;
if (isset($_GET['w'])) {
    $width = $_GET['w'];
}
if (isset($_GET['h'])) {
    $height = $_GET['h'];
}
if (isset($_GET['c'])) {
    $c = $_GET['c'];
    $r = hexdec($c[0] . $c[1]);
    $g = hexdec($c[2] . $c[3]);
    $b = hexdec($c[4] . $c[5]);
}
$im = imagecreatetruecolor($width, $height);
$color = ImageColorAllocate($im, $r, $g, $b);
$white = ImageColorAllocate($im, 255, 255, 255);
imagefilltoborder($im, 0, 0, $white, $white);
imagecolortransparent($im, $white);
$cx = ceil($width / 2);
$cy = ceil($height / 2);
ImageFilledEllipse($im, $cx, $cy, $width - 1, $height - 1, $color);
// send the new PNG image to the browser
imagepng($im);
// destroy the reference pointer to the image in memory to free up resources
imagedestroy($im);
예제 #26
0
 /**
  * Adds a rounded border to image
  * Based on the original script located in http://911-need-code-help.blogspot.com/2009/05/generate-images-with-round-corners-on.html
  * @param int $radius The size of the border
  * @param boolean $transparent Defines if the image will have a transparent background (png/gif only)
  * @return boolean true on success and false on errors
  */
 public function borderRadius($radius = 10, $transparent = true)
 {
     if (is_resource($this->image) === false) {
         $this->eventLog('No picture was uploaded', __FILE__, __LINE__);
         return false;
     }
     if (is_numeric($radius) === false || $radius <= 0) {
         $this->eventLog('$radius must be greater than zero', __FILE__, __LINE__);
         return false;
     }
     $half = $radius / 2;
     $position = $radius + 3;
     // corners
     imagearc($this->image, $half, $half, $position, $position, 180, -90, $this->bgColor);
     imagearc($this->image, $half, $this->info['height'] - $half - 1, $position, $position, 90, 180, $this->bgColor);
     imagearc($this->image, $this->info['width'] - $half - 1, $this->info['height'] - $half - 1, $position, $position, 0, 90, $this->bgColor);
     imagearc($this->image, $this->info['width'] - $half - 1, $half, $position, $position, 270, 0, $this->bgColor);
     // fill
     imagefilltoborder($this->image, 0, 0, $this->bgColor, $this->bgColor);
     imagefilltoborder($this->image, $this->info['width'], $this->info['height'], $this->bgColor, $this->bgColor);
     imagefilltoborder($this->image, 0, $this->info['height'], $this->bgColor, $this->bgColor);
     imagefilltoborder($this->image, $this->info['width'], 0, $this->bgColor, $this->bgColor);
     if ($transparent === true) {
         imagecolortransparent($this->image, $this->bgColor);
     }
     $this->eventLog('The image had yours corners rounded in ' . $radius . 'px', __FILE__, __LINE__);
     return true;
 }
예제 #27
0
function crearImagenLineas($x, $y, $zi, $mx, $my, $capa)
{
    $factor = 366468.447793805 / $x;
    $img = imagecreatetruecolor($x, $y);
    $trans = imagecolorallocatealpha($img, 255, 255, 255, 127);
    $red = imagecolorallocatealpha($img, 255, 0, 0, 63);
    $blue = imagecolorallocatealpha($img, 0, 0, 255, 63);
    $white = imagecolorallocatealpha($img, 255, 248, 246, 63);
    if ($capa == "rios") {
        $color = $blue;
    } else {
        if ($capa == "caminos") {
            $color = $white;
        }
    }
    imagefilltoborder($img, 0, 0, $trans, $trans);
    imagesavealpha($img, true);
    $host = 'localhost';
    $db = 'cursoGIS';
    $usr = '******';
    $pass = '******';
    $strconn = "host={$host} port=5432 dbname={$db} user={$usr} password={$pass}";
    $conn = pg_connect($strconn) or die("Error de Conexion con la base de datos");
    $query = "select r.gid gid,\r\n\tstring_agg(CAST(((ST_X(ST_GeometryN(r.geom,1))-283585.639702539)/{$factor}) as varchar(100)),', ') x,\r\n\tstring_agg(CAST(({$x} - (ST_Y(ST_GeometryN(r.geom,1))-889378.554139937)/{$factor}) as varchar(100)),', ') y\r\nfrom (select ((ST_DumpPoints((ST_GeometryN(geom,1)))).geom) geom, gid \r\n\tFROM {$capa}) r\r\n\tgroup by gid";
    $result = pg_query($conn, $query) or die("Error al ejecutar la consulta");
    while ($row = pg_fetch_row($result)) {
        $arrayX = explode(", ", $row[1]);
        $arrayY = explode(", ", $row[2]);
        for ($i = 0; $i < count($arrayX) - 1; ++$i) {
            $x1 = ajustar($arrayX[$i], $zi, $x, $mx);
            $x2 = ajustar($arrayX[$i + 1], $zi, $x, $mx);
            $y1 = ajustar($arrayY[$i], $zi, $y, $my);
            $y2 = ajustar($arrayY[$i + 1], $zi, $y, $my);
            imageline($img, $x1, $y1, $x2, $y2, $color);
        }
    }
    return $img;
}
예제 #28
0
/**
 * ref: http://www.tricksofit.com/2014/08/round-corners-on-image-using-php-and-gd-library
 *
 * @param resource $sourceImage GD Image resource
 * @param int[]    $radii       array(top left, top right, bottom left, bottom right) of pixel radius
 *                               for each corner. A 0 disables rounding on a corner.
 *
 * @return resource
 */
function imageCreateCorners($sourceImage, $radii)
{
    $q = 2;
    // quality - improve alpha blending by using larger (*$q) image size
    // find a unique color
    $tryCounter = 0;
    do {
        if (++$tryCounter > 255) {
            $r = 2;
            $g = 254;
            $b = 0;
            break;
        }
        $r = rand(0, 255);
        $g = rand(0, 255);
        $b = rand(0, 255);
    } while (imagecolorexact($sourceImage, $r, $g, $b) < 0);
    $imageWidth = imagesx($sourceImage);
    $imageHeight = imagesy($sourceImage);
    $workingWidth = $imageWidth * $q;
    $workingHeight = $imageHeight * $q;
    $workingImage = imagecreatetruecolor($workingWidth, $workingHeight);
    $alphaColor = imagecolorallocatealpha($workingImage, $r, $g, $b, 127);
    imagealphablending($workingImage, false);
    imagesavealpha($workingImage, true);
    imagefilledrectangle($workingImage, 0, 0, $workingWidth, $workingHeight, $alphaColor);
    imagefill($workingImage, 0, 0, $alphaColor);
    imagecopyresampled($workingImage, $sourceImage, 0, 0, 0, 0, $workingWidth, $workingHeight, $imageWidth, $imageHeight);
    if (0 < ($radius = $radii[0] * $q)) {
        // left top
        imagearc($workingImage, $radius - 1, $radius - 1, $radius * 2, $radius * 2, 180, 270, $alphaColor);
        imagefilltoborder($workingImage, 0, 0, $alphaColor, $alphaColor);
    }
    if (0 < ($radius = $radii[1] * $q)) {
        // right top
        imagearc($workingImage, $workingWidth - $radius, $radius - 1, $radius * 2, $radius * 2, 270, 0, $alphaColor);
        imagefilltoborder($workingImage, $workingWidth - 1, 0, $alphaColor, $alphaColor);
    }
    if (0 < ($radius = $radii[2] * $q)) {
        // left bottom
        imagearc($workingImage, $radius - 1, $workingHeight - $radius, $radius * 2, $radius * 2, 90, 180, $alphaColor);
        imagefilltoborder($workingImage, 0, $workingHeight - 1, $alphaColor, $alphaColor);
    }
    if (0 < ($radius = $radii[3] * $q)) {
        // right bottom
        imagearc($workingImage, $workingWidth - $radius, $workingHeight - $radius, $radius * 2, $radius * 2, 0, 90, $alphaColor);
        imagefilltoborder($workingImage, $workingWidth - 1, $workingHeight - 1, $alphaColor, $alphaColor);
    }
    imagealphablending($workingImage, true);
    imagecolortransparent($workingImage, $alphaColor);
    // scale back down to original size
    $destinationImage = imagecreatetruecolor($imageWidth, $imageHeight);
    imagealphablending($destinationImage, false);
    imagesavealpha($destinationImage, true);
    imagefilledrectangle($destinationImage, 0, 0, $imageWidth, $imageHeight, $alphaColor);
    imagecopyresampled($destinationImage, $workingImage, 0, 0, 0, 0, $imageWidth, $imageHeight, $workingWidth, $workingHeight);
    // imagedestroy($sourceImage);
    imagedestroy($workingImage);
    return $destinationImage;
}
예제 #29
0
 function FillToBorder($x, $y, $aBordColor)
 {
     $bc = $this->rgb->allocate($aBordColor);
     if ($bc == -1) {
         JpGraphError::Raise('Image::FillToBorder : Can not allocate more colors');
         exit;
     }
     imagefilltoborder($this->img, round($x), round($y), $bc, $this->current_color);
 }
예제 #30
0
        // On vérifie si le nombre d'inscrits représente au moins un millième du total
        // (Sans cela, il se produit un bug d'affichage)
        //
        $part = 0;
        if ($total_inscrits > 0 && ($part = round($listes[$i]['num'] / $total_inscrits, 3)) > 0.001) {
            $deb_arc = round($degre);
            $degre += $part * 360;
            $end_arc = round($degre);
            imagearc($im, $startX, $startY, 100, 100, $deb_arc, $end_arc, $color_arc);
            list($arcX, $arcY) = xy_arc($deb_arc, 100);
            imageline($im, $startX, $startY, floor($startX + $arcX), floor($startY + $arcY), $color_arc);
            list($arcX, $arcY) = xy_arc($end_arc, 100);
            imageline($im, $startX, $startY, ceil($startX + $arcX), ceil($startY + $arcY), $color_arc);
            $mid_arc = round(($end_arc - $deb_arc) / 2 + $deb_arc);
            list($arcX, $arcY) = xy_arc($mid_arc, 50);
            imagefilltoborder($im, floor($startX + $arcX), floor($startY + $arcY), $color_arc, $color_arc);
        }
        //
        // Insertion du carré de couleur pour la légende, suivi du nom de la liste et du nombre d'abonnés
        //
        imagefilledrectangle($im, 165, $globalY + $int + 2, 175, $globalY + $int + 12, $gray2);
        imagefilledrectangle($im, 166, $globalY + $int + 1, 176, $globalY + $int + 11, $color_arc);
        imagestring($im, $text_font, 185, $globalY + $int, sprintf('%s [%d] [%s%%]', $listes[$i]['name'], $listes[$i]['num'], wa_number_format($part > 0 ? round($part * 100, 2) : 0, 1)), $black);
    }
    imagearc($im, $startX, $startY, 100, 100, 0, 360, $black);
    imagearc($im, $startX, $startY, 101, 101, 0, 360, $black);
    send_image('parts_by_liste', $im);
}
$output->build_listbox(AUTH_VIEW, false);
require WA_ROOTDIR . '/includes/functions.box.php';
if ($session->sessid_url != '') {