Exemple #1
0
 public function addBackground($canvas, $bgImage, $bgWidth, $bgHeight, $bgOriginX, $bgOriginY)
 {
     $background = imagecreatetruecolor($bgWidth, $bgHeight);
     imagesettile($background, $bgImage);
     imagefill($background, 0, 0, IMG_COLOR_TILED);
     imagecopy($canvas, $background, $bgOriginX, $bgOriginY, 0, 0, $bgWidth, $bgHeight);
 }
 /**
  * {@inheritdoc}
  */
 public function apply(CanvasInterface $canvas, AbstractStyledDrawable $drawable)
 {
     if (false == @imagesettile($canvas->getHandler(), $this->pattern->getHandler())) {
         throw new DrawableException('Could Not Apply The Fill Pattern Style');
     }
     return new TiledColor();
 }
Exemple #3
0
 public function index()
 {
     //	Check the request headers; avoid hitting the disk at all if possible. If the Etag
     //	matches then send a Not-Modified header and terminate execution.
     if ($this->_serve_not_modified($this->_cache_file)) {
         return;
     }
     // --------------------------------------------------------------------------
     //	The browser does not have a local cache (or it's out of date) check the
     //	cache directory to see if this image has been processed already; serve it up if
     //	it has.
     if (file_exists(DEPLOY_CACHE_DIR . $this->_cache_file)) {
         $this->_serve_from_cache($this->_cache_file);
     } else {
         //	Cache object does not exist, create a new one and cache it
         //	Get and create the placeholder graphic
         $_tile = imagecreatefrompng($this->_tile);
         // --------------------------------------------------------------------------
         //	Create the container
         $_img = imagecreatetruecolor($this->_width, $this->_height);
         // --------------------------------------------------------------------------
         //	Tile the placeholder
         imagesettile($_img, $_tile);
         imagefilledrectangle($_img, 0, 0, $this->_width, $this->_height, IMG_COLOR_TILED);
         // --------------------------------------------------------------------------
         //	Draw a border
         $_border = imagecolorallocate($_img, 190, 190, 190);
         for ($i = 0; $i < $this->_border; $i++) {
             //	Left
             imageline($_img, 0 + $i, 0, 0 + $i, $this->_height, $_border);
             //	Top
             imageline($_img, 0, 0 + $i, $this->_width, 0 + $i, $_border);
             //	Bottom
             imageline($_img, 0, $this->_height - 1 - $i, $this->_width, $this->_height - 1 - $i, $_border);
             //	Right
             imageline($_img, $this->_width - 1 - $i, 0, $this->_width - 1 - $i, $this->_height, $_border);
         }
         // --------------------------------------------------------------------------
         //	Set the appropriate cache headers
         $this->_set_cache_headers(time(), $this->_cache_file, FALSE);
         // --------------------------------------------------------------------------
         //	Output to browser
         header('Content-Type: image/png', TRUE);
         imagepng($_img);
         // --------------------------------------------------------------------------
         //	Save local version, make sure cache is writable
         imagepng($_img, DEPLOY_CACHE_DIR . $this->_cache_file);
         // --------------------------------------------------------------------------
         //	Destroy the images to free up resource
         imagedestroy($_tile);
         imagedestroy($_img);
     }
     // --------------------------------------------------------------------------
     //	Kill script, th, th, that's all folks.
     //	Stop the output class from hijacking our headers and
     //	setting an incorrect Content-Type
     exit(0);
 }
Exemple #4
0
 public function apply($resource)
 {
     $imageWidth = imagesx($resource->image);
     $imageHeight = imagesy($resource->image);
     $width = $imageWidth * $this->settings->xtimes;
     $height = $imageHeight * $this->settings->xtimes;
     $new = imagecreatetruecolor($width, $height);
     imagesettile($new, $resource->image);
     imagefill($new, 0, 0, IMG_COLOR_TILED);
     $resource->image = $new;
 }
