Example #1
1
 public function getAvatar($string, $widthHeight = 12, $theme = 'default')
 {
     $widthHeight = max($widthHeight, 12);
     $md5 = md5($string);
     $fileName = _TMP_DIR_ . '/' . $md5 . '.png';
     if ($this->tmpFileExists($fileName)) {
         return $fileName;
     }
     // Create seed.
     $seed = intval(substr($md5, 0, 6), 16);
     mt_srand($seed);
     $body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
     // Avatar random parts.
     $parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
     $avatar = imagecreate($widthHeight, $widthHeight);
     imagesavealpha($avatar, true);
     imagealphablending($avatar, false);
     $background = imagecolorallocate($avatar, 0, 0, 0);
     $line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
     imagecolortransparent($avatar, $background);
     imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
     // Fill avatar with random parts.
     foreach ($parts as &$part) {
         $this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
     }
     imagepng($avatar, $fileName);
     imagecolordeallocate($avatar, $line_colour);
     imagecolordeallocate($avatar, $background);
     imagedestroy($avatar);
     return $fileName;
 }
Example #2
0
function smart_spam($code)
{
    @putenv('GDFONTPATH=' . realpath('.'));
    $font = 'FONT.TTF';
    // antispam image height
    $height = 40;
    // antispam image width
    $width = 110;
    $font_size = $height * 0.6;
    $image = @imagecreate($width, $height);
    $background_color = @imagecolorallocate($image, 255, 255, 255);
    $noise_color = @imagecolorallocate($image, 20, 40, 100);
    /* add image noise */
    for ($i = 0; $i < $width * $height / 4; $i++) {
        @imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
    }
    /* render text */
    $text_color = @imagecolorallocate($image, 20, 40, 100);
    @imagettftext($image, $font_size, 0, 7, 29, $text_color, $font, $code) or die('Cannot render TTF text.');
    //output image to the browser *//*
    header('Content-Type: image/png');
    @imagepng($image) or die('imagepng error!');
    @imagedestroy($image);
    exit;
}
Example #3
0
 function save($handle, $uri = null, $compression = 9, $filters = PNG_ALL_FILTERS)
 {
     if ($compression > 9) {
         $compression *= 9 / 100;
     }
     return imagepng($handle, $uri, $compression, $filters);
 }
Example #4
0
function GetPartialImage($url)
{
	$W = 150;
	$H = 130;
	$F = 80;
	$STEP = 1.0 / $F;
	$im = imagecreatefromjpeg($url);
	$dest = imagecreatetruecolor($W, $H);
	imagecopy($dest, $im, 0, 0, 35, 40, $W, $H);
	
	$a = 1;
	for( $y = $H - $F; $y < $H; $y++ )
	{
		for ( $x = 0; $x < $W; $x++ )
		{
			$i = imagecolorat($dest, $x, $y);
			$c = imagecolorsforindex($dest, $i);
			$c = imagecolorallocate($dest, 
				a($c['red'], $a),
				a($c['green'], $a), 
				a($c['blue'], $a)
			);
			imagesetpixel($dest, $x, $y, $c);
		}
		$a -= $STEP;
	}
	
	header('Content-type: image/png');
	imagepng($dest);
	imagedestroy($dest);
	imagedestroy($im);
}
Example #5
0
function makeDataMatrix($code, $path)
{
    $x = 70;
    // barcode center
    $y = 70;
    // barcode center
    $height = 125;
    // barcode height in 1D ; module size in 2D
    $width = 4;
    // barcode height in 1D ; not use in 2D
    $angle = 90;
    // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
    $type = 'datamatrix';
    $im = imagecreatetruecolor(140, 140);
    $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
    $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
    $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
    $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
    imagefilledrectangle($im, 0, 0, 140, 140, $white);
    $data = \BarcodeGEN::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
    /*for($i=1; $i<5; $i++){
          drawCross($im, $blue, $data['p'.$i]['x'], $data['p'.$i]['y']);
      }*/
    imagepng($im, $path);
    imagedestroy($im);
}
Example #6
0
 /**
  * Processes incoming text
  */
 public function action_index()
 {
     $this->request->headers['Content-type'] = 'image/png';
     // Grab text and styles
     $text = arr::get($_GET, 'text');
     $styles = $_GET;
     $hover = FALSE;
     try {
         // Create image
         $img = new PNGText($text, $styles);
         foreach ($styles as $key => $value) {
             if (substr($key, 0, 6) == 'hover-') {
                 // Grab hover associated styles and override existing styles
                 $hover = TRUE;
                 $styles[substr($key, 6)] = $value;
             }
         }
         if ($hover) {
             // Create new hover image and stack it
             $hover = new PNGText($text, $styles);
             $img->stack($hover);
         }
         echo $img->draw();
     } catch (Exception $e) {
         if (Kohana::config('pngtext.debug')) {
             // Dump error message in an image form
             $img = imagecreatetruecolor(strlen($e->getMessage()) * 6, 16);
             imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
             imagestring($img, 2, 0, 0, $e->getMessage(), imagecolorallocate($img, 0, 0, 0));
             echo imagepng($img);
         }
     }
 }
