コード例 #1
1
ファイル: MonsterId.php プロジェクト: recallfx/monsterid.php
 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;
 }
コード例 #2
1
ファイル: image.php プロジェクト: nyan-cat/easyweb
 static function load($filename)
 {
     $info = getimagesize($filename);
     list($width, $height) = $info;
     if (!$width || !$height) {
         return null;
     }
     $image = null;
     switch ($info['mime']) {
         case 'image/gif':
             $image = imagecreatefromgif($filename);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($filename);
             break;
         case 'image/png':
             $image = imagecreatetruecolor($width, $height);
             $white = imagecolorallocate($image, 255, 255, 255);
             imagefill($image, 0, 0, $white);
             $png = imagecreatefrompng($filename);
             imagealphablending($png, true);
             imagesavealpha($png, true);
             imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
             imagedestroy($png);
             break;
     }
     if ($image) {
         return new image($image, $width, $height);
     } else {
         return null;
     }
 }
コード例 #3
0
ファイル: image.php プロジェクト: ryanknu/Cuber
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);
}
コード例 #4
0
ファイル: gd.php プロジェクト: gilyaev/framework-bench
 public function load($filename, $return_data = false)
 {
     extract(parent::load($filename, $return_data));
     $return = false;
     $image_extension == 'jpg' and $image_extension = 'jpeg';
     if (!$return_data) {
         $this->image_data !== null and imagedestroy($this->image_data);
         $this->image_data = null;
     }
     // Check if the function exists
     if (function_exists('imagecreatefrom' . $image_extension)) {
         // Create a new transparent image.
         $sizes = $this->sizes($image_fullpath);
         $tmpImage = call_user_func('imagecreatefrom' . $image_extension, $image_fullpath);
         $image = $this->create_transparent_image($sizes->width, $sizes->height, $tmpImage);
         if (!$return_data) {
             $this->image_data = $image;
             $return = true;
         } else {
             $return = $image;
         }
         $this->debug('', "<strong>Loaded</strong> <code>" . $image_fullpath . "</code> with size of " . $sizes->width . "x" . $sizes->height);
     } else {
         throw new \RuntimeException("Function imagecreatefrom" . $image_extension . "() does not exist (Missing GD?)");
     }
     return $return_data ? $return : $this;
 }
コード例 #5
0
 public function fill_watermark()
 {
     $image = $this->editor->get_image();
     $size = $this->editor->get_size();
     list($mask_width, $mask_height, $mask_type, $mask_attr) = getimagesize($this->args['mask']);
     switch ($mask_type) {
         case 1:
             $mask = imagecreatefromgif($this->args['mask']);
             break;
         case 2:
             $mask = imagecreatefromjpeg($this->args['mask']);
             break;
         case 3:
             $mask = imagecreatefrompng($this->args['mask']);
             break;
     }
     imagealphablending($image, true);
     if (strpos($this->args['position'], 'left') !== false) {
         $left = $this->args['padding'];
     } else {
         $left = $size['width'] - $mask_width - $this->args['padding'];
     }
     if (strpos($this->args['position'], 'top') !== false) {
         $top = $this->args['padding'];
     } else {
         $top = $size['height'] - $mask_height - $this->args['padding'];
     }
     imagecopy($image, $mask, $left, $top, 0, 0, $mask_width, $mask_height);
     $this->editor->update_image($image);
     imagedestroy($mask);
 }
コード例 #6
0
 /**
  * Displays the image
  *
  * @param	integer	$quality	image render quality 1-100, default 100
  * @access	public
  * @return	void
  */
 function render($quality = 100)
 {
     header('Content-type: image/' . $this->type);
     @imageinterlace($this->handle, 1);
     @imagegif($this->handle, NULL, $quality);
     @imagedestroy($this->handle);
 }