Exemple #5
0
 /**
  * Fills image with color or pattern
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $filling = $this->argument(0)->value();
     $x = $this->argument(1)->type('digit')->value();
     $y = $this->argument(2)->type('digit')->value();
     $width = imagesx($image->getCore());
     $height = imagesy($image->getCore());
     try {
         // set image tile filling
         $tile = $image->getDriver()->init($filling);
     } catch (\Intervention\Image\Exception\NotReadableException $e) {
         // set solid color filling
         $color = new Color($filling);
         $filling = $color->getInt();
     }
     foreach ($image as $frame) {
         if (isset($tile)) {
             imagesettile($frame->getCore(), $tile->getCore());
             $filling = IMG_COLOR_TILED;
         }
         imagealphablending($frame->getCore(), true);
         if (is_int($x) && is_int($y)) {
             // resource should be visible through transparency
             $base = $image->getDriver()->newImage($width, $height)->getCore();
             imagecopy($base, $frame->getCore(), 0, 0, 0, 0, $width, $height);
             // floodfill if exact position is defined
             imagefill($frame->getCore(), $x, $y, $filling);
             // copy filled original over base
             imagecopy($base, $frame->getCore(), 0, 0, 0, 0, $width, $height);
             // set base as new resource-core
             imagedestroy($frame->getCore());
             $frame->setCore($base);
         } else {
             // fill whole image otherwise
             imagefilledrectangle($frame->getCore(), 0, 0, $width - 1, $height - 1, $filling);
         }
     }
     isset($tile) ? imagedestroy($tile->getCore()) : null;
     return true;
 }
Exemple #6
0
 public function generate()
 {
     imagesavealpha($this->_owner->image, true);
     imagealphablending($this->_owner->image, true);
     imagesavealpha($this->watermark->image, false);
     imagealphablending($this->watermark->image, false);
     $width = $this->_owner->imagesx();
     $height = $this->_owner->imagesy();
     $watermark_width = $this->watermark->imagesx();
     $watermark_height = $this->watermark->imagesy();
     switch ($this->position) {
         case "tl":
             $x = 0;
             $y = 0;
             break;
         case "tm":
             $x = ($width - $watermark_width) / 2;
             $y = 0;
             break;
         case "tr":
             $x = $width - $watermark_width;
             $y = 0;
             break;
         case "ml":
             $x = 0;
             $y = ($height - $watermark_height) / 2;
             break;
         case "mm":
             $x = ($width - $watermark_width) / 2;
             $y = ($height - $watermark_height) / 2;
             break;
         case "mr":
             $x = $width - $watermark_width;
             $y = ($height - $watermark_height) / 2;
             break;
         case "bl":
             $x = 0;
             $y = $height - $watermark_height;
             break;
         case "bm":
             $x = ($width - $watermark_width) / 2;
             $y = $height - $watermark_height;
             break;
         case "br":
             $x = $width - $watermark_width;
             $y = $height - $watermark_height;
             break;
         case "user":
             $x = $this->position_x - $this->watermark->getHandleX() / 2;
             $y = $this->position_y - $this->watermark->getHandleY() / 2;
             break;
         default:
             $x = 0;
             $y = 0;
             break;
     }
     if ($this->position != "tile") {
         imagecopy($this->_owner->image, $this->watermark->image, $x, $y, 0, 0, $watermark_width, $watermark_height);
     } else {
         imagesettile($this->_owner->image, $this->watermark->image);
         imagefilledrectangle($this->_owner->image, 0, 0, $width, $height, IMG_COLOR_TILED);
     }
     return true;
 }
 function show_surface()
 {
     if (sizeof($this->valori) > 0) {
         $series = $this->values;
         $single = true;
         $culori = $this->culori;
         $categories = explode(",", $this->categories);
         $pozitii = array();
         $catego = array();
         $xmax = 0;
         $xmin = 0;
         $ymax = 0;
         $ymin = 0;
         $sil = explode(";", $series);
         $gx = $this->width * 0.06;
         if (strlen($this->title) <= 0) {
             $gy = $this->height * 0.03;
         } else {
             $gy = $this->height * 0.12;
         }
         if (strlen($this->text) > 0) {
             if ($this->showpanel) {
                 $gyy = $this->height / 2 + (10 - sizeof($sil)) * $this->fontsize / 1 * 1.4;
             } else {
                 $gyy = $this->height * 0.75;
             }
         } elseif ($this->showpanel) {
             $gyy = $this->height / 2 + (10 - sizeof($sil)) * $this->fontsize / 1 * 1.4;
         } else {
             $gyy = $this->height * 0.92;
         }
         if ($this->showcoords == true) {
             $gxx = $this->width * 0.92;
         } else {
             $gxx = $this->width * 0.98;
         }
         $gdify = $gyy - $gy;
         $gdifx = $gxx - $gx;
         $pos = 0;
         $sir = explode(";", $series);
         foreach ($sir as $element) {
             $sir1 = explode("=", $element);
             $catego[] = $sir1[0];
             $restulc = $sir1[1];
             $valoriy = $this->doary($restulc);
             $valorix = $this->doarx($restulc);
             if (sizeof($valoriy) == sizeof($valorix)) {
                 $single = false;
             } else {
                 $valorix = $this->baga_coordonate_suplimentare($valorix, $valoriy, $gx, $gdifx, sizeof($valoriy));
             }
             if (sizeof($valoriy) < $this->maxcount) {
                 $this->count = sizeof($valoriy);
             } else {
                 $this->count = $this->maxcount;
                 $valoriy = $this->forteaza_numar_valoriy($valoriy);
                 $valorix = $this->forteaza_numar_valorix($valorix, $valoriy);
             }
             $vx[] = $valorix;
             $vy[] = $valoriy;
             $numarari[] = $this->count;
             foreach ($valoriy as $valoarey) {
                 $ymax = max($ymax, $valoarey);
                 $ymin = min($ymin, $valoarey);
             }
             foreach ($valorix as $valoarex) {
                 $xmax = max($xmax, $valoarex);
                 $xmin = min($xmin, $valoarex);
             }
         }
         $po = 0;
         foreach ($vx as $valorix) {
             $cate2 = sizeof($catego);
             $dif = $ymax - $ymin;
             $difm = abs($ymax) + abs($ymin);
             $dmax = $ymax * $difm / $gdify;
             $dmin = $ymin * $difm / $gdify;
             $difx = $xmax - $xmin;
             $difmx = abs($xmax) + abs($xmin);
             $dmaxx = $xmax * $difmx / $gdifx;
             $dminx = $xmin * $difmx / $gdifx;
             $valoriy = $vy[$po];
             $this->count = $numarari[$po];
             $po++;
             $cordx = $this->pixel_up(0, $difmx, $gdifx, $xmin) + $gx;
             $cordy = $gyy - $this->pixel_up(0, $difm, $gdify, $ymin);
             if ($this->yaxiswidth > 0 && $xmin * $xmax <= 0) {
                 $this->linie($this->imagine, $cordx, $gy * 0.6, $cordx, $gyy, $this->yaxiswidth, "brown-peach", 1);
             }
             if ($this->xaxiswidth > 0 && $ymin * $ymax < 0) {
                 $coordy = $gyy - $this->pixel_up(0, $difm, $gdify, $ymin);
                 $this->linie($this->imagine, $gx * 0.6, $coordy, $gxx, $coordy, $this->xaxiswidth, "brown-peach", 1);
             }
             if ($this->showlinecoords) {
                 for ($j = 0; $j < $this->count; $j++) {
                     $coordy = $gyy - $this->pixel_up($valoriy[$j], $difm, $gdify, $ymin);
                     $coordx = $this->pixel_up($valorix[$j], $difmx, $gdifx, $xmin) + $gx;
                     $this->linie($this->imagine, $cordx, $coordy, $coordx, $coordy, 1, "lightgray2", 1);
                     $this->linie($this->imagine, $coordx, $coordy, $coordx, $cordy, 1, "lightgray2", 1);
                 }
             }
             if ($this->showgrid) {
                 $mmin = abs($ymin);
                 $mmax = abs($ymax);
                 $max1 = floor(log10($mmax));
                 $min1 = floor(log10($mmin));
                 if (abs($ymax) >= abs($ymin)) {
                     $pana_la_max = floor($mmax / pow(10, $max1));
                     $pana_la_min = floor($mmin / pow(10, $max1));
                 } else {
                     $pana_la_max = floor($mmax / pow(10, $min1));
                     $pana_la_min = floor($mmin / pow(10, $min1));
                 }
                 for ($k = 0; $k < $pana_la_max; $k++) {
                     $valu = ($k + 1) * pow(10, $max1);
                     $gly = $this->pixel_up($valu, $difm, $gdify, $ymin);
                     $this->linie($this->imagine, $gx * 0.6, $gyy - $gly, $gxx, $gyy - $gly, 1, "lightgray2", 1);
                     imagefttext($this->imagine, $this->fontsize * 0.65 + 3, 0, $gx * 0.2, $gyy - $gly + $this->fontsize / 2, $this->bc($this->imagine, "darkgray"), $this->font, $valu);
                 }
                 for ($k = 0; $k <= $pana_la_min; $k++) {
                     $valu = -1 * $k * pow(10, $min1);
                     $gly = $this->pixel_up($valu, $difm, $gdify, $ymin);
                     $this->linie($this->imagine, $gx * 0.6, $gyy - $gly, $gxx, $gyy - $gly, 1, "lightgray2", 1);
                     imagefttext($this->imagine, $this->fontsize * 0.65 + 3, 0, $gx * 0.12, $gyy - $gly + $this->fontsize / 3, $this->bc($this->imagine, "darkgray"), $this->font, $valu);
                 }
                 $mmin = abs($xmin);
                 $mmax = abs($xmax);
                 $max1 = floor(log10($mmax));
                 $min1 = floor(log10($mmin));
                 if (abs($xmax) >= abs($xmin)) {
                     $pana_la_max = floor($mmax / pow(10, $max1));
                     $pana_la_min = floor($mmin / pow(10, $max1));
                 } else {
                     $pana_la_max = floor($mmax / pow(10, $min1));
                     $pana_la_min = floor($mmin / pow(10, $min1));
                 }
                 for ($k = 0; $k < $pana_la_max; $k++) {
                     $valu = ($k + 1) * pow(10, $max1);
                     $glx = $this->pixel_up($valu, $difmx, $gdifx, $xmin) + $gx;
                     $this->linie($this->imagine, $glx, $gy, $glx, $gyy, 1, "lightgray2", 1);
                     imagefttext($this->imagine, $this->fontsize * 0.65 + 3, 0, $glx - $this->fontsize * 0.8, $gyy + $this->fontsize * 1.6, $this->bc($this->imagine, "darkgray"), $this->font, $valu);
                 }
                 for ($k = 0; $k <= $pana_la_min; $k++) {
                     $valu = -1 * $k * pow(10, $min1);
                     $glx = $this->pixel_up($valu, $difmx, $gdifx, $xmin) + $gx;
                     $this->linie($this->imagine, $glx, $gy, $glx, $gyy, 1, "lightgray2", 1);
                     imagefttext($this->imagine, $this->fontsize * 0.65 + 3, 0, $glx - $this->fontsize * 0.8, $gyy + $this->fontsize * 1.6, $this->bc($this->imagine, "darkgray"), $this->font, $valu);
                 }
             }
         }
         $po = 0;
         foreach ($vx as $valorix) {
             $valoriy = $vy[$po];
             $this->count = $numarari[$po];
             $po++;
             $cate2 = sizeof($catego);
             $dif = $ymax - $ymin;
             $difm = abs($ymax) + abs($ymin);
             $dmax = $ymax * $difm / $gdify;
             $dmin = $ymin * $difm / $gdify;
             $difx = $xmax - $xmin;
             $difmx = abs($xmax) + abs($xmin);
             $dmaxx = $xmax * $difmx / $gdifx;
             $dminx = $xmin * $difmx / $gdifx;
             $poz = array();
             $olx = $this->pixel_up($valorix[0], $difmx, $gdifx, $xmin) + $gx;
             $oly = $this->pixel_up($valoriy[0], $difm, $gdify, $ymin);
             $oly0 = $this->pixel_up(0, $difm, $gdify, $ymin);
             $poz[] = $olx;
             $poz[] = $gyy - $oly0;
             $poz[] = $olx;
             $poz[] = $gyy - $oly;
             if ($single == false) {
                 $pozitii[$pos][0] = array($olx, $gyy - $oly, ${$olx}, $gyy - $oly, $valorix[0] . "," . $valoriy[0]);
             } else {
                 $pozitii[$pos][0] = array($olx, $gyy - $oly, ${$olx}, $gyy - $oly, $valoriy[0]);
             }
             for ($j = 1; $j < $this->count; $j++) {
                 $lx = $this->pixel_up($valorix[$j], $difmx, $gdifx, $xmin) + $gx;
                 $ly = $this->pixel_up($valoriy[$j], $difm, $gdify, $ymin);
                 $poz[] = $lx;
                 $poz[] = $gyy - $ly;
                 if ($single == false) {
                     $textul = $valorix[$j] . "," . $valoriy[$j];
                 } else {
                     $textul = $valoriy[$j];
                 }
                 $pozitii[$pos][$j] = array($lx, $gyy - $ly, $olx, $gyy - $oly, $textul);
                 $olx = $lx;
                 $oly = $ly;
                 $i++;
             }
             $poz[] = $lx;
             $poz[] = $gyy - $oly0;
             if ($this->acolors[$pos][1] == 0) {
                 imagefilledpolygon($this->imagine, $poz, sizeof($poz) / 2, $this->acolors[$pos][0]);
             } else {
                 imagesettile($this->imagine, $this->acolors[$pos][0]);
                 imagefilledpolygon($this->imagine, $poz, sizeof($poz) / 2, IMG_COLOR_TILED);
             }
             if ($this->showcoords) {
                 foreach ($pozitii as $line) {
                     foreach ($line as $lin) {
                         $this->pune_indice($this->imagine, $lin[0], $lin[1], $lin[2], $lin[3], $lin[4]);
                     }
                 }
             }
             $k++;
             $pos++;
         }
         if ($single == true && $this->count > 1 && $this->count / ($this->fonstsize + 1) < 10) {
             if ($this->count > 2) {
                 $pana = min($this->count, sizeof($categories));
             } else {
                 $pana = min($this->count, sizeof($categories)) - 1;
             }
             for ($j = 0; $j < $pana; $j++) {
                 $lx = ($this->pixel_up($valorix[$j], $difmx, $gdifx, $xmin) + $this->pixel_up($valorix[$j + 1], $difmx, $gdifx, $xmin)) / 2 + $gx - $this->fontsize * strlen($categories[$j]) / 3.3;
                 imagefttext($this->imagine, $this->fontsize * 0.8, 0, $lx, $gyy + $this->fontsize * 1.5, $this->bc($this->imagine, "darkgray"), $this->font, $categories[$j]);
             }
         }
         if ($this->showpanel) {
             $px = $gx * 0.8;
             $pxx = $gxx * 1;
             $py = $gyy * 1.06;
             $pyy = $gyy * 1.5;
             $rand = $this->fontsize * 0.8;
             $cc = sizeof($pozitii);
             $bordura = "white-brown";
             for ($i = 0; $i < $cc; $i++) {
                 $diferenta = $py * 1.02 - $py;
                 $this->liniuta($this->imagine, $px, $py + $i * $rand + $i * $diferenta, $px * 3, $py + $i * $rand + ($i + 1) * $diferenta, $this->linewidth, $culori[$i], $i);
                 imagefttext($this->imagine, $rand, 0, $px * 3 - $rand / 3, $py + $i * $rand + $rand / 1.5 + ($i + 1) * $diferenta, $this->black, $this->font, $catego[$i]);
             }
             $ttx = $this->width * 0.28;
             $tty = $gyy * 1.12;
             $cate = ($gxx - $ttx) / $this->fontsize * 1.5;
         } else {
             $ttx = $this->width * 0.02;
             $tty = $gyy * 1.12;
             $cate = ($gxx - $ttx) / $this->fontsize * 1.5;
         }
         if (strlen($this->title) > 0) {
             $tlx = $this->width / 2 - strlen($this->title) * $this->fontsize / 2.5;
             $tly = $this->height * 0.04 + 3;
             imagefttext($this->imagine, $this->fontsize + 3, 0, $tlx, $tly, $this->bc($this->imagine, $this->title_color), $this->font, $this->title);
         }
         if (strlen($this->text) > 0) {
             $textul = array();
             for ($i = 1; $i <= $cate; $i++) {
                 $textul[] = nl2br(substr($this->text, floor(($i - 1) * $cate), ceil($cate)));
             }
             $i = 0;
             foreach ($textul as $linie) {
                 imagefttext($this->imagine, $this->fontsize - 1, 0, $ttx, $tty + $i, $this->bc($this->imagine, $this->text_color), $this->font, $linie);
                 $i += $this->fontsize + 1;
             }
         }
         $this->set_filter();
     } else {
         echo "not enought values";
     }
 }
Exemple #8
0
    case 4:
        $col_txt = ImageColorAllocate($im, $col_txt_r, $col_txt_g, $col_txt_b);
        break;
}
$noiset = mt_rand(1, 2);
$image_data = getimagesize($im_bg_url);
$image_type = $image_data[2];
if ($image_type == 1) {
    $img_src = imagecreatefromgif($im_bg_url);
} elseif ($image_type == 2) {
    $img_src = imagecreatefromjpeg($im_bg_url);
} elseif ($image_type == 3) {
    $img_src = imagecreatefrompng($im_bg_url);
}
if ($im_bg_type == 1) {
    imagesettile($im, $img_src);
    imageFilledRectangle($im, 0, 0, $image_width, $image_height, IMG_COLOR_TILED);
} else {
    imagecopyresampled($im, $img_src, 0, 0, 0, 0, $image_width, $image_height, $image_data[0], $image_data[1]);
}
$pos_x = ($image_width - $codelen) / 2;
foreach ($data as $d) {
    $pos_y = ($image_height + $d['height']) / 2;
    ImageTTFText($im, $d['size'], $d['angle'], $pos_x, $pos_y, $col_txt, $font, $d['char']);
    $pos_x += $d['width'] + $char_padding;
}
### a nice border
ImageRectangle($im, 0, 0, $image_width - 1, $image_height - 1, $color_border);
switch ($output_type) {
    case 'jpeg':
        Header('Content-type: image/jpeg');
Exemple #9
0
 static function set(&$image, $value, $method)
 {
     if ($method == 'border') {
         //画线粗细
         return imagesetthickness($image, (int) $value);
     }
     if ($method == 'style') {
         //画线风格
         return imagesetstyle($image, (array) $value);
     }
     if ($method == 'brush') {
         //画笔图像
         return imagesetbrush($image, $value);
     }
     if ($method == 'pattern') {
         //填充的贴图 图案
         return imagesettile($image, $value);
     }
     if ($method == 'alias') {
         //抗锯齿
         return imageantialias($image, (bool) $value);
     }
     if ($method == 'alpha') {
         //alpha混色标志
         return imagelayereffect($image, (int) $value);
     }
     if ($method == 'transparent') {
         //透明色
         return imagecolortransparent($image, (int) $value);
     }
     if ($method == 'mix') {
         //混色模式
         return imagealphablending($image, (bool) $value);
     }
 }
 /**
  * Creates a captcha image.
  *
  */
 private function createImage()
 {
     $intWidth = $this->intImageWidth;
     $intHeight = $intWidth / 3;
     $intFontSize = floor($intWidth / strlen($this->strRandomString)) - 2;
     $intAngel = 15;
     $intVerticalMove = floor($intHeight / 7);
     $image = imagecreatetruecolor($intWidth, $intHeight);
     $arrFontColors = array(imagecolorallocate($image, 0, 0, 0), imagecolorallocate($image, 255, 0, 0), imagecolorallocate($image, 0, 180, 0), imagecolorallocate($image, 0, 105, 172), imagecolorallocate($image, 145, 19, 120));
     $arrFonts = array($this->strFontDir . 'coprgtb.ttf', $this->strFontDir . 'ltypeb.ttf');
     //Draw background
     $imagebg = imagecreatefromjpeg($this->strBackgroundDir . rand(1, $this->intNumberOfBackgrounds) . '.jpg');
     imagesettile($image, $imagebg);
     imagefilledrectangle($image, 0, 0, $intWidth, $intHeight, IMG_COLOR_TILED);
     //Draw string
     for ($i = 0; $i < strlen($this->strRandomString); ++$i) {
         $intColor = rand(0, count($arrFontColors) - 1);
         $intFont = rand(0, count($arrFonts) - 1);
         $intAngel = rand(-$intAngel, $intAngel);
         $intYMove = rand(-$intVerticalMove, $intVerticalMove);
         if ($this->boolFreetypeInstalled) {
             imagettftext($image, $intFontSize, $intAngel, 6 + $intFontSize * $i, $intHeight / 2 + $intFontSize / 2 + $intYMove, $arrFontColors[$intColor], $arrFonts[$intFont], substr($this->strRandomString, $i, 1));
         } else {
             imagestring($image, 5, 6 + 25 * $i, 12 + $intYMove, substr($this->strRandomString, $i, 1), $arrFontColors[$intColor]);
         }
     }
     //save the image for further processing
     $this->image = $image;
 }
 public function tile($tile) : InternalGD
 {
     if (!is_resource($tile)) {
         throw new InvalidArgumentException('Error', 'resourceParameter', '1.($tile)');
     }
     imagesettile($this->canvas, $tile);
     return $this;
 }