Example #7
0
function getCode($num, $w, $h)
{
    // 去掉了 0 1 O l 等
    $str = "23456789abcdefghijkmnpqrstuvwxyz";
    $code = '';
    for ($i = 0; $i < $num; $i++) {
        $code .= $str[mt_rand(0, strlen($str) - 1)];
    }
    //将生成的验证码写入session,备验证页面使用
    $_SESSION["my_checkcode"] = $code;
    //创建图片,定义颜色值
    Header("Content-type: image/PNG");
    $im = imagecreate($w, $h);
    $black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
    $gray = imagecolorallocate($im, 118, 151, 199);
    $bgcolor = imagecolorallocate($im, 235, 236, 237);
    //画背景
    imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
    //画边框
    imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
    //imagefill($im, 0, 0, $bgcolor);
    //在画布上随机生成大量点,起干扰作用;
    for ($i = 0; $i < 80; $i++) {
        imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
    }
    //将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
    $strx = rand(5, 10);
    for ($i = 0; $i < $num; $i++) {
        $strpos = rand(1, 6);
        imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
        $strx += $w / 5;
    }
    imagepng($im);
    imagedestroy($im);
}
Example #8
0
 private static function __image()
 {
     self::__background();
     self::__adulterate();
     self::__font();
     header("Expires: 0" . PHP_EOL);
     header("Cache-Control: no-cache" . PHP_EOL);
     header("Pragma: no-cache" . PHP_EOL);
     if (function_exists('imagejpeg')) {
         header('Content-type:image/jpeg' . PHP_EOL);
         $void = imagejpeg(self::$im);
     } else {
         if (function_exists('imagepng')) {
             header('Content-type:image/png' . PHP_EOL);
             $void = imagepng(self::$im);
         } else {
             if (function_exists('imagegif')) {
                 header('Content-type:image/gif' . PHP_EOL);
                 $void = imagegif(self::$im);
             } else {
                 return false;
             }
         }
     }
     imagedestroy(self::$im);
     return $void;
 }
Example #9
0
 public function createSemacode($info, $name)
 {
     $_img = $this->_semacode->asGDImage($info, 120);
     header('Content-Type: image/png');
     imagepng($_img, "/tmp/{$name}.png");
     imagedestroy($_img);
 }
Example #10
0
	function setUp() {
		parent::setUp();
		
		if(!file_exists(ASSETS_PATH)) mkdir(ASSETS_PATH);

		// Create a test folders for each of the fixture references
		$folderIDs = $this->allFixtureIDs('Folder');
		
		foreach($folderIDs as $folderID) {
			$folder = DataObject::get_by_id('Folder', $folderID);
			
			if(!file_exists(BASE_PATH."/$folder->Filename")) mkdir(BASE_PATH."/$folder->Filename");
		}
		
		// Create a test files for each of the fixture references
		$fileIDs = $this->allFixtureIDs('Image');
		foreach($fileIDs as $fileID) {
			$file = DataObject::get_by_id('Image', $fileID);
			$image = imagecreatetruecolor(300,300);
		
			imagepng($image, BASE_PATH."/$file->Filename");
			imagedestroy($image);
		
			$file->write();
		}
	}
