public function generate() { $this->calculate(); $crop = new Image_Image(); $crop->createImageTrueColorTransparent($this->canvas_x, $this->canvas_y); $src_x = $this->_owner->getHandleX() - floor($this->canvas_x / 2); $src_y = $this->_owner->getHandleY() - floor($this->canvas_y / 2); imagecopy($crop->image, $this->_owner->image, 0, 0, $src_x, $src_y, $this->canvas_x, $this->canvas_y); $this->_owner->image = $crop->image; unset($crop); return true; }
public function generate() { $width = $this->_owner->imagesx(); $height = $this->_owner->imagesy(); $temp = new Image_Image(); $temp->createImageTrueColor($width, $height); imagecopy($temp->image, $this->_owner->image, $this->offset_x, $this->offset_y, 0, 0, $width - $this->offset_x, $height - $this->offset_y); imagecopy($temp->image, $this->_owner->image, 0, 0, $width - $this->offset_x, $height - $this->offset_y, $this->offset_x, $this->offset_y); imagecopy($temp->image, $this->_owner->image, 0, $this->offset_y, $width - $this->offset_x, 0, $this->offset_x, $height - $this->offset_y); imagecopy($temp->image, $this->_owner->image, $this->offset_x, 0, 0, $height - $this->offset_y, $width - $this->offset_x, $this->offset_y); $this->_owner->image = $temp->image; unset($temp); return true; }
public function generate() { $src_x = $this->_owner->imagesx(); $src_y = $this->_owner->imagesy(); $temp = new Image_Image(); $temp->createImageTrueColorTransparent($src_x, $src_y + 20); $text = str_replace("[Filename]", $this->_owner->getSettings('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 $arrColor = $this->_owner->hexColorToArrayColor($this->barcolor); $bar_color = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['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 $arrColor = $this->_owner->hexColorToArrayColor($this->textcolor); $text_color = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['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->imagesx(); $height = $this->_owner->imagesy(); $padding = $this->padding; $arrColor = Image_Image::hexColorToArrayColor($this->color); $temp = new Image_Image(); $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() { $width = $this->_owner->imagesx(); $height = $this->_owner->imagesy(); $mx = array(array(-0, 0, 0), array(-1, 0, 1), array(-0, 0, 0)); $my = array(array(0, 1, 0), array(0, 0, 0), array(-0, -1, -0)); $m_elements = count($mx); $m_offset = floor($m_elements / 2); $p = array(); for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { $rgb = $this->_owner->imagecolorat($x, $y); $arrRgb = Image_Image::intColorToArrayColor($rgb); $p[$x][$y]['r'] = $arrRgb['red']; $p[$x][$y]['g'] = $arrRgb['green']; $p[$x][$y]['b'] = $arrRgb['blue']; } } for ($y = 1; $y < $height - 1; $y++) { for ($x = 1; $x < $width - 1; $x++) { $sumXr = $sumXg = $sumXb = $sumYr = $sumYg = $sumYb = 0; for ($i = -1; $i <= 1; $i++) { for ($j = -1; $j <= 1; $j++) { $sumXr = $sumXr + $p[$x + $i][$y + $j]['r'] * $mx[$i + 1][$j + 1]; $sumXg = $sumXg + $p[$x + $i][$y + $j]['g'] * $mx[$i + 1][$j + 1]; $sumXb = $sumXb + $p[$x + $i][$y + $j]['b'] * $mx[$i + 1][$j + 1]; $sumYr = $sumYr + $p[$x + $i][$y + $j]['r'] * $my[$i + 1][$j + 1]; $sumYg = $sumYg + $p[$x + $i][$y + $j]['g'] * $my[$i + 1][$j + 1]; $sumYb = $sumYb + $p[$x + $i][$y + $j]['b'] * $my[$i + 1][$j + 1]; } } $sumr = abs($sumXr) + abs($sumYr); $sumg = abs($sumXg) + abs($sumYg); $sumb = abs($sumXb) + abs($sumYb); if ($sumr > 255) { $sumr = 255; } if ($sumg > 255) { $sumg = 255; } if ($sumb > 255) { $sumb = 255; } if ($sumr < 0) { $sumr = 0; } if ($sumg < 0) { $sumg = 0; } if ($sumb < 0) { $sumb = 0; } $color = imagecolorallocate($this->_owner->image, 255 - $sumr, 255 - $sumg, 255 - $sumb); imagesetpixel($this->_owner->image, $x, $y, $color); } } return true; }
public function generate() { $findColor = Image_Image::hexColorToArrayColor($this->find); $replaceColor = Image_Image::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 testSize() { $image = new Image_Image(); $analyser = $image->attach(new Image_Helper_Analyser()); $image->openImage(TEST_BASE . DIRECTORY_SEPARATOR . 'image.png'); $this->assertEquals($image->testImageHandle(), true); $this->assertEquals($image->imagesx(), 100); $this->assertEquals($image->imagesy(), 100); $image->destroyImage(); }
public function testCalculateResizeAndCrop() { $image = new Image_Image(); $resize = new Image_Fx_Resize(); $resize_id = $image->attach($resize); $crop = new Image_Fx_Crop(); $crop_id = $image->attach($crop); if ($image->gd_support_png) { $this->assertEquals($image->openImage(TEST_BASE . DIRECTORY_SEPARATOR . "resize.png"), true); $image->{$resize_id}->resize_x = 160; $image->{$crop_id}->crop_x = 120; $image->evaluateFXStack(); $this->assertEquals($image->imagesx(), 120); $this->assertEquals($image->imagesy(), 120); } }
public function generate() { $alt = 0; imagesavealpha($this->_owner->image, true); imagealphablending($this->_owner->image, true); $arrColor = Image_Image::hexColorToArrayColor($this->color); $l = imagecolorallocatealpha($this->_owner->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], $this->light_alpha); $d = imagecolorallocatealpha($this->_owner->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], $this->dark_alpha); for ($x = 0; $x < $this->_owner->imagesy(); $x += $this->width) { if ($alt++ % 2 == 0) { imagefilledrectangle($this->_owner->image, 0, $x, $this->_owner->imagesx(), $x + $this->width - 1, $l); } else { imagefilledrectangle($this->_owner->image, 0, $x, $this->_owner->imagesx(), $x + $this->width - 1, $d); } } return true; }
public function generate() { $width = $this->_owner->imagesx(); $height = $this->_owner->imagesy(); $temp = new Image_Image(); if (!empty($this->color)) { $temp->createImageTrueColor($width + ($this->r + $this->l), $height + ($this->t + $this->b)); $arrColor = Image_Image::hexColorToArrayColor($this->color); $tempcolor = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']); imagefilledrectangle($temp->image, 0, 0, $temp->imagesx(), $temp->imagesy(), $tempcolor); } else { $temp->createImageTrueColorTransparent($width + ($this->r + $this->l), $height + ($this->t + $this->b)); } imagecopy($temp->image, $this->_owner->image, $this->l, $this->t, 0, 0, $width, $height); $this->_owner->image = $temp->image; unset($temp); return true; }
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/car.jpg'); $image->attach(new Image_Fx_Resize(198)); $image->attach(new Image_Fx_Crop(156, 60)); $image->attach(new Image_Fx_Blackandwhite()); $image->attach(new Image_Draw_Border(2, "000000")); $image->attach(new Image_Draw_Border(1, "FFFFFF")); $image->attach(new Image_Draw_Border(17, "000000")); $image->imagePng();
public function generate() { $width = $this->_owner->imagesx(); $height = $this->_owner->imagesy(); $distance = $this->distance; $matrix = $this->matrix; $matrix_width = count($matrix); $matrix_sum = array_sum($matrix); $c = 0; $m_offset = floor($matrix_width / 2); $temp = new Image_Image(); $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->imagesx(); $h = $temp->imagesy(); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { $t = $temp->imagecolorat($x, $y); $t1 = Image_Image::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->imagesx(); $h = $this->_owner->imagesy(); $d_offset = $distance - $matrix_width; if ($this->color != "image") { $arrColor = $this->_owner->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; }
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/flowers.jpg'); $image->attach(new Image_Fx_Resize(196)); $image->attach(new Image_Fx_Crop(0, 100)); $image->attach(new Image_Fx_Sobel()); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/field.jpg'); $image->attach(new Image_Fx_Resize(200)); $image->attach(new Image_Fx_Crop(0, 90)); $image->attach(new Image_Fx_Ripple()); $image->attach(new Image_Fx_Corners(13, 13)); $image->attach(new Image_Draw_Border(5, "FFFFFF")); $image->attach(new Image_Fx_Corners(15, 15)); $image->imagePng();
public function testPluginGaussian() { $image = new Image_Image(); $this->assertEquals($image->attach(new image_fx_gaussian()), true); }
public function testPluginBorder() { $image = new Image_Image(); $this->assertEquals($image->attach(new Image_Draw_Border()), true); }
public function testPluginFilter() { $image = new Image_Image(); $this->assertEquals($image->attach(new Image_Fx_Filter()), true); }
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(250, 100); $image->attach(new Image_Draw_QRCode("http://code.google.com/p/php5-image/")); $image->imagePng();
public function generate() { imagesavealpha($this->_owner->image, true); imagealphablending($this->_owner->image, false); $image_x = $this->_owner->imagesx(); $image_y = $this->_owner->imagesy(); $gdCorner = imagecreatefromstring(base64_decode($this->_cornerpng())); $corner = new Image_Image(); $corner->createImageTrueColorTransparent($this->radius_x, $this->radius_y); imagecopyresampled($corner->image, $gdCorner, 0, 0, 0, 0, $this->radius_x, $this->radius_y, imagesx($gdCorner), imagesy($gdCorner)); $corner_x = $this->radius_x - 1; $corner_y = $this->radius_y - 1; for ($y = 0; $y < $corner_y; $y++) { for ($x = 0; $x < $corner_x; $x++) { for ($c = 0; $c < 4; $c++) { switch ($c) { case 0: $xo = 0; $yo = 0; $cxo = $x; $cyo = $y; break; case 1: $xo = $image_x - $corner_x; $yo = 0; $cxo = $corner_x - $x; $cyo = $y; break; case 2: $xo = $image_x - $corner_x; $yo = $image_y - $corner_y; $cxo = $corner_x - $x; $cyo = $corner_y - $y; break; case 3: $xo = 0; $yo = $image_y - $corner_y; $cxo = $x; $cyo = $corner_y - $y; break; } $irgb = imagecolorat($this->_owner->image, $xo + $x, $yo + $y); $r = $irgb >> 16 & 0xff; $g = $irgb >> 8 & 0xff; $b = $irgb & 0xff; $crgb = imagecolorat($corner->image, $cxo, $cyo); $a = $crgb >> 24 & 0xff; $colour = imagecolorallocatealpha($this->_owner->image, $r, $g, $b, $a); switch ($c) { case 0: imagesetpixel($this->_owner->image, $x, $y, $colour); break; case 1: imagesetpixel($this->_owner->image, $xo + $x, $y, $colour); break; case 2: imagesetpixel($this->_owner->image, $xo + $x, $yo + $y, $colour); break; case 3: imagesetpixel($this->_owner->image, $x, $yo + $y, $colour); break; } } } } }
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/icecream.jpg'); $image->attach(new Image_Fx_Resize(196)); $image->attach(new Image_Fx_Crop(166, 70)); $image->attach(new Image_Fx_Corners(15, 15)); $image->attach(new Image_Draw_Border(5, "FF0000")); $image->attach(new Image_Fx_Corners(17, 17)); $image->attach(new Image_Draw_Border(5, "FF8888")); $image->attach(new Image_Fx_Corners(20, 20)); $image->attach(new Image_Draw_Border(5, "FFCCCC")); $image->attach(new Image_Fx_Corners(22, 22)); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/face.jpg'); $image->attach(new Image_Fx_Resize(198)); $image->attach(new Image_Fx_Crop(194, 94)); $image->attach(new Image_Fx_Filter(IMG_FILTER_NEGATE)); $image->attach(new Image_Draw_Border(1, "FFFFFF")); $image->attach(new Image_Draw_Border(1, "BBBBBB")); $image->attach(new Image_Draw_Border(1, "FFFFFF")); $image->imagePng();
public function testPluginWatermark() { $image = new Image_Image(); $this->assertEquals($image->attach(new Image_Draw_Watermark()), true); }
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/balloons.jpg'); $image->attach(new Image_Fx_Resize(250)); $image->attach(new Image_Fx_Crop(206, 100)); $image->attach(new Image_Fx_Vignette(new Image_Image(dirname(__FILE__) . '/source/vignette.png'))); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(); $image->createImageTrueColorTransparent(192, 96); $image->attach(new Image_Fx_Canvassize(0, 0, 0, 0, "FFFFFF")); $image->attach(new Image_Draw_Border(1, "BBBBBB")); $image->attach(new Image_Draw_Border(1, "FFFFFF")); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/planes.jpg'); $image->attach(new Image_Fx_Resize(250)); $image->attach(new Image_Fx_Crop(206, 96)); $image->attach(new Image_Fx_Jitter()); $image->attach(new Image_Draw_Border(1, "BBBBBB")); $image->attach(new Image_Draw_Border(1, "FFFFFF")); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(); $image->createImageTrueColor(206, 96, "FF0000"); //Primitives $background = new Image_Draw_Primitive("FFFFFF", 20); $background->addLine(20, 20, 80, 80); $background->addRectangle(100, 20, 180, 80); $background->addFilledRectangle(150, 10, 170, 30); $background->addEllipse(10, 50, 20, 60); $background->addFilledEllipse(140, 60, 160, 80); $background->addCircle(200, 50, 30); $background->addSpiral(100, 50, 100, 10); $image->attach($background); //Captcha text $captcha = new Image_Draw_Captcha("captcha"); $captcha->addTTFFont(dirname(__FILE__) . '/../fonts/blambotcustom.ttf'); $captcha->addTTFFont(dirname(__FILE__) . '/../fonts/adventure.ttf'); $captcha->addTTFFont(dirname(__FILE__) . '/../fonts/bluehigh.ttf'); $captcha->setTextSize(20)->setSizeRandom(20)->setAngleRandom(60)->setTextSpacing(5)->setTextColor("ffff00"); $image->attach($captcha); //Add a border $image->attach(new Image_Draw_Border(1, "BBBBBB")); $image->attach(new Image_Draw_Border(1, "FFFFFF")); $image->imagePng();
public function testPluginJitter() { $image = new Image_Image(); $this->assertEquals($image->attach(new image_fx_jitter()), true); }
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/beach.jpg'); $image->attach(new Image_Fx_Resize(200)); $image->attach(new Image_Fx_Crop(0, 86)); $image->attach(new Image_Draw_Border(2, "000000")); $image->attach(new Image_Fx_Canvassize(0, 10, 10, 0)); $watermark = new Image_Draw_Watermark(new Image_Image(dirname(__FILE__) . '/source/button.png')); $watermark->setPosition("br"); $image->attach($watermark); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/stamens.jpg'); $image->attach(new Image_Fx_Resize(196)); $image->attach(new Image_Fx_Crop(0, 96)); $watermark = new Image_Draw_Watermark(new Image_Image(dirname(__FILE__) . '/source/watermark.png')); $watermark->setPosition("tile"); $image->attach($watermark); $image->attach(new Image_Draw_Border(2, "000000")); $image->imagePng();
<?php require_once dirname(__FILE__) . '/bootstrap.php'; $image = new Image_Image(dirname(__FILE__) . '/source/portrait.jpg'); $image->attach(new Image_Fx_Resize(198)); $image->attach(new Image_Fx_Crop(196, 96)); $image->attach(new Image_Helper_FaceDetector()); $image->evaluateFXStack()->drawFaceRectangle(); $image->imagePng();