Exemple #12
0
 /**
  * Rellena la imagen con un patrón
  * @param  resource $tile Identificador de recurso de imagen de la imagen patrón
  */
 public function fillPattern($tile)
 {
     if (!imagesettile($this->imgData, $tile)) {
         throw new Exception("imagesettile error", 1);
     }
     imagefilledrectangle($this->imgData, 0, 0, $this->width(), $this->height(), IMG_COLOR_TILED);
     //$this->imgData=$tile;
 }
Exemple #13
0
	$imbg = imageCreateFromPNG ('tile.png'); // Alpha-transparent PNG
	
	$black = imagecolorallocate($im,   0,   0,   0);
	$white = imagecolorallocate($im, 255, 255, 255);
	$red   = imagecolorallocate($im, 255,   0,   0);
	$green = imagecolorallocate($im,   0, 128,   0);
	
	imagestring ($im, 3, 60+$x*4, 40, $nome, $green);
	imagestring ($im, 3, 59+$x*4, 39, $nome, $white);
	
	imageline  ($im, 0, 20+$x*8, 400, 40+$x*-2,      $green);
	imagestring($im, 3, 30,       50, microtime(),   $white);
	imagestring($im, 3, 35,       60, "X: $x",       $white);
	imagestring($im, 3, 105,      60, date("H:i:s"), $red);
   
	imagesettile ($im, $imbg);
	imagefilledrectangle ($im, 0, 0, 400, 200, IMG_COLOR_TILED);
	
	$randFilename = "tempFolder/".uniqid("$x-").".gif";
	$generated[] = $randFilename;
	imagegif($im, $randFilename);
}
$genEndTime = microtime(true);