Example #11
0
 /**
  * Class constructor generates the CAPTCHA image.
  *
  * @return blob the image
  * @access public
  */
 function __construct()
 {
     session_start();
     $image = imagecreate($this->width, $this->height);
     $random_str = $this->gen_str($this->chars_nr);
     #md5( microtime() );						// md5 to generate the random string
     $result_str = substr($random_str, 0, $this->chars_nr);
     //trim $chars_nr digit
     $bg_color = imagecolorallocate($image, $this->background_color['red'], $this->background_color['green'], $this->background_color['blue']);
     // background color
     $tx_color = imagecolorallocate($image, $this->text_color['red'], $this->text_color['gree'], $this->text_color['blue']);
     // text color
     for ($i = 0; $i <= $this->lines; $i++) {
         $line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         //line color
         imageline($image, rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), $line_color);
         // Create lines on image
     }
     imagestring($image, 5, 20, 10, $result_str, $tx_color);
     // Draw a random string horizontally
     $_SESSION['key'] = $result_str;
     // Carry the data through session
     header("Content-type: image/png");
     // Out out the image
     imagepng($image);
     // Output image to browser
 }
Example #12
0
 function writeToCache($ID, $pChartObject)
 {
     /* Compute the paths */
     $TemporaryFile = $this->CacheFolder . "/tmp_" . rand(0, 1000) . ".png";
     $Database = $this->CacheFolder . "/" . $this->CacheDB;
     $Index = $this->CacheFolder . "/" . $this->CacheIndex;
     /* Flush the picture to a temporary file */
     imagepng($pChartObject->Picture, $TemporaryFile);
     /* Retrieve the files size */
     $PictureSize = filesize($TemporaryFile);
     $DBSize = filesize($Database);
     /* Save the index */
     $Handle = fopen($Index, "a");
     fwrite($Handle, $ID . "," . $DBSize . "," . $PictureSize . "," . time() . ",0      \r\n");
     fclose($Handle);
     /* Get the picture raw contents */
     $Handle = fopen($TemporaryFile, "r");
     $Raw = fread($Handle, $PictureSize);
     fclose($Handle);
     /* Save the picture in the solid database file */
     $Handle = fopen($Database, "a");
     fwrite($Handle, $Raw);
     fclose($Handle);
     /* Remove temporary file */
     unlink($TemporaryFile);
 }
Example #13
0
 function createCode($len = 4)
 {
     $width = 100;
     $height = 50;
     $size = 22;
     //字体大小
     $font = ROOT_PATH . '/static/font/arial.ttf';
     //字体
     $img = imagecreatetruecolor($width, $height);
     //创建画布
     $bgimg = imagecreatefromjpeg(ROOT_PATH . '/static/background/' . rand(1, 5) . '.jpg');
     //生成背景图片
     $bg_x = rand(0, 100);
     //随机招贴画布起始X轴坐标
     $bg_y = rand(0, 50);
     //随机招贴画布起始Y轴坐标
     imagecopy($img, $bgimg, 0, 0, $bg_x, $bg_y, $bg_x + $width, $bg_y + $height);
     //把背景图片$bging粘贴的画布上
     $str = $this->creaStr($len);
     //字符串
     for ($i = 0, $j = 5; $i < 4; $i++) {
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //扭曲角度
         imagettftext($img, $size, $an, $j + 5, 34, imagecolorallocate($img, rand(0, 100), rand(0, 100), rand(0, 100)), $font, $str[$i]);
         //生成验证字符窜
         $j += 20;
     }
     cookie('captchacode', strtolower($str));
     header('Content-type:image/png');
     imagepng($img);
     imagedestroy($img);
 }
