/** * Create a new Sparkline instance. */ public function __construct() { /* Initial size doesn't matter, the images resize themselves anyway */ parent::__construct(1, 1); /* Default parameter values */ $this->_seed(array('image-border-top' => 0, 'image-border-right' => 0, 'image-border-bottom' => 0, 'image-border-left' => 0, 'value-scale' => 1, 'draw-zero-axis' => true, 'draw-highlight-max' => false, 'draw-highlight-min' => false, 'background-color' => $this->color_from_string('#fff'), 'zero-axis-color' => $this->color_from_string('#d3d7cf'), 'debug-resize-factor' => 1)); }
/** Test drawing functions */ static function draw_lines_and_shapes() { $img = new AnewtImage(40, 40); $img->fill($img->color_from_rgb(83, 17, 43)); $ctx1 = $img->create_drawing_context(); $ctx2 = $img->create_drawing_context(); /* First context */ $ctx1->set('color', $img->color_from_string('#ff0')); $ctx1->draw_line(18, 18, 21, 18); $ctx1->set('color', $img->color_from_rgb(203, 143, 107)); $ctx1->draw_string(0, 26, 'Anewt'); /* Other context */ $ctx2->set('color', $img->color_from_string('#933')); $ctx2->set('line-width', 5); $ctx2->draw_line(23, 23, 27, 27); $ctx2->draw_point(2, 20); $ctx2->draw_point(2, 22); $ctx2->draw_point(2, 24); /* Back to first context */ $ctx1->draw_line(13, 13, 8, 17); $ctx1->draw_filled_rectangle_size(2, 2, 6, 6); $ctx1->set('color', $img->color_from_string('#3c3')); $ctx1->draw_filled_rectangle_size(3, 3, 4, 3); $ctx1->set('color', $img->color_from_string('#969')); $ctx1->draw_rectangle(3, 3, 6, 7); $ctx1->draw_filled_rectangle_size(15, 2, 2, 2); $ctx1->draw_filled_rectangle_size(15, 2, -1, -1); $col = $img->color_from_string('#36c'); $ctx1->set('color', $col); $ctx1->draw_filled_rectangle(20, 2, 18, 3); assert('$ctx1->color_at(19, 2) == $col'); /* Blow up so we can count the pixels in the result */ $img->resize_relative(10, false); $img->flush_png(); $img->destroy(); }
/** * Flush the output to the browser. The 'filename' property is inspected to * see what file type to use, e.g. PNG or JPEG. * * \see AnewtImage::flush_png * \see AnewtImage::flush_jpeg * \see AnewtImage::save */ public function flush() { assert('$this->is_set("filename")'); $filename = $this->get('filename'); if (AnewtImage::_filename_looks_like_png($filename)) { $this->flush_png($filename); } elseif (AnewtImage::_filename_looks_like_jpeg($filename)) { $this->flush_jpeg($this->get('quality')); } else { trigger_error(sprintf('AnewtImage::save(): Cannot flush image, filename "%s" does not have a supported extension', $filename), E_USER_ERROR); } }