$startTime = microtime(true);
/** Instantiate the class to join all the frames into one single GIF **/
$gif = new dGifAnimator();
$gif->setLoop(0);                         # Loop forever
$gif->setDefaultConfig('delay_ms', '10'); # Delay: 10ms
if(isset($_GET['transparent']))
	$gif->setDefaultConfig('transparent_color', 0);
 private function createTextWatermark($w, $h)
 {
     $font = $this->fw->get('ROOT') . '/../' . APP_FOLDER . '/views/' . $this->fw->get('site.tpl') . '/assets/fonts/' . $this->fw->get('site.watermark.font');
     //		\helpers\Debug::prePrintR($font);
     $text = $this->fw->get('site.watermark.text');
     $color = $this->fw->get('site.watermark.color');
     //		$hexcolor = $this->hexToPHPColor($this->fw->get('site.watermark.color'));
     $x = $this->fw->get('site.watermark.x');
     $y = $this->fw->get('site.watermark.y');
     $size = $this->fw->get('site.watermark.size');
     $angle = $this->fw->get('site.watermark.angle');
     if (is_string($x) || is_string($y)) {
         $textsize = imagettfbbox($size, $angle, $font, $text);
         $textwidth = abs($textsize[2]);
         $textheight = abs($textsize[7]);
         list($xalign, $xalign_offset) = explode(" ", $x);
         list($yalign, $yalign_offset) = explode(" ", $y);
     }
     if (is_string($x)) {
         switch ($xalign) {
             case 'left':
                 $x = 0 + $xalign_offset;
                 break;
             case 'right':
                 $x = $w - $textwidth + $xalign_offset;
                 break;
             case 'middle':
             case 'center':
                 $x = ($w - $textwidth) / 2 + $xalign_offset;
                 break;
         }
     }
     if (is_string($y)) {
         switch ($yalign) {
             case 'top':
                 $y = 0 + $textheight + $yalign_offset;
                 break;
             case 'bottom':
                 $y = $h + $yalign_offset;
                 break;
             case 'middle':
             case 'center':
                 $y = ($h - $textheight) / 2 + $textheight + $yalign_offset;
                 break;
         }
     }
     $img = imagecreatetruecolor($w, $h);
     imagefill($img, 0, 0, IMG_COLOR_TRANSPARENT);
     if ($this->fw->get('site.watermark.tile')) {
         $tile = imagecreatetruecolor($textwidth * 4, $textwidth * 4);
         imagefill($tile, 0, 0, IMG_COLOR_TRANSPARENT);
         $color_id = imagecolorallocate($tile, $color[0], $color[1], $color[2]);
         imagettftext($tile, $size, $angle, $textwidth, $textwidth * 2, $color_id, $font, $text);
         imagesettile($img, $tile);
         imagefilledrectangle($img, 0, 0, $w - 1, $h - 1, IMG_COLOR_TILED);
         imagedestroy($tile);
     } else {
         $color_id = imagecolorallocate($img, $color[0], $color[1], $color[2]);
         imagettftext($img, $size, $angle, $x, $y, $color_id, $font, $text);
     }
     imagesavealpha($img, true);
     imagepng($img, $this->fw->get('TEMP') . '/watermark.png');
     imagedestroy($img);
     return $this->fw->get('TEMP') . '/watermark.png';
 }