Example #14
0
 /**
  * 生成验证码
  * @param  string $file 图片保存文件名,不指定则图片会被直接输出
  * @return null
  */
 public function get($file = "")
 {
     $support = $this->support();
     list($code, $answer) = $this->generateCode();
     $image = null;
     @session_start();
     $_SESSION['vitex.captcha.answer'] = strtolower($answer);
     if ($support == 'imagick') {
         $image = new \Imagick();
         $image->newImage($this->width, $this->height, "none");
         $image->setImageFormat('png');
         $image = $this->imagickLine($image, $this->linenum);
         $image = $this->imagickDrawText($image, $code);
         $image->swirlImage(30);
         $image->oilPaintImage(1);
         if ($file) {
             $image->writeImage($file);
         } else {
             header("Content-type:image/png");
             echo $image->getImageBlob();
         }
     } else {
         $image = imagecreate($this->width, $this->height);
         $color = imagecolorallocate($image, 255, 255, 255);
         imagecolortransparent($image, $color);
         $this->gdLine($image, $this->linenum);
         $this->gdDrawText($image, $code);
         if ($file) {
             imagepng($image, $file);
         } else {
             header("Content-type: image/jpeg; Cache-Control: no-store, no-cache, must-revalidate");
             imagepng($image);
         }
     }
 }
Example #15
0
 /**
  * Render the gradient to an image
  **/
 public function render($width, $height, $format = 'png', $filename = null)
 {
     $image = $this->render_gd($width, $height);
     switch ($format) {
         case 'jpg':
         case 'jpeg':
         case 'jpe':
             if (empty($filename)) {
                 header('Content-Type: image/jpeg');
             }
             imagejpeg($image, $filename, 90);
             break;
         case 'gif':
             if (empty($filename)) {
                 header('Content-Type: image/gif');
             }
             imagegif($image, $filename);
             break;
         case 'png':
         default:
             if (empty($filename)) {
                 header('Content-Type: image/png');
             }
             imagepng($image, $filename, 9);
             break;
     }
     imagedestroy($image);
 }
Example #16
0
function create_pic($upfile, $new_path, $width)
{
    $quality = 100;
    $image_path = $upfile;
    $image_info = getimagesize($image_path);
    $exname = '';
    //1  =  GIF,  2  =  JPG,  3  =  PNG,  4  =  SWF,  5  =  PSD,  6  =  BMP,  7  =  TIFF(intel  byte  order),  8  =  TIFF(motorola  byte  order),  9  =  JPC,  10  =  JP2,  11  =  JPX,  12  =  JB2,  13  =  SWC,  14  =  IFF
    switch ($image_info[2]) {
        case 1:
            @($image = imagecreatefromgif($image_path));
            $exname = 'gif';
            break;
        case 2:
            @($image = imagecreatefromjpeg($image_path));
            $exname = 'jpg';
            break;
        case 3:
            @($image = imagecreatefrompng($image_path));
            $exname = 'png';
            break;
        case 6:
            @($image = imagecreatefromwbmp($image_path));
            $exname = 'wbmp';
            break;
    }
    $T_width = $image_info[0];
    $T_height = $image_info[1];
    if (!empty($image)) {
        $image_x = imagesx($image);
        $image_y = imagesy($image);
    } else {
        return FALSE;
    }
    @chmod($new_path, 0777);
    if ($image_x > $width) {
        $x = $width;
        $y = intval($x * $image_y / $image_x);
    } else {
        @copy($image_path, $new_path . '.' . $exname);
        return $exname;
    }
    $newimage = imagecreatetruecolor($x, $y);
    imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y);
    switch ($image_info[2]) {
        case 1:
            imagegif($newimage, $new_path . '.gif', $quality);
            break;
        case 2:
            imagejpeg($newimage, $new_path . '.jpg', $quality);
            break;
        case 3:
            imagepng($newimage, $new_path . '.png', $quality);
            break;
        case 6:
            imagewbmp($newimage, $new_path . '.wbmp', $quality);
            break;
    }
    imagedestroy($newimage);
    return $exname;
}
 static function resizewidth($width, $imageold, $imagenew)
 {
     $image_info = getimagesize($imageold);
     $image_type = $image_info[2];
     if ($image_type == IMAGETYPE_JPEG) {
         $image = imagecreatefromjpeg($imageold);
     } elseif ($this->image_type == IMAGETYPE_GIF) {
         $image = imagecreatefromgif($imageold);
     } elseif ($this->image_type == IMAGETYPE_PNG) {
         $image = imagecreatefrompng($imageold);
     }
     $ratio = imagesy($image) / imagesx($image);
     $height = $width * $ratio;
     //$width = imagesx($image) * $width/100;
     // $height = imagesx($image) * $width/100;
     $new_image = imagecreatetruecolor($width, $height);
     imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_info[0], $image_info[1]);
     $image = $new_image;
     $compression = 75;
     $permissions = null;
     if ($image_type == IMAGETYPE_JPEG) {
         imagejpeg($image, $imagenew, $compression);
     } elseif ($image_type == IMAGETYPE_GIF) {
         imagegif($image, $imagenew);
     } elseif ($image_type == IMAGETYPE_PNG) {
         imagepng($image, $imagenew);
     }
     if ($permissions != null) {
         chmod($imagenew, $permissions);
     }
 }