コード例 #7
0
ファイル: resizeImage2.php プロジェクト: Wumingla/shopImooc
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5)
{
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    //image_50/sdfsdkfjkelwkerjle.jpg
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
コード例 #8
0
ファイル: captcha.php プロジェクト: binaek89/cms-canvas
 public function index()
 {
     $code = substr(sha1(mt_rand()), 17, 6);
     $this->session->set_userdata('captcha_code', $code);
     $width = '120';
     $height = '40';
     $font = APPPATH . 'modules/contact/assets/fonts/monofont.ttf';
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
コード例 #9
0
ファイル: code_char.php プロジェクト: hanpc/chushen
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);
}
コード例 #10
0
function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
コード例 #11
0
ファイル: profile.php プロジェクト: ngxuanmui/hanhphuc.vn
 function saveinfo()
 {
     $juser =& JFactory::getUser();
     if ($juser->guest) {
         $error = 'Bạn phải đăng nhập để thực hiện chức năng này';
         $this->setError($error);
         return false;
     }
     $post = JRequest::get('post');
     $data = array();
     $data['user_id'] = $juser->id;
     $data['couple_name'] = $post['couple_name'];
     $data['address'] = $post['address'];
     $data['country'] = $post['country'];
     if (isset($_FILES['avatar']) && $_FILES['avatar']['error'] == 0) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'thumb.php';
         $p = manThumb::resize($_FILES['avatar']['tmp_name'], 96, 96);
         $name = 'avatar_' . $juser->id . '.jpg';
         $file = JPATH_ROOT . DS . 'images' . DS . 'wedding' . DS . 'avatar' . DS . $name;
         imagejpeg($p, $file, 90);
         imagedestroy($p);
         $data['avatar'] = 'images/wedding/avatar/' . $name;
     }
     $row =& $this->getTable('users');
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     return true;
 }
コード例 #12
0
function resizer($image)
{
    $name = md5(sha1(date('d-m-y H:i:s') . $image['tmp_name']));
    $type = $image['type'];
    switch ($type) {
        case "image/jpeg":
            $img = imagecreatefromjpeg($image['tmp_name']);
            break;
        case "image/png":
            $img = imagecreatefrompng($image['tmp_name']);
            break;
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $height = 150 * $y / $x;
    $new = imagecreatetruecolor(150, $height);
    imagecopyresampled($new, $img, 0, 0, 0, 0, 150, $height, $x, $y);
    switch ($type) {
        case "image/jpeg":
            $local = "../assets/img/crudpartners/{$name}" . ".jpg";
            imagejpeg($new, $local);
            break;
        case "image/png":
            $local = "../assets/img/crudpartners/{$name}" . ".png";
            imagejpeg($new, $local);
            break;
    }
    imagedestroy($img);
    imagedestroy($new);
    return $local;
}
コード例 #13
0
ファイル: funcoes.php プロジェクト: mauriliovilela/ser-social
function upload($tmp, $name, $nome, $larguraP, $pasta)
{
    $ext = strtolower(end(explode('.', $name)));
    if ($ext == 'jpg') {
        $img = imagecreatefromjpeg($tmp);
    } elseif ($ext == 'gif') {
        $img = imagecreatefromgif($tmp);
    } else {
        $img = imagecreatefrompng($tmp);
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $largura = $x > $larguraP ? $larguraP : $x;
    $altura = $largura * $y / $x;
    if ($altura > $larguraP) {
        $altura = $larguraP;
        $largura = $altura * $x / $y;
    }
    $nova = imagecreatetruecolor($largura, $altura);
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
    imagejpeg($nova, "{$pasta}/{$nome}");
    imagedestroy($img);
    imagedestroy($nova);
    return $nome;
}
コード例 #14
0
 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;
 }
コード例 #15
0
function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false)
{
    // Create image
    $im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post));
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $color = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $color);
    // Draw stitches
    foreach ($embroidery->blocks as $block) {
        $color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b);
        $x = false;
        foreach ($block->stitches as $stitch) {
            if ($x !== false) {
                imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color);
            }
            $x = $stitch->x;
            $y = $stitch->y;
        }
    }
    // Scale finished image
    if ($scale_pre) {
        $im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre);
        imagesavealpha($im2, true);
        imagealphablending($im2, false);
        imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post);
        imagedestroy($im);
        $im = $im2;
    }
    return $im;
}
コード例 #16
0
ファイル: iSeccode.class.php プロジェクト: Junred/iCMS
 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;
 }
