/** * Generates button image to memory */ public function generate() { if ($this->config['signature']) { $im = imagecreatefrompng($this->resourcesDir . '/signatures/en.png'); $this->elements['signature'] = array('im' => $im, 'width' => imagesx($im), 'height' => 17); } else { $this->elements['signature'] = null; } switch ($this->config['theme']) { case 'green': case 'blue': case 'pink': $this->button['fontColor'] = new Color(255, 255, 255, 0); $this->button['shadowColor'] = new Color(0, 0, 0, 70); break; case 'red': case 'black': case 'yellow': $this->button['fontColor'] = new Color(255, 255, 255, 0); $this->button['shadowColor'] = new Color(0, 0, 0, 60); break; case 'grey': $this->button['fontColor'] = new Color(52, 52, 52, 0); $this->button['shadowColor'] = new Color(249, 249, 249, 0); break; default: throw new \InvalidArgumentException('Invalid theme.'); } $im = imagecreatefrompng($this->resourcesDir . '/themes/' . $this->config['theme'] . '.png'); $this->button['im'] = $im; $this->button['width'] = imagesx($im); $this->button['height'] = imagesy($im); $this->button['shadowY'] = -1; if ((int) $this->config['priority'] <= 5 and (int) $this->config['priority'] >= 1) { $this->elements['priority']['val'] = (int) $this->config['priority']; $this->elements['priority']['height'] = 24; } else { $this->elements['priority'] = null; } if ((int) $this->config['priority'] <= 5 and (int) $this->config['priority'] >= 1) { $this->elements['priority']['val'] = (int) $this->config['priority']; $this->elements['priority']['height'] = 24; } else { $this->elements['priority'] = null; } if (!empty($this->config['captionText'])) { if (strlen($this->config['captionText']) < 200) { $this->elements['caption']['text'] = $this->config['captionText']; $this->elements['caption']['height'] = 27; $this->elements['caption']['y'] = 3; } else { throw new \InvalidArgumentException('Invalid caption'); } } else { $this->elements['caption'] = null; } $width = $this->button['width']; $height = 0; if (!is_null($this->elements['priority']) && is_null($this->elements['caption'])) { $height += 37; } elseif (is_null($this->elements['priority']) && !is_null($this->elements['caption'])) { $height += 37; } elseif (!is_null($this->elements['priority']) && !is_null($this->elements['caption'])) { $height += 60; } if (!is_null($this->elements['signature'])) { $height += 17; } $height += $this->button['height']; $this->im = imagecreatetruecolor($width, $height + 10); imagesavealpha($this->im, true); imagefill($this->im, 0, 0, imagecolorallocatealpha($this->im, 0, 0, 0, 127)); /** * MoD signature */ if (!is_null($this->elements['signature'])) { imagecopy($this->im, $this->elements['signature']['im'], ($width - $this->elements['signature']['width']) / 2, 0, 0, 0, $this->elements['signature']['width'], $this->elements['signature']['height']); } /** * Additional information */ if (!is_null($this->elements['priority']) and is_null($this->elements['caption']) or is_null($this->elements['priority']) and !is_null($this->elements['caption'])) { $footer = imagecreatefrompng($this->resourcesDir . '/themes/f1.png'); imagecopy($this->im, $footer, (imagesx($this->im) - imagesx($footer)) / 2, 59 + $this->elements['signature']['height'], 0, 0, imagesx($footer), imagesy($footer)); } if (!is_null($this->elements['priority']) and !is_null($this->elements['caption'])) { $this->elements['priority']['y'] = -13; $footer = imagecreatefrompng($this->resourcesDir . '/themes/f2.png'); imagecopy($this->im, $footer, (imagesx($this->im) - imagesx($footer)) / 2, 53 + $this->elements['signature']['height'], 0, 0, imagesx($footer), imagesy($footer)); } /** * Priorities */ if (!is_null($this->elements['priority'])) { $x = 154; $y = 72 + $this->elements['signature']['height']; if ($this->elements['priority']['val'] < 5) { $starI = imagecreatefrompng($this->resourcesDir . '/stars/s0.png'); } else { throw new \InvalidArgumentException("Too high priority has been specified."); } $starA = imagecreatefrompng($this->resourcesDir . '/stars/s' . $this->elements['priority']['val'] . '.png'); for ($i = 0; $i < $this->elements['priority']['val']; $i++) { imagecopy($this->im, $starA, $x + $i * 18, $y, 0, 0, 17, 17); } for ($i = 0; $i < 5 - $this->elements['priority']['val']; $i++) { imagecopy($this->im, $starI, $x + $this->elements['priority']['val'] * 18 + $i * 18, $y, 0, 0, 17, 17); } $type = new Box($this->im); $type->setFontFace($this->resourcesDir . '/fonts/d.otf'); $type->setFontSize(16); $type->setLineHeight(1.25); $type->setTextShadow(new Color(255, 255, 255), 0, 1); $type->setFontColor(new Color(75, 75, 75)); $type->setTextAlign('right', 'center'); $type->setBox(17, 5 + $this->button['height'] + $this->elements['signature']['height'], 130, 20); $type->draw($this->config['priorityLabel']); } if (!is_null($this->elements['caption'])) { $type = new Box($this->im); $type->setFontFace($this->resourcesDir . '/fonts/bn.ttf'); $type->setFontSize(21); $type->setTextShadow(new Color(255, 255, 255), 0, 1); $type->setFontColor(new Color(52, 52, 52)); $type->setTextAlign('center', 'center'); $type->setBox(10, $this->button['height'] + $this->elements['priority']['height'] + $this->elements['signature']['height'] + $this->elements['caption']['y'], 280, 30); $type->draw($this->elements['caption']['text']); } imagecopy($this->im, $this->button['im'], 0, $this->elements['signature']['height'], 0, 0, $this->button['width'], $this->button['height']); $type = new Box($this->im); $type->setFontFace($this->config['fontPath']); $type->setFontSize($this->config['fontSize']); $type->setLineHeight(0.8); $type->setFontColor($this->button['fontColor']); $type->setTextShadow($this->button['shadowColor'], 0, $this->button['shadowY']); $type->setTextAlign('center', 'center'); $type->setBox(0, 4 + $this->elements['signature']['height'], $this->button['width'], $this->button['height']); $type->draw($this->config['titleText']); imagesavealpha($this->im, true); }