/** * Convert an image. Returns TRUE when successfull, FALSE if image is * not a truecolor image. * * @param img.Image image * @return bool * @throws img.ImagingException */ public function convert($image) { if (!imageistruecolor($image->handle)) { return false; } $tmp = Image::create($image->getWidth(), $image->getHeight(), IMG_TRUECOLOR); $tmp->copyFrom($image); imagetruecolortopalette($image->handle, $this->dither, $this->ncolors); imagecolormatch($tmp->handle, $image->handle); unset($tmp); return true; }
/** * Method to render pie charts * * @param img.chart.PieChart bc * @return img.Image */ public function renderPieChart($pc) { // Create local variables for faster access $border = 50; $sum = $pc->sum(); $innerHeight = $this->height - $border * 2; $innerWidth = $this->width - $border * 2; $middleX = $this->width / 2; $middleY = $this->height / 2; $count = $pc->count(); $font = 2; $fontw = imagefontwidth($font); $fonth = imagefontheight($font); // Create image with($img = Image::create($this->width, $this->height)); $colors = $this->_colors($img, $pc->getColor('sample')); $axisColor = $img->allocate($pc->getColor('axis')); // Flood fill with background color $img->fill($img->allocate($pc->getColor('chartback')), $leftBorder + 1, $topBorder + 1); $pc->getDisplayLegend() && $this->_renderLegend(['labels' => $pc->getLabels(), 'font' => $font, 'fontWidth' => $fontw, 'fontHeight' => $fonth, 'rightBorder' => $border / 5, 'topBorder' => $border / 5, 'margin' => 5, 'legendColor' => $img->allocate($pc->getColor('legend')), 'legendbackColor' => $img->allocate($pc->getColor('legendback')), 'sampleColor' => $colors], $img); $start = $end = 0; for ($i = 0; $i < $count; $i++) { $end += $pc->series[0]->values[$i]; $angle = deg2rad(90 - ($start + ($end - $start) / 2) / $sum * 360); $insetX = sin($angle) * $pc->getValueInset($i); $insetY = cos($angle) * $pc->getvalueInset($i); imagefilledarc($img->handle, $middleX + $insetX, $middleY + $insetY, $innerWidth, $innerHeight, $start / $sum * 360, $end / $sum * 360, $colors[$i % sizeof($colors)]->handle, IMG_ARC_PIE); if ($pc->getDisplayValues()) { imagestring($img->handle, $font, $middleX + $insetX + sin($angle) * $innerWidth / 3 - strlen($pc->series[0]->values[$i]) * $fontw / 2, $middleY + $insetY + cos($angle) * $innerHeight / 3 - $fonth / 2, $pc->series[0]->values[$i], $axisColor->handle); } $start = $end; } return $img; }
public function read() { $s = new MemoryInputStream(base64_decode('R0lGODdhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')); Image::loadFrom(new GifStreamReader($s)); }
public function read() { $s = new MemoryInputStream(base64_decode('/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gNzUK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAAQABAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A9/ooooA//9k=')); Image::loadFrom(new JpegStreamReader($s)); }
public function readMalformedData() { $s = new MemoryInputStream('@@MALFORMED@@'); Image::loadFrom(new PngStreamReader($s)); }
/** * Get Thumbnail * * @return img.Image */ public function getThumbnail() { $s = new Stream(); $s->open(STREAM_MODE_WRITE); $s->write(exif_thumbnail($this->getFilename())); $s->rewind(); return Image::loadFrom(new StreamReader($s)); }
public function read_bc() { $s = new Stream(); FileUtil::setContents($s, base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAACklEQVQImWNgAAAAAgAB9HFkpgAAAABJRU5ErkJggg==')); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
public function read() { $s = new MemoryInputStream(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAACklEQVQImWNgAAAAAgAB9HFkpgAAAABJRU5ErkJggg==')); Image::loadFrom(new PngStreamReader($s)); }
public function read_bc() { $s = new Stream(); FileUtil::setContents($s, base64_decode('R0lGODdhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
public function readMalformedDataBC() { $s = new Stream(); FileUtil::setContents($s, '@@MALFORMED@@'); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
/** * Setup this test. Creates a 1x1 pixel image filled with white. */ public function setUp() { $this->image = \img\Image::create(1, 1); $this->image->fill($this->image->allocate(new \img\Color('#ffffff'))); }