Example #18
0
function graph_error($string)
{
    global $vars, $config, $debug, $graphfile;
    $vars['bg'] = 'FFBBBB';
    include 'includes/graphs/common.inc.php';
    $rrd_options .= ' HRULE:0#555555';
    $rrd_options .= " --title='" . $string . "'";
    rrdtool_graph($graphfile, $rrd_options);
    if ($height > '99') {
        shell_exec($rrd_cmd);
        d_echo('<pre>' . $rrd_cmd . '</pre>');
        if (is_file($graphfile) && !$debug) {
            header('Content-type: image/png');
            $fd = fopen($graphfile, 'r');
            fpassthru($fd);
            fclose($fd);
            unlink($graphfile);
            exit;
        }
    } else {
        if (!$debug) {
            header('Content-type: image/png');
        }
        $im = imagecreate($width, $height);
        $px = (imagesx($im) - 7.5 * strlen($string)) / 2;
        imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0));
        imagepng($im);
        imagedestroy($im);
        exit;
    }
}
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files")
{
    // Größe und Typ ermitteln
    list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src);
    if (!$src_typ) {
        return false;
    }
    // calculate new size
    if ($src_width >= $src_height) {
        $new_image_height = $src_height / $src_width * $img_width;
        $new_image_width = $img_width;
        if ($new_image_height > $img_height) {
            $new_image_width = $new_image_width / $new_image_height * $img_height;
            $new_image_height = $img_height;
        }
    } else {
        $new_image_width = $src_width / $src_height * $img_height;
        $new_image_height = $img_height;
        if ($new_image_width > $img_width) {
            $new_image_height = $new_image_height / $new_image_width * $img_width;
            $new_image_width = $img_width;
        }
    }
    // for the case that the thumbnail would be bigger then the original picture
    if ($new_image_height > $src_height) {
        $new_image_width = $new_image_width * $src_height / $new_image_height;
        $new_image_height = $src_height;
    }
    if ($new_image_width > $src_width) {
        $new_image_height = $new_image_height * $new_image_width / $src_width;
        $new_image_width = $src_width;
    }
    if ($src_typ == 1) {
        $image = imagecreatefromgif($folder_scr . "/" . $img_src);
        $new_image = imagecreate($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 2) {
        $image = imagecreatefromjpeg($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 3) {
        $image = imagecreatefrompng($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagepng($new_image, $des_src . "/" . $img_src . "_thumb");
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } else {
        return false;
    }
}
 public function createImageKey($user, $dblink)
 {
     if ($stm = $dblink->prepare("SELECT 2fa_imgname FROM  " . TABLE_USERS . " WHERE email = ?")) {
         $stm->execute(array($user));
         $row = $stm->fetch();
         $stm = NULL;
         $file = 'uploads/2fa/' . $row['2fa_imgname'];
     }
     $im = new Image();
     $imageclean = $im->loadLocalFile($file);
     $imagekey = $im->embedStegoKey($imageclean);
     $stegoKey = $im->stegoKey;
     $hash = password_hash($stegoKey, PASSWORD_DEFAULT);
     if ($stm = $dblink->prepare("UPDATE " . TABLE_USERS . " SET 2fa_hash = ? WHERE email = ?")) {
         $stm->execute(array($hash, $user));
         $stm = NULL;
     }
     if (ob_get_level()) {
         ob_end_clean();
     }
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=KeyImage.png');
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     //header('Content-Length: ' . filesize($file));
     $ok = imagepng($imagekey);
     //, NULL, 9
     imagedestroy($imagekey);
     return $ok;
 }
Example #21
0
 function background()
 {
     $this->im = imagecreatetruecolor($this->width, $this->height);
     $backgrounds = $c = array();
     if (!$this->background || !$backgrounds) {
         for ($i = 0; $i < 3; $i++) {
             $start[$i] = mt_rand(200, 255);
             $end[$i] = mt_rand(100, 150);
             $step[$i] = ($end[$i] - $start[$i]) / $this->width;
             $c[$i] = $start[$i];
         }
         for ($i = 0; $i < $this->width; $i++) {
             $color = imagecolorallocate($this->im, $c[0], $c[1], $c[2]);
             imageline($this->im, $i, 0, $i, $this->height, $color);
             $c[0] += $step[0];
             $c[1] += $step[1];
             $c[2] += $step[2];
         }
         $c[0] -= 20;
         $c[1] -= 20;
         $c[2] -= 20;
     }
     ob_start();
     if (function_exists('imagepng')) {
         imagepng($this->im);
     } else {
         imagejpeg($this->im, '', 100);
     }
     imagedestroy($this->im);
     $bgcontent = ob_get_contents();
     ob_end_clean();
     $this->fontcolor = $c;
     return $bgcontent;
 }
Example #22
0
 /**
  * Output binary image from base-64 encoded data.
  *
  * @deprecated 1.5.1
  *
  * @param string $imageData Base-64 encoded image data (via $_POST)
  */
 public static function outputBinaryImage()
 {
     Piwik::checkUserHasSomeViewAccess();
     $rawData = Piwik_Common::getRequestVar('imageData', '', 'string', $_POST);
     // returns false if any illegal characters in input
     $data = base64_decode($rawData);
     if ($data !== false) {
         // check for PNG header
         if (Piwik_Common::substr($data, 0, 8) === "‰PNG\r\n\n") {
             header('Content-Type: image/png');
             // more robust validation (if available)
             if (function_exists('imagecreatefromstring')) {
                 // validate image data
                 $imgResource = @imagecreatefromstring($data);
                 if ($imgResource !== false) {
                     // output image and clean-up
                     imagepng($imgResource);
                     imagedestroy($imgResource);
                     exit;
                 }
             } else {
                 echo $data;
                 exit;
             }
         }
     }
     Piwik::setHttpStatus('400 Bad Request');
     exit;
 }
Example #23
0
 function resizeThumbnailImage($thumb, $image, $width, $height, $start_width, $start_height, $scale)
 {
     $newImageWidth = ceil($width * $scale);
     $newImageHeight = ceil($height * $scale);
     $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
     $ext = strtolower(substr(basename($image), strrpos(basename($image), '.') + 1));
     $source = '';
     if ($ext == 'png') {
         $source = imagecreatefrompng($image);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $source = imagecreatefromjpeg($image);
     } elseif ($ext == 'gif') {
         $source = imagecreatefromgif($image);
     }
     imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
     $ext = strtolower(substr(basename($thumb), strrpos(basename($thumb), '.') + 1));
     if ($ext == 'png') {
         $result = imagepng($newImage, $thumb, 0);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $result = imagejpeg($newImage, $thumb, 90);
     } elseif ($ext == 'gif') {
         $result = imagegif($newImage, $thumb);
     }
     if (!$result) {
         return false;
     }
     chmod($thumb, 0664);
     return $thumb;
 }
Example #24
0
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $bg = dirname(__FILE__) . '/resources/simple.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     // Write it in a random position..
     $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
     $x = 5;
     $y = 20;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $fnt = rand(7, 10);
         $y = rand(6, 10);
         imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
         $x = $x + rand(15, 25);
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }
function cuttingimg($zoom, $fn, $sz)
{
    @mkdir(WUO_ROOT . '/photos/maps');
    $img = imagecreatefrompng(WUO_ROOT . '/photos/maps/0-0-0-' . $fn);
    // получаем идентификатор загруженного изрбражения которое будем резать
    $info = getimagesize(WUO_ROOT . '/photos/maps/0-0-0-' . $fn);
    // получаем в массив информацию об изображении
    $w = $info[0];
    $h = $info[1];
    // ширина и высота исходного изображения
    $sx = round($w / $sz, 0);
    // длинна куска изображения
    $sy = round($h / $sz, 0);
    // высота куска изображения
    $px = 0;
    $py = 0;
    // координаты шага "реза"
    for ($y = 0; $y <= $sz; $y++) {
        for ($x = 0; $x <= $sz; $x++) {
            $imgcropped = imagecreatetruecolor($sx, $sy);
            imagecopy($imgcropped, $img, 0, 0, $px, $py, $sx, $sy);
            imagepng($imgcropped, WUO_ROOT . '/photos/maps/' . $zoom . '-' . $y . '-' . $x . '-' . $fn);
            $px = $px + $sx;
        }
        $px = 0;
        $py = $py + $sy;
    }
}
Example #26
0
function draw_bar_graph($width, $height, $data, $max_value, $filename)
{
    // Create the empty graph image
    $img = imagecreatetruecolor($width, $height);
    // Set a white background with black text and gray graphics
    $bg_color = imagecolorallocate($img, 255, 255, 255);
    // white
    $text_color = imagecolorallocate($img, 255, 255, 255);
    // white
    $bar_color = imagecolorallocate($img, 0, 0, 0);
    // black
    $border_color = imagecolorallocate($img, 192, 192, 192);
    // light gray
    // Fill the background
    imagefilledrectangle($img, 0, 0, $width, $height, $bg_color);
    // Draw the bars
    $bar_width = $width / (count($data) * 2 + 1);
    for ($i = 0; $i < count($data); $i++) {
        imagefilledrectangle($img, $i * $bar_width * 2 + $bar_width, $height, $i * $bar_width * 2 + $bar_width * 2, $height - $height / $max_value * $data[$i][1], $bar_color);
        imagestringup($img, 5, $i * $bar_width * 2 + $bar_width, $height - 5, $data[$i][0], $text_color);
    }
    // Draw a rectangle around the whole thing
    imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color);
    // Draw the range up the left side of the graph
    for ($i = 1; $i <= $max_value; $i++) {
        imagestring($img, 5, 0, $height - $i * ($height / $max_value), $i, $bar_color);
    }
    // Write the graph image to a file
    imagepng($img, $filename, 5);
    imagedestroy($img);
}
Example #27
0
 public function save()
 {
     $maxHeight = 0;
     $width = 0;
     foreach ($this->_segmentsArray as $segment) {
         $maxHeight = max($maxHeight, $segment->height);
         $width += $segment->width;
     }
     // create our canvas
     $img = imagecreatetruecolor($width, $maxHeight);
     $background = imagecolorallocatealpha($img, 255, 255, 255, 127);
     imagefill($img, 0, 0, $background);
     imagealphablending($img, false);
     imagesavealpha($img, true);
     // start placing our images on a single x axis
     $xPos = 0;
     foreach ($this->_segmentsArray as $segment) {
         $tmp = imagecreatefromjpeg($segment->pathToImage);
         imagecopy($img, $tmp, $xPos, 0, 0, 0, $segment->width, $segment->height);
         $xPos += $segment->width;
         imagedestroy($tmp);
     }
     // create our final output image.
     imagepng($img, $this->_saveToPath);
 }
