Пример #1
0
 public function pass_json($pass_type_identifier = '', $team_identifier = '')
 {
     $array = array('formatVersion' => 1, 'passTypeIdentifier' => $pass_type_identifier, 'teamIdentifier' => $team_identifier, 'serialNumber' => '001', 'organizationName' => '', 'description' => $this->description, 'logoText' => $this->logo_text);
     $array['coupon'] = array();
     $set_coupon_fields = function ($fields, $fields_name) use(&$array) {
         if (count($fields) > 0) {
             $array['coupon'][$fields_name] = array_values(array_map(function ($field) {
                 return $field->to_array();
             }, $fields));
         }
     };
     $set_coupon_fields($this->primary_fields(), 'primaryFields');
     $set_coupon_fields($this->secondary_fields(), 'secondaryFields');
     $set_coupon_fields($this->auxiliary_fields(), 'auxiliaryFields');
     $set_coupon_fields($this->back_fields(), 'backFields');
     if (!empty($this->foreground_color)) {
         $array['foregroundColor'] = 'rgb(' . Color::hex2rgb($this->foreground_color) . ')';
     }
     if (!empty($this->background_color)) {
         $array['backgroundColor'] = 'rgb(' . Color::hex2rgb($this->background_color) . ')';
     }
     if (!empty($this->label_color)) {
         $array['labelColor'] = 'rgb(' . Color::hex2rgb($this->label_color) . ')';
     }
     if (!empty($this->locations)) {
         $array['locations'] = array_map(function ($location) {
             return $location->to_array();
         }, array_values($this->locations));
     }
     if (!empty($this->barcode_message)) {
         $array['barcode'] = array('message' => $this->barcode_message, 'format' => $this->barcode_format(), 'messageEncoding' => 'UTF-8');
     }
     if ($this->relevant_date != 0) {
         $array['relevantDate'] = date('Y-m-d\\TG:i:sP', $this->relevant_date);
     }
     return \Fuel\Core\Format::forge($array)->to_json();
 }
Пример #2
0
 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();
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Create a GD image with text.
  *
  * @param   string    $text        The text to use. TTF fonts accept HTML character codes.
  * @param   integer   $size        Fontsize in pixels. For non-truetype fonts, size has a range of [1-5] points.
  * @param   integer   $padding     Padding in pixels arround the text
  * @param   string    $color       Color of the text
  * @param   string    $background  Background for the text. Default is transparent background.
  * @param   integer   $radius      Radius of rounded corners ont eh background if desired
  * @return  resource               GD resource with text.
  */
 public function text_image($text, $size = 24, $padding = 0, $color = "#ffffff", $background = 'transparent', $radius = 10)
 {
     if ($this->ttfont) {
         # Decode any htmls special chars, insert copyright date
         $text = html_entity_decode($text) . ' ' . chr(169) . date('Y');
         # Get our bounding box coordinates to find width and height.
         $bbox = imagettfbbox($size, 0, $this->ttfont, $text);
         $w = abs($bbox[4] - $bbox[0]) + $padding * 2;
         $h = abs($bbox[5] - $bbox[0]) + $padding * 2;
         # Center horizontally
         $x = $padding;
         # Center vertically
         $y = $h - $padding;
     } else {
         # Insert copyright date
         $text = $text . ' (c)' . date('Y');
         $size = Number::minmax($size, 1, 5);
         $w = imagefontwidth($size) * strlen($text) + 2 * $padding;
         $h = imagefontheight($size) + 2 * $padding;
         # Center horizontally, vertically
         $x = $y = $padding;
     }
     # Blank canvas
     $stamp = imagecreatetruecolor($w, $h);
     # Allocate Transparent background
     imagefill($stamp, 0, 0, imagecolorallocatealpha($stamp, 0, 0, 0, 127));
     # Add (rounded) rectangle to background if desired
     if ($background != 'transparent') {
         $this->imagefillroundedrect($stamp, 0, 0, $w, $h, $radius, $background, 1);
     }
     # Allocate Text Color
     $tcol = Color::hex2rgb($color);
     $tcol = imagecolorallocatealpha($stamp, $tcol[0], $tcol[1], $tcol[2], 0);
     # Allocate text using Truetype font if available
     if ($this->ttfont) {
         imageTTFText($stamp, $size, 0, $x, $y, $tcol, $this->ttfont, $text);
     } else {
         imagestring($stamp, $size, $x, $y, $text, $tcol);
     }
     return $stamp;
 }