Exemple #15
0
<?php

$tile = imagecreate(36, 36);
$base = imagecreate(150, 150);
$white = imagecolorallocate($tile, 255, 255, 255);
$black = imagecolorallocate($tile, 0, 0, 0);
$white = imagecolorallocate($base, 255, 255, 255);
$black = imagecolorallocate($base, 0, 0, 0);
/* create the dots pattern */
for ($x = 0; $x < 36; $x += 2) {
    for ($y = 0; $y < 36; $y += 2) {
        imagesetpixel($tile, $x, $y, $black);
    }
}
imagesettile($base, $tile);
imagerectangle($base, 9, 9, 139, 139, $black);
imageline($base, 9, 9, 139, 139, $black);
imagefill($base, 11, 12, IMG_COLOR_TILED);
$res = imagecolorat($base, 0, 10) == $black ? '1' : '0';
$res .= imagecolorat($base, 0, 20) == $black ? '1' : '0';
$res .= imagecolorat($base, 0, 30) == $black ? '1' : '0';
$res .= imagecolorat($base, 0, 40) == $black ? '1' : '0';
$res .= imagecolorat($base, 0, 50) == $black ? '1' : '0';
$res .= imagecolorat($base, 0, 60) == $black ? '1' : '0';
$res .= imagecolorat($base, 11, 12) == $white ? '1' : '0';
$res .= imagecolorat($base, 12, 13) == $white ? '1' : '0';
$res .= imagecolorat($base, 13, 14) == $white ? '1' : '0';
$res .= imagecolorat($base, 14, 15) == $white ? '1' : '0';
$res .= imagecolorat($base, 15, 16) == $white ? '1' : '0';
$res .= imagecolorat($base, 16, 17) == $white ? '1' : '0';
$res .= imagecolorat($base, 10, 12) == $black ? '1' : '0';
Exemple #16
0
//Функция imageSetThickness() - задает толщину линии(1-ресурс изображения, 2-толщина линии)
$color = imageColorAllocate($i, 0, 0, 255);
imageRectangle($i, 50, 80, 150, 150, $color);
imageSetThickness($i, 3);
$color = imageColorAllocate($i, 255, 255, 0);
imageLine($i, 10, 10, 350, 250, $color);
//Функция imageLine() - рисует линию по двум точкам (1-ресурс изображения, 2 - х-координата точки 1, 3 - у-координата точки 1, 4 - х-координата точки 2, 5 - у-координата точки 2, 6 - цвет бордера)
$color = imageColorAllocate($i, 255, 255, 255);
imageArc($i, 300, 100, 150, 150, 0, 0, $color);
//Функция imagearc() - рисует окружность дуги с заданными координатами центра, дуга рисуется по часовой стрелке (1-ресурс изображения, 2 - х-координата центра, 3 - у-координата центра, 4 - ширина дуги, 5 - высота дуги, 6 - угол начала дуги в градусах, 7 - угол окончания дуги в градусах, 8 - цвет дуги )
//Функция imagefilledarc() - рисует и заливает окружность дуги с заданными координатами центра, дуга рисуется по часовой стрелке (1-ресурс изображения, 2 - х-координата центра, 3 - у-координата центра, 4 - ширина дуги, 5 - высота дуги, 6 - угол начала дуги в градусах, 7 - угол окончания дуги в градусах, 8 - цвет дуги )
$color = imageColorAllocate($i, 0, 255, 255);
imagefill($i, 130, 130, $color);
//Функция imagefill() - производит заливку, начиная с заданных координат точки (1-ресурс изображения, 2 - х-координата точки, 3 - у-координата точки, 4 - цвет заливки, либо можно указать константу заливки IMG_COLOR_TILED)
$im = imagecreatefromgif("images/image.gif");
imagesettile($i, $im);
//Функция imagesettile() - задает изображение, которое будет использовано в качестве элемента мозаичной заливки (1-ресурс изображения который будут заливать, 2- ресурс изображения для использования мозайчной заливки)
imagefill($i, 250, 50, IMG_COLOR_TILED);
$color = imagecolorallocate($i, 0, 0, 0);
imagepolygon($i, array(50, 250, 100, 250, 120, 280, 80, 350, 50, 250), 5, $color);
//Функция imagepolygon() - рисует многоугольник(1-ресурс изображения, 2 - массив координат вершин{array(x1,y1,x2,y2...)}, 3 - количество вершин точнее указанных точек, 4 - цвет бордера)
//Функция imagefilledpolygon() - рисует закрашенный многоугольник(1-ресурс изображения, 2 - массив координат вершин{array(x1,y1,x2,y2...)}, 3 - количество вершин точнее указанных точек, 4 - цвет заливки)
$color = imagecolorallocate($i, 128, 128, 128);
for ($iter = 0; $iter < 10000; $iter++) {
    $x = mt_rand(0, imageSX($i));
    $y = mt_rand(0, imageSY($i));
    imagesetpixel($i, $x, $y, $color);
    //Функция imagesetpixel() - рисует точку (пиксел) на заданных координатах (1-ресурс изображения, 2 - х-координата точки, 3 - у-координата точки, цвет точки)
}
$color = imagecolorallocate($i, 255, 255, 255);
imagestring($i, 5, 150, 50, "PHP", $color);
Exemple #17
0
 public function createBackground()
 {
     $this->tiles = imagecreatefromjpeg($this->path . '/img/tiles.jpg');
     $this->middle = imagecreatefromjpeg($this->path . '/img/tile_center.jpg');
     $this->background = imagecreatetruecolor($this->sizeX * 20, $this->sizeY * 20);
     imagesettile($this->background, $this->tiles);
     imagefilledrectangle($this->background, 0, 0, $this->sizeX * 20, $this->sizeY * 20, IMG_COLOR_TILED);
     imageCopy($this->background, $this->middle, $this->sizeX * 10 - 5, $this->sizeY * 10 - 5, 0, 0, 10, 10);
 }
    for ($i = 0; $i < $steps; $i++) {
        $r = $s[0] - ($s[0] - $e[0]) / $steps * $i;
        $g = $s[1] - ($s[1] - $e[1]) / $steps * $i;
        $b = $s[2] - ($s[2] - $e[2]) / $steps * $i;
        $color = imagecolorallocate($img, $r, $g, $b);
        imagefilledrectangle($img, $x, $y + $i, $x1, $y + $i + 1, $color);
    }
    return true;
}
$imgWidth = 1920;
$imgHeight = 1080 + floor($argv[1] * 20);
$img = imagecreatetruecolor($imgWidth, $imgHeight);
image_gradientrect($img, 0, 0, $imgWidth, floor($imgHeight * 0.5), $pal['color5'], $pal['color4']);
image_gradientrect($img, 0, ceil($imgHeight * 0.5), $imgWidth, $imgHeight, $pal['color4'], $pal['color3']);
$water_pattern = imagecreatefrompng('assets/botb_bg.png');
imagesettile($img, $water_pattern);
imagefilledrectangle($img, 0, 0, $imgWidth, $imgHeight, IMG_COLOR_TILED);
imagedestroy($water_pattern);
imagepng($img, 'assets/background.png');
imagedestroy($img);
# create BotB logo
$text = 'battleofthebits.org';
$font = './arial-black.ttf';
$size = 160;
$spacing = -20;
function create_color($hex, $img)
{
    $r = hexdec(substr($hex, 0, 2));
    $g = hexdec(substr($hex, 2, 2));
    $b = hexdec(substr($hex, 4, 2));
    return imagecolorallocatealpha($img, $r, $g, $b, 0);
 function generate_image_from_json($json_filename)
 {
     // Load the JSON into an array.
     $pixel_array = json_decode($this->cache_manager($json_filename), TRUE);
     // If the pixel array is empty, bail out of this function.
     if (empty($pixel_array)) {
         return;
     }
     // Calculate the final width & final height
     $width_pixelate = $this->width_resampled * $this->block_size_x;
     $height_pixelate = $this->height_resampled * $this->block_size_y;
     // Set the canvas for the processed image & resample the source image.
     $image_processed = imagecreatetruecolor($width_pixelate, $height_pixelate);
     $background_color = imagecolorallocate($image_processed, 20, 20, 20);
     imagefill($image_processed, 0, 0, IMG_COLOR_TRANSPARENT);
     // Process the pixel_array
     $blocks = array();
     foreach ($pixel_array['pixels'] as $position_y => $pixel_row) {
         $box_y = $position_y * $this->block_size_y;
         foreach ($pixel_row as $position_x => $pixel) {
             $box_x = $position_x * $this->block_size_x;
             $color = imagecolorclosest($image_processed, $pixel['rgba']['red'], $pixel['rgba']['green'], $pixel['rgba']['blue']);
             imagefilledrectangle($image_processed, $box_x, $box_y, $box_x + $this->block_size_x, $box_y + $this->block_size_y, $color);
         }
     }
     // Place a tiled overlay on the image.
     if ($this->row_flip_horizontal) {
         imageflip($image_processed, IMG_FLIP_HORIZONTAL);
     }
     // Apply a gaussian blur.
     if (FALSE) {
         $blur_matrix = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
         imageconvolution($image_processed, $blur_matrix, 16, 0);
     }
     // Process the filename & save the image files.
     if ($this->generate_images) {
         if ($this->overlay_image) {
             // Place a tiled overlay on the image.
             $tiled_overlay = imagecreatefrompng($this->overlay_tile_file);
             imagealphablending($image_processed, true);
             imagesettile($image_processed, $tiled_overlay);
             imagefilledrectangle($image_processed, 0, 0, $width_pixelate, $height_pixelate, IMG_COLOR_TILED);
             imagedestroy($tiled_overlay);
         }
         $image_filenames = array();
         foreach ($this->image_types as $image_type) {
             // If the cache directory doesn’t exist, create it.
             if (!is_dir($this->cache_path[$image_type])) {
                 mkdir($this->cache_path[$image_type], $this->directory_permissions, true);
             }
             // Process the filename & generate the image files.
             $filename = $this->create_filename($this->image_file, $image_type);
             if ($image_type == 'gif' && !file_exists($filename)) {
                 imagegif($image_processed, $filename, $this->image_quality['gif']);
             } else {
                 if ($image_type == 'jpeg' && !file_exists($filename)) {
                     imagejpeg($image_processed, $filename, $this->image_quality['jpeg']);
                 } else {
                     if ($image_type == 'png' && !file_exists($filename)) {
                         imagepng($image_processed, $filename, $this->image_quality['png']);
                     }
                 }
             }
         }
     }
     imagedestroy($image_processed);
 }
 /**
  * Fill image with given color or image source at position x,y
  *
  * @param  mixed   $source
  * @param  integer $pos_x
  * @param  integer $pos_y
  * @return Image
  */
 public function fill($source, $pos_x = null, $pos_y = null)
 {
     if (is_a($source, 'Intervention\\Image\\Image')) {
         // fill with image
         imagesettile($this->resource, $source->resource);
         $source = IMG_COLOR_TILED;
     } elseif ($this->isImageResource($source)) {
         // fill with image resource
         imagesettile($this->resource, $source);
         $source = IMG_COLOR_TILED;
     } elseif (is_string($source) && $this->isBinary($source)) {
         // fill with image from binary string
         $img = new self($source);
         imagesettile($this->resource, $img->resource);
         $source = IMG_COLOR_TILED;
     } elseif (is_string($source) && file_exists(realpath($source))) {
         $img = new self($source);
         imagesettile($this->resource, $img->resource);
         $source = IMG_COLOR_TILED;
     } else {
         // fill with color
         $source = $this->parseColor($source);
     }
     if (is_int($pos_x) && is_int($pos_y)) {
         // floodfill if exact position is defined
         imagefill($this->resource, $pos_x, $pos_y, $source);
     } else {
         // fill whole image otherwise
         imagefilledrectangle($this->resource, 0, 0, $this->width - 1, $this->height - 1, $source);
     }
     return $this;
 }
Exemple #21
0
 static function set($res, $method, $mix)
 {
     if ($method == 1) {
         //画线粗细
         return imagesetthickness($res, (int) $mix);
     }
     if ($method == 2) {
         //画线风格
         return imagesetstyle($res, (array) $mix);
     }
     if ($method == 3) {
         //画笔图像
         return imagesetbrush($res, $mix);
     }
     if ($method == 4) {
         //填充的贴图
         return imagesettile($res, $mix);
     }
     if ($method == 5) {
         //抗锯齿
         return imageantialias($res, (bool) $mix);
     }
     if ($method == 6) {
         //alpha混色标志
         return imagelayereffect($res, (int) $mix);
     }
     if ($method == 7) {
         //透明色
         return imagecolortransparent($res, (int) $mix);
     }
     if ($method == 8) {
         //混色模式
         return imagealphablending($res, (bool) $mix);
     }
     return 'method error';
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     if (is_object($this->fill)) {
         imagesettile($resource, $this->fill->getAdapter()->getHolder());
         imagefill($resource, $this->x, $this->y, IMG_COLOR_TILED);
     } else {
         imagefill($resource, $this->x, $this->y, $image->getAdapter()->getColorByHex($resource, $this->fill));
     }
     return $image;
 }
Exemple #23
0
 static function set(&$image, $value, $style = 'mix')
 {
     switch ($style) {
         case 'border':
             //画线粗细
             return imagesetthickness($image, (int) $value);
         case 'style':
             //画线风格
             return imagesetstyle($image, (array) $value);
         case 'brush':
             //画笔图像
             return imagesetbrush($image, $value);
         case 'pattern':
             //填充的贴图 图案
             return imagesettile($image, $value);
         case 'alias':
             //抗锯齿
             return imageantialias($image, (bool) $value);
         case 'alpha':
             //alpha混色标志
             return imagelayereffect($image, (int) $value);
         case 'transparent':
             //透明色
             return imagecolortransparent($image, (int) $value);
         case 'mix':
             //混色模式
         //混色模式
         default:
             return imagealphablending($image, (bool) $value);
     }
 }
 /**
  * render specific tex_col
  *
  * @param array $tex_col
  * @param array $color_rgb
  * @param array $polygon_array
  */
 private function render_tex_col($tex_col = [], $color_rgb = [], $polygon_array = [])
 {
     /* sure that happen? */
     if (empty($tex_col)) {
         return;
     }
     /* jingle */
     if (isset($tex_col['flipH']) && stripos('_flipH', $tex_col['assetNames'][0] !== false)) {
         $tex_col['assetNames'] = str_ireplace('_flipH', '', $tex_col['assetNames'][0]);
     }
     /* let's create a image.. */
     if (is_bool($tex_cols_asset = @imagecreatefrompng(MASKS_ROOT . $tex_col['assetNames'][0] . '.png'))) {
         return;
     }
     /* soo flip, soo flip, flip. */
     if (isset($tex_col['flipH']) && $tex_col['flipH'] == 'true') {
         imageflip($tex_cols_asset, IMG_FLIP_HORIZONTAL);
     }
     /* really, tha color is really bad.. */
     $this->image_recolor($tex_cols_asset, $color_rgb[0], $color_rgb[1], $color_rgb[2]);
     imagesettile($this->image, $tex_cols_asset);
     /* the tex_cols must be putted back into original image, y? */
     imagefilledpolygon($this->image, $polygon_array, count($polygon_array) / 2, IMG_COLOR_TILED);
     /* no garbage, sir */
     imagedestroy($tex_cols_asset);
 }
function sunshine_watermark_image($attachment_id, $metadata = array())
{
    global $sunshine;
    $attachment = get_post($attachment_id);
    if (get_post_type($attachment->post_parent) == 'sunshine-gallery' && $sunshine->options['watermark_image']) {
        $watermark_image = get_attached_file($sunshine->options['watermark_image']);
        $watermark_file_type = wp_check_filetype($watermark_image);
        if (file_exists($watermark_image) && $watermark_file_type['ext'] == 'png') {
            $image = get_attached_file($attachment_id, 'full');
            $image_size = apply_filters('sunshine_image_size', 'full');
            if (empty($metadata['sizes'][$image_size]['file'])) {
                $metadata = wp_get_attachment_metadata($attachment_id);
            }
            if ($image_size != 'full' && !empty($metadata['sizes'][$image_size]['file'])) {
                $image_basename = basename($image);
                $image_path = str_replace($image_basename, '', $image);
                $image = $image_path . $metadata['sizes'][$image_size]['file'];
            }
            if (!file_exists($image) || !file_exists($watermark_image)) {
                return;
            }
            $watermark = imagecreatefrompng($watermark_image);
            $new_image = imagecreatefromjpeg($image);
            $margin = $sunshine->options['watermark_margin'] != '' ? $sunshine->options['watermark_margin'] : 30;
            $watermark_width = imagesx($watermark);
            $watermark_height = imagesy($watermark);
            $new_image_width = imagesx($new_image);
            $new_image_height = imagesy($new_image);
            if ($sunshine->options['watermark_position'] == 'topleft') {
                $x_pos = $margin;
                $y_pos = $margin;
            } elseif ($sunshine->options['watermark_position'] == 'topright') {
                $x_pos = $new_image_width - $watermark_width - $margin;
                $y_pos = $margin;
            } elseif ($sunshine->options['watermark_position'] == 'bottomleft') {
                $x_pos = $margin;
                $y_pos = $new_image_height - $watermark_height - $margin;
            } elseif ($sunshine->options['watermark_position'] == 'bottomright') {
                $x_pos = $new_image_width - $watermark_width - $margin;
                $y_pos = $new_image_height - $watermark_height - $margin;
            } else {
                $x_pos = $new_image_width / 2 - $watermark_width / 2;
                $y_pos = $new_image_height / 2 - $watermark_height / 2;
            }
            if ($sunshine->options['watermark_position'] == 'repeat') {
                imagesettile($new_image, $watermark);
                imagefilledrectangle($new_image, 0, 0, $new_image_width, $new_image_height, IMG_COLOR_TILED);
            } else {
                imagecopy($new_image, $watermark, $x_pos, $y_pos, 0, 0, $watermark_width, $watermark_height);
            }
            // Output and free memory
            imagejpeg($new_image, $image, 100);
            imagedestroy($new_image);
            // Watermark the thumbnail if needed
            if ($sunshine->options['watermark_thumbnail']) {
                $image_editor = wp_get_image_editor($image);
                $image_editor->resize($sunshine->options['thumbnail_width'], $sunshine->options['thumbnail_height'], $sunshine->options['thumbnail_crop']);
                $image_editor->save($image_path . $metadata['sizes']['sunshine-thumbnail']['file']);
            }
        }
    }
}
Exemple #26
0
 public function setTile($image, $point = NULL, $width = NULL, $height = NULL)
 {
     $tile = $this->loadImage($image);
     if ($tile) {
         if (!$this->checkPoint($point)) {
             $point = array(0, 0);
         }
         if (is_null($width)) {
             $width = $this->width;
         }
         if (is_null($height)) {
             $height = $this->height;
         }
         imagesettile($this->img, $tile);
         imageFilledRectangle($this->img, $point[0], $point[1], $point[0] + $width, $point[1] + $height, IMG_COLOR_TILED);
         $this->destroyImage($tile);
         return true;
     } else {
         return false;
     }
 }
function cforms2_reset_captcha()
{
    check_admin_referer('cforms2_reset_captcha');
    $cformsSettings = get_option('cforms_settings');
    $cap = $cformsSettings['global']['cforms_captcha_def'];
    ### overwrite for admin demo purposes, no cookie set though
    if (count($_GET) > 4) {
        $cap = $_GET;
    }
    $min = cforms2_prepVal($cap['c1'], 4);
    $max = cforms2_prepVal($cap['c2'], 5);
    $src = cforms2_prepVal($cap['ac'], 'abcdefghijkmnpqrstuvwxyz23456789');
    $img_sz_type = 0;
    $img_sz_width = cforms2_prepVal($cap['w'], 115);
    $img_sz_height = cforms2_prepVal($cap['h'], 25);
    $im_bg_type = 1;
    $im_bg_url = plugin_dir_path(__FILE__) . 'captchabg/' . cforms2_prepVal($cap['bg'], '1.gif');
    $font_url = plugin_dir_path(__FILE__) . 'captchafonts/' . cforms2_prepVal($cap['f'], 'font4.ttf');
    $min_font_size = cforms2_prepVal($cap['f1'], 17);
    $max_font_size = cforms2_prepVal($cap['f2'], 19);
    $min_angle = cforms2_prepVal($cap['a1'], -12);
    $max_angle = cforms2_prepVal($cap['a2'], 12);
    $col_txt_type = 4;
    $col = cforms2_prepVal($cap['c'], '#000066');
    $col_txt_r = hexdec(substr($col, 1, 2));
    $col_txt_g = hexdec(substr($col, 3, 2));
    $col_txt_b = hexdec(substr($col, 5, 2));
    $border = cforms2_prepVal($cap['l'], '#000066');
    $border_r = hexdec(substr($border, 1, 2));
    $border_g = hexdec(substr($border, 3, 2));
    $border_b = hexdec(substr($border, 5, 2));
    $char_padding = 2;
    $output_type = 'png';
    $no = cforms2_prepVal($_GET['ts'], '');
    ### captcha random code
    $srclen = strlen($src) - 1;
    $length = mt_rand($min, $max);
    $turing = '';
    for ($i = 0; $i < $length; $i++) {
        $turing .= substr($src, mt_rand(0, $srclen), 1);
    }
    $tu = $cap['i'] == 'i' ? strtolower($turing) : $turing;
    if (!(isset($_GET['c1']) || isset($_GET['c2']) || isset($_GET['ac']))) {
        setcookie("turing_string_" . $no, $cap['i'] . '+' . md5($tu), time() + 60 * 60 * 5, "/");
    }
    $font = $font_url;
    ### initialize variables
    $length = strlen($turing);
    $data = array();
    $image_width = $image_height = 0;
    $codelen = 0;
    ### build the data array of the characters, size, placement, etc.
    for ($i = 0; $i < $length; $i++) {
        $char = substr($turing, $i, 1);
        $size = mt_rand($min_font_size, $max_font_size);
        $angle = mt_rand($min_angle, $max_angle);
        $bbox = ImageTTFBBox($size, $angle, $font, $char);
        $char_width = max($bbox[2], $bbox[4]) - min($bbox[0], $bbox[6]);
        $char_height = max($bbox[1], $bbox[3]) - min($bbox[7], $bbox[5]);
        $codelen = $codelen + $char_width + $char_padding;
        $image_width += $char_width + $char_padding;
        $image_height = max($image_height, $char_height);
        $data[] = array('char' => $char, 'size' => $size, 'angle' => $angle, 'height' => $char_height, 'width' => $char_width);
    }
    ### calculate the final image size, adding some padding
    $x_padding = 12;
    if ($img_sz_type == 1) {
        $image_width += $x_padding * 2;
        $image_height = $image_height * 1.5 + 2;
    } else {
        $image_width = $img_sz_width;
        $image_height = $img_sz_height;
    }
    ### build the image, and allocte the colors
    $im = ImageCreate($image_width, $image_height);
    $d1 = $d2 = $d3 = 0;
    while ($d1 < 50 and $d2 < 50 and $d3 < 50) {
        $r = mt_rand(200, 255);
        $g = mt_rand(200, 255);
        $b = mt_rand(200, 255);
        $d1 = abs($r - $g);
        $d2 = abs($r - $b);
        $d3 = abs($g - $b);
    }
    ImageColorAllocate($im, $r, $g, $b);
    $color_border = ImageColorAllocate($im, $border_r, $border_g, $border_b);
    ImageColorAllocate($im, round($r * 0.85), round($g * 0.85), round($b * 0.85));
    ImageColorAllocate($im, round($r * 0.95), round($g * 0.95), round($b * 0.95));
    ImageColorAllocate($im, round($r * 0.9), round($g * 0.9), round($b * 0.9));
    $d1 = mt_rand(0, 50);
    $d2 = mt_rand(0, 50);
    $d3 = mt_rand(0, 50);
    $d1 = $d2 = $d3 = 0;
    while ($d1 < 100 and $d2 < 100 and $d3 < 100) {
        $r = mt_rand(0, 150);
        $g = mt_rand(0, 150);
        $b = mt_rand(0, 150);
        $d1 = abs($r - $g);
        $d2 = abs($r - $b);
        $d3 = abs($g - $b);
    }
    switch ($col_txt_type) {
        case 1:
            $col_txt = ImageColorAllocate($im, $r, $g, $b);
            break;
        case 2:
            $col_txt = ImageColorAllocate($im, 0, 0, 0);
            break;
        case 3:
            $col_txt = ImageColorAllocate($im, 255, 255, 255);
            break;
        case 4:
            $col_txt = ImageColorAllocate($im, $col_txt_r, $col_txt_g, $col_txt_b);
            break;
    }
    $image_data = getimagesize($im_bg_url);
    $image_type = $image_data[2];
    if ($image_type == 1) {
        $img_src = imagecreatefromgif($im_bg_url);
    } elseif ($image_type == 2) {
        $img_src = imagecreatefromjpeg($im_bg_url);
    } elseif ($image_type == 3) {
        $img_src = imagecreatefrompng($im_bg_url);
    }
    if ($im_bg_type == 1) {
        imagesettile($im, $img_src);
        imageFilledRectangle($im, 0, 0, $image_width, $image_height, IMG_COLOR_TILED);
    } else {
        imagecopyresampled($im, $img_src, 0, 0, 0, 0, $image_width, $image_height, $image_data[0], $image_data[1]);
    }
    $pos_x = ($image_width - $codelen) / 2;
    foreach ($data as $d) {
        $pos_y = ($image_height + $d['height']) / 2;
        ImageTTFText($im, $d['size'], $d['angle'], $pos_x, $pos_y, $col_txt, $font, $d['char']);
        $pos_x += $d['width'] + $char_padding;
    }
    ### a nice border
    ImageRectangle($im, 0, 0, $image_width - 1, $image_height - 1, $color_border);
    // There can be some output from other loaded PHP files, therefore clean output.
    ob_end_clean();
    switch ($output_type) {
        case 'jpeg':
            Header('Content-type: image/jpeg');
            ImageJPEG($im, NULL, 100);
            break;
        case 'png':
        default:
            Header('Content-type: image/png');
            ImagePNG($im);
            break;
    }
    flush();
    ImageDestroy($im);
    die;
}
 /**
  * Fill image with given color or image source at position x,y
  *
  * @param  mixed   $source
  * @param  integer $pos_x
  * @param  integer $pos_y
  * @return Image
  */
 public function fill($source, $pos_x = 0, $pos_y = 0)
 {
     if (is_a($source, 'Intervention\\Image\\Image')) {
         // fill with image
         imagesettile($this->resource, $source->resource);
         $source = IMG_COLOR_TILED;
     } elseif ($this->isImageResource($source)) {
         // fill with image resource
         imagesettile($this->resource, $source);
         $source = IMG_COLOR_TILED;
     } elseif (is_string($source) && $this->isBinary($source)) {
         // fill with image from binary string
         $img = new self($source);
         imagesettile($this->resource, $img->resource);
         $source = IMG_COLOR_TILED;
     } elseif (is_string($source) && file_exists(realpath($source))) {
         $img = new self($source);
         imagesettile($this->resource, $img->resource);
         $source = IMG_COLOR_TILED;
     } else {
         // fill with color
         $source = $this->parseColor($source);
     }
     imagefill($this->resource, $pos_x, $pos_y, $source);
     return $this;
 }
     if ($operator == 'L') {
         $px -= $delta;
     }
     if ($operator == 'T') {
         $py -= $delta;
     }
     if ($operator == 'B') {
         $py += $delta;
     }
     $points[] = mapCoord($px);
     $points[] = mapCoord($py);
 }
 if ($subShape == 0) {
     // first polygon is outline
     // fill
     imagesettile($target_image, $fill_image);
     imagesetthickness($target_image, 2);
     imagefilledpolygon($target_image, $points, count($points) / 2, IMG_COLOR_TILED);
     // look mom, Decimal System!
     $labelCharCount = 1 + floor(log10(max(1, $pNum)));
     // label BG + TXT
     imagefilledrectangle($target_image, mapCoord($px) + 2, mapCoord($py) + 2, mapCoord($px) + 2 + imagefontwidth(1) * $labelCharCount, mapCoord($py) + 2 + imagefontheight(1), $colBg);
     imagestring($target_image, 1, mapCoord($px) + 2, mapCoord($py) + 2, $pNum, $colTxt);
     // outline line
     imagepolygon($target_image, $points, count($points) / 2, $colShape);
 } else {
     // other polygons describes "holes" in shape
     imagesetthickness($target_image, 2);
     imagefilledpolygon($target_image, $points, count($points) / 2, $colBg);
     imagepolygon($target_image, $points, count($points) / 2, $colShape);
     imagestring($target_image, 1, mapCoord($px) + 2, mapCoord($py) + 2, $pNum, $colShape);
<?php

define("WIDTH", 450);
define("HEIGHT", 450);
define("T_WIDTH", 20);
define("T_HEIGHT", 20);
$img = imagecreate(WIDTH, HEIGHT);
$background = $white = imagecolorallocate($img, 0xff, 0xff, 0xff);
$black = imagecolorallocate($img, 0, 0, 0);
$tile = imagecreate(T_WIDTH, T_HEIGHT);
$t_bkgr = $t_white = imagecolorallocate($tile, 0xff, 0xff, 0xff);
$t_black = imagecolorallocate($tile, 0, 0, 0);
imagefilledrectangle($tile, 0, 0, T_WIDTH / 2, T_HEIGHT / 2, $t_black);
imagefilledrectangle($tile, T_WIDTH / 2, T_HEIGHT / 2, T_WIDTH - 1, T_HEIGHT - 1, $t_black);
imagerectangle($img, 0, 0, WIDTH - 1, HEIGHT - 1, $black);
imagesettile($img, $tile);
imagefilledrectangle($img, 1, 1, WIDTH - 2, HEIGHT - 2, IMG_COLOR_TILED);
header("Content-Type: image/png");
imagepng($img);