Example #28
-1
 public function store_codeOp()
 {
     if ($_GET['text']) {
         $text = $_GET['text'];
         $size = '6';
         $level = 'H';
         $logo = BASE_RESOURCE_PATH . DS . '/logo_2.png';
         $padding = '2';
         $path = BASE_RESOURCE_PATH . DS . 'phpqrcode';
         $QR = $path . 'qrcode.png';
         require_once BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'phpqrcode.php';
         QRcode::png($text, $QR, $level, $size, $padding);
         if ($logo !== false) {
             $QR = imagecreatefromstring(file_get_contents($QR));
             $logo = imagecreatefromstring(file_get_contents($logo));
             $QR_width = imagesx($QR);
             $QR_height = imagesy($QR);
             $logo_width = imagesx($logo);
             $logo_height = imagesy($logo);
             $logo_qr_width = $QR_width / 5;
             $scale = $logo_width / $logo_qr_width;
             $logo_qr_height = $logo_height / $scale;
             $from_width = ($QR_width - $logo_qr_width) / 2;
             imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
         }
         header("Content-Type:image/jpg");
         imagepng($QR);
     } else {
         output_error('参数错误00023');
     }
 }
Example #29
-1
 function output()
 {
     $arr = $this->ret;
     $bg = DATA_DIR . '/cache/vcodebg.png';
     $image = imagecreatefrompng($bg);
     list($w, $baseH) = getimagesize($bg);
     header('Content-type: image/png');
     $x = 1;
     foreach ($arr as $i => $filename) {
         list($w, $h) = getimagesize($filename);
         $source = imagecreatefrompng($filename);
         $t_id = imagecolortransparent($source);
         $rotate = imagerotate($source, rand(-20, 20), $t_id);
         $w2 = $w * $baseH / $h;
         imagecopyresized($image, $rotate, $x, 0, 0, 0, $w2, $baseH, $w, $h);
         imagedestroy($source);
         imagedestroy($rotate);
         $x += $w2;
     }
     $x += 1;
     $dst = imagecreatetruecolor($x, $baseH);
     imagecopyresampled($dst, $image, 0, 0, 0, 0, $x, $baseH, $x, $baseH);
     imagepng($dst);
     imagedestroy($image);
     imagedestroy($dst);
     exit;
 }