コード例 #17
0
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;
    }
}
コード例 #18
0
ファイル: upload.php プロジェクト: Zame31/SifutProject
function UploadImage($bukti_name)
{
    //direktori gambar
    $vdir_upload = "bukti/";
    $vfile_upload = $vdir_upload . $bukti_name;
    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["bukti"]["tmp_name"], $vfile_upload);
    //identitas file asli
    $im_src = imagecreatefromjpeg($vfile_upload);
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);
    //Simpan dalam versi small 110 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width = 50;
    $dst_height = $dst_width / $src_width * $src_height;
    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
    //Simpan gambar
    imagejpeg($im, $vdir_upload . "small_" . $bukti_name);
    //Simpan dalam versi medium 360 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width2 = 270;
    $dst_height2 = $dst_width2 / $src_width * $src_height;
    //proses perubahan ukuran
    $im2 = imagecreatetruecolor($dst_width2, $dst_height2);
    imagecopyresampled($im2, $im_src, 0, 0, 0, 0, $dst_width2, $dst_height2, $src_width, $src_height);
    //Simpan gambar
    imagejpeg($im2, $vdir_upload . "medium_" . $bukti_name);
    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
    imagedestroy($im2);
}
コード例 #19
0
ファイル: GdMediaAdapter.php プロジェクト: razzman/media
 function close($Media)
 {
     if (is_resource($Media->resources['gd'])) {
         return imagedestroy($Media->resources['gd']);
     }
     return false;
 }
コード例 #20
0
 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.5;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 20, 20, 20);
     $text_color = imagecolorallocate($image, 230, 197, 89);
     $noise_color = imagecolorallocate($image, 0, 0, 0);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     /*for( $i=0; $i<($width*$height)/150; $i++ ) {
     			imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
     		}*/
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
コード例 #21
0
ファイル: upload.php プロジェクト: xiaoniainiu/php-yaf-yk
namespace common;

class upload
{
    //从tmp中移动upload
    public static function zoom(&$file, &$maxWidth = 0, &$maxHeight = 0)
    {
        list($width, $height, $im, $func, $ext) = self::_init($file);
        if (!$im) {
            \yk\log::runlog('file upload error: im not found', 'upload');
            return false;
        }
        if ($maxWidth > 0) {
            $p = max($width / $maxWidth, $height / $maxHeight);
            $dstwidth = intval($width / $p);
            $dstheight = intval($height / $p);
        } else {
            $dstwidth = $width;
            $dstheight = $height;
        }
        $maxWidth = $dstwidth;
        $maxHeight = $dstheight;
        $dstim = imagecreatetruecolor($dstwidth, $dstheight);
        imagealphablending($dstim, false);
        //关闭混杂模式,不可缺少,  PHP文档中说明: (在非混色模式下,画笔颜色连同其 alpha 通道信息一起被拷贝,替换掉目标像素。混色模式在画调色板图像时不可用。)  而且是imagesavealpha方法起作用的前置步骤.
        imagesavealpha($dstim, true);
        //保存 PNG 图像时保存完整的 alpha 通道信息
        $transparent = imagecolorallocatealpha($dstim, 255, 255, 255, 127);
        //取得一个透明的颜色,  透明度在 0-127 间
        imagefill($dstim, 0, 0, $transparent);
        imagecopyresampled($dstim, $im, 0, 0, 0, 0, $dstwidth, $dstheight, $width, $height);
        $file = uniqid() . $ext;
コード例 #22
0
ファイル: Controller.php プロジェクト: neolf/PIWIK4MOBILE
 /**
  * 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;
 }
コード例 #23
0
ファイル: seccode.php プロジェクト: dotku/shopnc_cnnewyork
 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;
 }
コード例 #24
0
ファイル: Image.class.php プロジェクト: trabisdementia/xuups
 function destroy()
 {
     if ($this->isValid() && !$this->handleReleased) {
         imagedestroy($this->handle);
     }
     $this->handle = null;
 }
コード例 #25
0
ファイル: phpGD_functions.php プロジェクト: ritarafaeli/notes
function createthumb($originalImage, $newName, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg($originalImage);
    $newName .= ".jpg";
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}
コード例 #26
0
ファイル: Simple.php プロジェクト: Dulciane/jaws
 /**
  * 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;
 }
コード例 #27
0
ファイル: mymismatch.php プロジェクト: khk0613/YHK
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);
}
コード例 #28
0
ファイル: CssSprite.php プロジェクト: ejacobs/css-sprite
 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);
 }
コード例 #29
-1
ファイル: gd.php プロジェクト: syjzwjj/quyeba
 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;
 }
コード例 #30
-1
function createthumb($originalImage, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg("uploads/" . $originalImage);
    # Add the _t to our image name
    list($imageName, $extension) = explode(".", $originalImage);
    $newName = $imageName . "_t." . $extension;
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, "uploads/" . $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}