public function generate() { $findColor = Color::hexColorToArrayColor($this->_find); $replaceColor = Color::hexColorToArrayColor($this->_replace); $index = imagecolorclosest($this->_owner->image, $findColor['red'], $findColor['green'], $findColor['blue']); //find imagecolorset($this->_owner->image, $index, $replaceColor['red'], $replaceColor['green'], $replaceColor['blue']); //replace unset($index); return true; }
public function generate() { $width = $this->_owner->getImageWidth(); $height = $this->_owner->getImageHeight(); $padding = $this->_padding; $arrColor = Color::hexColorToArrayColor($this->_color); $temp = new Canvas(); $temp->createImageTrueColor($width + $padding * 2, $height + $padding * 2); $tempcolor = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']); imagefill($temp->image, 0, 0, $tempcolor); imagecopy($temp->image, $this->_owner->image, $padding, $padding, 0, 0, $width, $height); $this->_owner->image = $temp->image; unset($temp); return true; }
public function generate() { $alt = 0; imagesavealpha($this->_owner->image, true); imagealphablending($this->_owner->image, true); $color = Color::hexColorToArrayColor($this->_color); $light = imagecolorallocatealpha($this->_owner->image, $color['red'], $color['green'], $color['blue'], $this->_light_alpha); $dark = imagecolorallocatealpha($this->_owner->image, $color['red'], $color['green'], $color['blue'], $this->_dark_alpha); for ($x = 0; $x < $this->_owner->getImageHeight(); $x += $this->_width) { if ($alt++ % 2 == 0) { imagefilledrectangle($this->_owner->image, 0, $x, $this->_owner->getImageWidth(), $x + $this->_width - 1, $light); } else { imagefilledrectangle($this->_owner->image, 0, $x, $this->_owner->getImageWidth(), $x + $this->_width - 1, $dark); } } return true; }
public function generate() { $width = $this->_owner->getImageWidth(); $height = $this->_owner->getImageHeight(); $temp = new Canvas(); if (!empty($this->_color)) { $temp->createImageTrueColor($width + ($this->_right + $this->_left), $height + ($this->_top + $this->_bottom)); $arrColor = Color::hexColorToArrayColor($this->_color); $tempcolor = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']); imagefilledrectangle($temp->image, 0, 0, $temp->getImageWidth(), $temp->getImageHeight(), $tempcolor); } else { $temp->createImageTrueColorTransparent($width + ($this->_right + $this->_left), $height + ($this->_top + $this->_bottom)); } imagecopy($temp->image, $this->_owner->image, $this->_left, $this->_top, 0, 0, $width, $height); $this->_owner->image = $temp->image; unset($temp); return true; }
public function generate() { $src_x = $this->_owner->getImageWidth(); $src_y = $this->_owner->getImageHeight(); $temp = new Canvas(); $temp->createImageTrueColorTransparent($src_x, $src_y + 20); $text = str_replace('[Filename]', $this->_owner->getProperty('filename'), $this->_info); switch ($this->_position) { case 't': $x = 0; $y = 20; $bar_y = 0; $text_y = 3; break; case 'b': $x = 0; $y = 0; $bar_y = $src_y + 20; $text_y = $bar_y - 20 + 3; break; default: return false; break; } switch ($this->_justify) { case 'l': $text_x = 3; break; case 'c': $text_x = ($src_x - imagefontwidth($this->_font) * strlen($text)) / 2; break; case 'r': $text_x = $src_x - 3 - imagefontwidth($this->_font) * strlen($text); break; } //Draw the bar background $color = Color::hexColorToArrayColor($this->_barcolor); $bar_color = imagecolorallocate($temp->image, $color['red'], $color['green'], $color['blue']); imagefilledrectangle($temp->image, 0, $bar_y, $src_x, 20, $bar_color); //Copy the image imagecopy($temp->image, $this->_owner->image, $x, $y, 0, 0, $src_x, $src_y); //Draw the text (to be replaced with image_draw_text one day $color = Color::hexColorToArrayColor($this->_textcolor); $text_color = imagecolorallocate($temp->image, $color['red'], $color['green'], $color['blue']); imagestring($temp->image, $this->_font, $text_x, $text_y, $text, $text_color); $this->_owner->image = $temp->image; unset($temp); return true; }
public function generate() { $width = $this->_owner->getImageWidth(); $height = $this->_owner->getImageHeight(); $distance = $this->_distance; $matrix = $this->_matrix; $matrix_width = count($matrix); $matrix_sum = array_sum($matrix); $m_offset = floor($matrix_width / 2); $temp = new Canvas(); $temp->createImageTrueColorTransparent($width + $matrix_width * 2, $height + $matrix_width * 2); imagecopy($temp->image, $this->_owner->image, $matrix_width, $matrix_width, 0, 0, $width, $height); $w = $temp->getImageWidth(); $h = $temp->getImageHeight(); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { $t = $temp->imagecolorat($x, $y); $t1 = Color::intColorToArrayColor($t); $p[$x][$y]['r'] = $t1['red']; $p[$x][$y]['g'] = $t1['green']; $p[$x][$y]['b'] = $t1['blue']; $p[$x][$y]['a'] = $t1['alpha']; $p1[$x][$y]['r'] = 255; $p1[$x][$y]['g'] = 255; $p1[$x][$y]['b'] = 255; $p1[$x][$y]['a'] = 127; } } $w = $this->_owner->getImageWidth(); $h = $this->_owner->getImageHeight(); $d_offset = $distance - $matrix_width; if ($this->_color != 'image') { $arrColor = Color::hexColorToArrayColor($this->_color); } $temp->createImageTrueColorTransparent($width + $distance + $m_offset, $height + $distance + $m_offset); imagesavealpha($temp->image, true); imagealphablending($temp->image, true); for ($i = $m_offset; $i < $w + $m_offset + $matrix_width; $i++) { for ($j = $m_offset; $j < $h + $m_offset + $matrix_width; $j++) { $sumr = 0; $sumg = 0; $sumb = 0; $suma = 0; for ($k = 0; $k < $matrix_width; $k++) { $xx = $i - ($matrix_width >> 1) + $k; $sumr += $p[$xx][$j]['r'] * $matrix[$k]; $sumg += $p[$xx][$j]['g'] * $matrix[$k]; $sumb += $p[$xx][$j]['b'] * $matrix[$k]; $suma += $p[$xx][$j]['a'] * $matrix[$k]; } $p1[$i][$j]['r'] = $sumr / $matrix_sum; $p1[$i][$j]['g'] = $sumg / $matrix_sum; $p1[$i][$j]['b'] = $sumb / $matrix_sum; $p1[$i][$j]['a'] = $suma / $matrix_sum; } } for ($i = $m_offset; $i < $w + $m_offset + $matrix_width; $i++) { for ($j = $m_offset; $j < $h + $m_offset + $matrix_width; $j++) { $sumr = 0; $sumg = 0; $sumb = 0; $suma = 0; for ($k = 0; $k < $matrix_width; $k++) { $xy = $j - ($matrix_width >> 1) + $k; $sumr += $p1[$i][$xy]['r'] * $matrix[$k]; $sumg += $p1[$i][$xy]['g'] * $matrix[$k]; $sumb += $p1[$i][$xy]['b'] * $matrix[$k]; $suma += $p1[$i][$xy]['a'] * $matrix[$k]; } if ($this->_color != 'image') { $col = imagecolorallocatealpha($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], $suma / $matrix_sum); } else { $col = imagecolorallocatealpha($temp->image, $sumr / $matrix_sum, $sumg / $matrix_sum, $sumb / $matrix_sum, $suma / $matrix_sum); } imagesetpixel($temp->image, $i + $d_offset, $j + $d_offset, $col); } } imagecopy($temp->image, $this->_owner->image, 0, 0, 0, 0, $width, $height); $this->_owner->image = $temp->image; unset($temp); return true; }
/** * Allocate a color for an image. * * @param string $color * @param int $alpha * * @return int */ public function imagecolorallocate($color = 'FFFFFF', $alpha = null) { if (is_string($color)) { $arrColor = Color::hexColorToArrayColor($color); } elseif (is_int($color)) { $arrColor = Color::intColorToArrayColor($color); $alpha = $arrColor['alpha']; } if ($alpha) { return imagecolorallocate($this->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']); } else { return imagecolorallocatealpha($this->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], intval($alpha)); } }