Example #30
-1
 /**
  *	Génère l'avatar
  */
 public function run()
 {
     //On créer l'image avec les dimentions données
     $image = imagecreate($this->_size, $this->_size);
     //On créer la couleur en fonction du hash de la chaine de caractères
     $color = imagecolorallocate($image, hexdec(substr($this->_color, 0, 2)), hexdec(substr($this->_color, 2, 2)), hexdec(substr($this->_color, 4, 2)));
     //on défini le fond de l'image (blanc)
     $bg = imagecolorallocate($image, 255, 255, 255);
     //nombre de blocs à placer dans l'image (taille de l'image/taille des blocs)
     $c = $this->_size / $this->_blockSize;
     for ($x = 0; $x < ceil($c / 2); $x++) {
         for ($y = 0; $y < $c; $y++) {
             // Si le nombre est pair $pixel vaut true sinon $pixel vaut false
             $pixel = hexdec($this->_hash[(int) ($x * ceil($c / 2)) + $y]) % 2 == 0;
             if ($pixel) {
                 $pixelColor = $color;
             } else {
                 $pixelColor = $bg;
             }
             // On place chaque bloc de l'image
             //imagefilledrectangle($image, $x*$this->_blockSize, $y*$this->_blockSize, ($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
             //imagefilledrectangle($image, $this->_size-$x*$this->_blockSize, $y*$this->_blockSize, $this->_size-($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
             imagefilledrectangle($image, $x * $this->_blockSize, $y * $this->_blockSize, ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
             imagefilledrectangle($image, $this->_size - $x * $this->_blockSize, $y * $this->_blockSize, $this->_size - ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
         }
     }
     ob_start();
     imagepng($image);
     //on place l'image en mémoire
     $this->_image = ob_get_contents();
     ob_clean();
 }