예제 #1
0
 public static function Mostrar()
 {
     // La cantidad de caracteres que va a mostrar el captcha
     $longitud = 5;
     // Los caracteres que nuestro captcha va a considerar
     $caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
     // El catpcha creado
     $captcha = "";
     for ($i = 0; $i < $longitud; $i++) {
         $captcha .= $caracteres[rand(0, strlen($caracteres) - 1)];
     }
     // Guardamos el catpcha en sesion para validar
     $_SESSION['captcha_codigo'] = strtolower($captcha);
     // Creamos la imagen
     // Creamos una imagen con forma de rectangulo por las medidas definidas a continuación
     $ancho = 600;
     $alto = 180;
     $fuente_tamano = 80;
     $fuente = 'lib/captcha/font.ttf';
     $img = imagecreatetruecolor($ancho, $alto);
     // Agregamos el texto
     $blanco = ImageColorAllocate($img, 255, 255, 255);
     // BLANCO
     // Coordenadas de donde va a ir el texto
     $x = $fuente_tamano;
     $y = $alto / 2 + 25;
     // El texto blanco
     imagettftext($img, $fuente_tamano, 0, $x, $y, $blanco, $fuente, $captcha);
     // Generamos la imagen
     header("Content-Type: image/jpeg");
     ImageJpeg($img);
     ImageDestroy($img);
 }
예제 #2
0
function Resampling($tmp_name, $directorio, $name)
{
    // Indico el destino del directorio de la imagen
    $imagen_origen = ImageCreateFromJPEG($tmp_name);
    // Calculo el tamaño de la imagen original
    $tam_ancho = imagesx($imagen_origen);
    $tam_alto = imagesy($imagen_origen);
    //Calculo la medida que va a tener
    if ($tam_ancho >= $tam_alto) {
        $ancho = 38;
        $alto = 38 * $tam_alto / $tam_ancho;
    } else {
        $ancho = 38 * $tam_ancho / $tam_alto;
        $alto = 38;
    }
    //Creo una imagen
    $imagen_destino = ImageCreateTrueColor($ancho, $alto);
    //Resize
    imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tam_ancho, $tam_alto);
    $nombre_destino = $directorio . $name;
    //Genero Copia Destino
    ImageJPEG($imagen_destino, $nombre_destino, 100);
    //Borro imagen virtual
    ImageDestroy($imagen_destino);
}
예제 #3
0
 function resize($img, $wid, $hei = 0, $quality = 100)
 {
     $hei == 0 && ($hei = $wid);
     $this->srcimg = $img;
     $this->resize_width = $wid;
     $this->resize_height = $hei;
     //图片的类型
     $this->type = strtolower(substr(strrchr($this->srcimg, "."), 1));
     $this->quality = $quality;
     //初始化图象
     if (!$this->initi_img()) {
         return false;
     }
     if (!$this->im) {
         $this->error = '生成资源出错';
         return false;
     }
     //目标图象地址
     //$this -> dst_img($dstpath);
     $this->dstimg = $this->srcimg . '.thumb.jpg';
     $this->width = imagesx($this->im);
     $this->height = imagesy($this->im);
     //生成图象
     $flag = $this->newimg();
     ImageDestroy($this->im);
     return $flag;
 }
예제 #4
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $wh = false)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $www = $imgW * $pixelPerPoint;
     $hhh = $imgH * $pixelPerPoint;
     if (is_array($wh)) {
         $www = $wh[0];
         $hhh = $wh[1];
     }
     $target_image = ImageCreate($www, $hhh);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $www, $hhh, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
 public function update_picture()
 {
     if (trim($_FILES["myfile"]["tmp_name"]) != "") {
         $images = $_FILES["myfile"]["tmp_name"];
         $new_images = "thumb_" . $this->session->userdata('std_cardid') . '_' . $_FILES["myfile"]["name"];
         copy($_FILES["myfile"]["tmp_name"], "assets/uploads/photo/" . $_FILES["myfile"]["name"]);
         $width = 150;
         //*** Fix Width & Heigh (Autu caculate) ***//
         $size = GetimageSize($images);
         $height = round($width * $size[1] / $size[0]);
         $images_orig = ImageCreateFromJPEG($images);
         $photoX = ImagesX($images_orig);
         $photoY = ImagesY($images_orig);
         $images_fin = ImageCreateTrueColor($width, $height);
         ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
         ImageJPEG($images_fin, "assets/uploads/photo/" . $new_images);
         ImageDestroy($images_orig);
         ImageDestroy($images_fin);
     }
     $fileName = $_FILES["myfile"]["name"];
     $ret[] = $fileName;
     $data_picture = array('std_picture' => $new_images);
     $this->Students_model->update_student_picture($this->session->userdata('std_cardid'), $data_picture);
     //echo  base_url()."assets/uploads/photo/".$new_images;
     redirect('/front_profiles/student_edit', 'refresh');
     //ChromePhp::log($ret);
     //exit;
 }
예제 #6
0
function getimagesize_remote($image_url)
{
    if (($handle = @fopen($image_url, "rb")) != true) {
        return;
    }
    $contents = "";
    $count = 0;
    if ($handle) {
        do {
            $count += 1;
            $data = fread($handle, 8192);
            if (strlen($data) == 0) {
                break;
            }
            $contents .= $data;
        } while (true);
    } else {
        return false;
    }
    fclose($handle);
    $im = ImageCreateFromString($contents);
    if (!$im) {
        return false;
    }
    $gis[0] = ImageSX($im);
    $gis[1] = ImageSY($im);
    // array member 3 is used below to keep with current getimagesize standards
    $gis[3] = "width={$gis[0]} height={$gis[1]}";
    ImageDestroy($im);
    return $gis;
}
예제 #7
0
 public function fixOrientation()
 {
     if (exif_imagetype($this->image) == 2) {
         $exif = exif_read_data($this->image);
         if (array_key_exists('Orientation', $exif)) {
             $orientation = $exif['Orientation'];
             $images_orig = ImageCreateFromJPEG($this->image);
             $rotate = "";
             switch ($orientation) {
                 case 3:
                     $rotate = imagerotate($images_orig, 180, 0);
                     break;
                 case 6:
                     $rotate = imagerotate($images_orig, -90, 0);
                     break;
                 case 8:
                     $rotate = imagerotate($images_orig, 90, 0);
                     break;
             }
             if ($rotate != "") {
                 ImageJPEG($rotate, $this->image);
                 ImageDestroy($rotate);
             }
             ImageDestroy($images_orig);
         }
     }
 }
예제 #8
0
function init_resultat_election()
{
    global $image, $blanc, $noir, $gris, $gris2;
    header("Content-type: image/png");
    $annee = $_REQUEST[annee];
    $genre = $_REQUEST[genre];
    $type = $_REQUEST[type];
    $lesMiss = selectDbMiss($annee, $genre, $type, "", true);
    usort($lesMiss, "callback_sort_nb_votes");
    $nb = count($lesMiss);
    $hauteur = TAILLE_BARRE * $nb;
    $largeur = TAILLE_HAUTEUR;
    $image = ImageCreate($hauteur, $largeur);
    // On passe en blanc le fond de l'image
    $blanc = imagecolorallocate($image, 255, 255, 255);
    $noir = imagecolorallocate($image, 0, 0, 0);
    $gris = ImageColorAllocate($image, 190, 190, 190);
    $gris2 = ImageColorAllocate($image, 140, 140, 140);
    imagefilledrectangle($image, 0, 0, $largeur, $hauteur, $blanc);
    $total_votes = nombre_votes_db($annee, $genre, $type);
    dessine_nom_results_miss($lesMiss, $total_votes);
    // Génération de l'image
    ImagePng($image);
    // Desctruction de l'image
    ImageDestroy($image);
}
예제 #9
0
파일: Captcha.php 프로젝트: miaokuan/wee
 public function show()
 {
     $size = min($this->im_y, $this->im_x / $this->text_num);
     $size = ceil($size * 0.8);
     $im = imagecreatetruecolor($this->im_x, $this->im_y);
     $text_c = imagecolorallocate($im, 255, 0, 0);
     $bg_c = imagecolorallocate($im, 255, 255, 255);
     imagefill($im, 0, 0, $bg_c);
     for ($i = 0; $i < $this->text_num; $i++) {
         $ypos = $size * 1.2;
         if (preg_match('/[ygJup]/', $this->text[$i])) {
             $ypos = ceil($ypos * 0.8);
         }
         //反色
         $rnd = rand(1, $this->text_num - 1);
         if ($i % $this->text_num == $rnd) {
             imagefilledellipse($im, $this->im_x * 0.05 + $i * $size * 1.3 + $size / 2, $ypos / 2, $size * 1.2, $this->im_y * 1.1, $text_c);
             imagettftext($im, $size, 0, $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $bg_c, $this->ttf_file, $this->text[$i]);
         } else {
             imagettftext($im, $size, rand(-20, 20), $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $text_c, $this->ttf_file, $this->text[$i]);
         }
     }
     ob_clean();
     header("Content-type: image/png");
     ImagePNG($im);
     ImageDestroy($im);
     echo '= ' . base64_encode('@author:miaokuan<*****@*****.**>');
 }
예제 #10
0
 function guvenlik_resmi()
 {
     $sifre = substr(md5(rand(0, 999999999999)), -5);
     if ($sifre) {
         $this->session->set_userdata('koruma', $sifre);
         $yukseklik = 62;
         $genislik = 200;
         $resim = ImageCreate($genislik, $yukseklik);
         $siyah = ImageColorAllocate($resim, 0, 0, 0);
         $kirmizi = ImageColorAllocate($resim, 182, 16, 99);
         $beyaz = ImageColorAllocate($resim, 255, 255, 255);
         ImageFill($resim, 0, 0, $beyaz);
         $font = 'css/comic.ttf';
         $font_boyut = 24;
         $sM = 30;
         $uM = 45;
         //kullanımı
         //resim adı, font boyutu, yazının açısı, yazının soldan margini, üstten margin, renk, font adı, şifrenin hangi digitinin yazılacağı bellirtiliyor
         imagettftext($resim, $font_boyut, rand(-45, 45), $sMa = $sM, $uM, rand(0, 255), $font, $sifre[0]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[1]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[2]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[3]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[4]);
         //ImageRectangle($resim, 0, 0, $genislik-1, $yukseklik-1, $kirmizi);
         imageline($resim, 0, $yukseklik / 2, $genislik, $yukseklik / 2, $kirmizi);
         imageline($resim, $genislik / 2, 0, $genislik / 2, $yukseklik, $kirmizi);
         header("Content-Type: image/png");
         ImagePng($resim);
         ImageDestroy($resim);
     }
     exit;
 }
예제 #11
0
파일: pin.class.php 프로젝트: nanfs/lt
 function getAuthImage($text)
 {
     $this->setpin($text);
     $im_x = 160;
     $im_y = 40;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $tmpC0 = mt_rand(100, 255);
     $tmpC1 = mt_rand(100, 255);
     $tmpC2 = mt_rand(100, 255);
     $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
     imagefill($im, 16, 13, $buttum_c);
     $font = PATH_SYS_PUBLIC . 'font-awesome/fonts/verdana.ttf';
     for ($i = 0; $i < strlen($text); $i++) {
         $tmp = substr($text, $i, 1);
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //角度
         $size = 28;
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $buttum_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 160;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 30);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/JPEG");
     //以PNG格式将图像输出到浏览器或文件;
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
 }
예제 #12
0
파일: code.php 프로젝트: NingerJohn/vfinder
function create_captcha($width = 60, $height = 32)
{
    session_start();
    //生成验证码图片
    Header("Content-type: image/PNG");
    $im = imagecreate($width, $height);
    // width and height of image
    $back = ImageColorAllocate($im, 245, 245, 245);
    // specify background color
    imagefill($im, 0, 0, $back);
    // fill the background color into image
    $vcodes = "";
    srand((double) microtime() * 1000000);
    //生成4位数字
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
        // 生成随机颜色
        $authnum = rand(1, 9);
        $vcodes .= $authnum;
        imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
    }
    for ($i = 0; $i < 100; $i++) {
        // interuppting
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
        // 画像素点函数
    }
    ImagePNG($im);
    ImageDestroy($im);
    $_SESSION['captcha'] = $vcodes;
}
예제 #13
0
function JPGText($str, $fontname, $fontsize, $backcol, $txtcol)
{
    global $layout;
    Header("Last-Modified: " . gmDate("D, d M Y H:i:s", Time()) . " GMT");
    Header("Expires: " . gmDate("D, d M Y H:i:s", Time() - 3601) . " GMT");
    Header("Pragma: no-cache");
    Header("Cache-control: no-cache");
    Header("Content-Type: image/jpeg");
    $a = ImageTTFBBox($fontsize, 0, $fontname, $str);
    $width = $a[2] + 4;
    $bla = get_maximum_height($fontname, $fontsize);
    $height = $bla[0] + 3;
    $bl = $bla[1];
    $im = ImageCreate($width, $height);
    $bgcol = ImageColorAllocate($im, $backcol['red'], $backcol['green'], $backcol['blue']);
    $fgcol = ImageColorAllocate($im, $txtcol['red'], $txtcol['green'], $txtcol['blue']);
    if (!function_exists(imagegif)) {
        imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str);
        imagejpeg($im, "", 80);
    } else {
        ImageColorTransparent($im, $bgcol);
        imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str);
        imagegif($im);
    }
    ImageDestroy($im);
}
예제 #14
0
파일: image.php 프로젝트: tilitala/nForum
 public function scale($dest, $width = null, $height = null, $force = false)
 {
     $im = $this->getIm();
     if (null === $width && null === $height) {
         $w = $width = imagesx($im);
         $h = $height = imagesy($im);
     } else {
         if (false === $force) {
             $w = imagesx($im);
             $h = imagesy($im);
             if (null === $width) {
                 $width = round($w * $height / $h);
             } else {
                 if (null === $height) {
                     $height = round($h * $width / $w);
                 } else {
                     if ($w / $h > $width / $height) {
                         $height = round($h * $width / $w);
                     } else {
                         $width = round($w * $height / $h);
                     }
                 }
             }
         }
     }
     if (function_exists("imagecreatetruecolor") && ($ni = imagecreatetruecolor($width, $height))) {
         imagecopyresampled($ni, $im, 0, 0, 0, 0, $width, $height, $w, $h);
     } else {
         $ni = imagecreate($width, $height);
         imagecopyresized($ni, $im, 0, 0, 0, 0, $width, $height, $w, $h);
     }
     imagejpeg($ni, $dest);
     ImageDestroy($ni);
 }
예제 #15
0
 /**
  * Generates a random captcha image
  *
  **/
 function display($cachable = false, $urlparams = false)
 {
     // @TODO: Run some cleaning query here to clear the database.
     JTable::addIncludePath(DISCUSS_TABLES);
     $id = JRequest::getInt('captcha-id', '');
     $captcha = DiscussHelper::getTable('Captcha');
     // clearing the oudated keys.
     $captcha->clear();
     // load the captcha records.
     $captcha->load($id);
     if (!$captcha->id) {
         return false;
     }
     // @task: Generate a very random integer and take only 5 chars max.
     $hash = JString::substr(md5(rand(0, 9999)), 0, 5);
     $captcha->response = $hash;
     $captcha->store();
     // Captcha width and height
     $width = 100;
     $height = 20;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 204, 204, 204);
     ImageFill($image, 0, 0, $white);
     ImageString($image, 5, 30, 3, $hash, $black);
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
     imageline($image, 0, $height / 2, $width, $height / 2, $gray);
     imageline($image, $width / 2, 0, $width / 2, $height, $gray);
     header('Content-type: image/jpeg');
     ImageJpeg($image);
     ImageDestroy($image);
     exit;
 }
예제 #16
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreatetruecolor($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 0, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagecolortransparent($base_image, $col[0]);
     imagealphablending($base_image, true);
     imagesavealpha($base_image, true);
     //        imagefill($base_image, 0, 0, $col[0]);
     imagefill($base_image, 0, 0, 0x7fff0000);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
예제 #17
0
function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad)
{
    // obtener datos de la fotografia
    $info_original = getimagesize($img_original);
    $anchura_original = $info_original[0];
    $altura_original = $info_original[1];
    // obtener datos de la "marca de agua"
    $info_marcadeagua = getimagesize($img_marcadeagua);
    $anchura_marcadeagua = $info_marcadeagua[0];
    $altura_marcadeagua = $info_marcadeagua[1];
    // calcular la posición donde debe copiarse la "marca de agua" en la fotografia
    /* 
    // Posicion: Centrado
    $horizmargen = ($anchura_original - $anchura_marcadeagua)/2; 
    $vertmargen = ($altura_original - $altura_marcadeagua)/2; 
    */
    // Posicion: abajo a la izquierda
    $horizmargen = 10;
    $vertmargen = $altura_original - $altura_marcadeagua - 10;
    // crear imagen desde el original
    $original = ImageCreateFromJPEG($img_original);
    ImageAlphaBlending($original, true);
    // crear nueva imagen desde la marca de agua
    $marcadeagua = ImageCreateFromPNG($img_marcadeagua);
    // copiar la "marca de agua" en la fotografia
    ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua);
    // guardar la nueva imagen
    ImageJPEG($original, $img_nueva, $calidad);
    // cerrar las imágenes
    ImageDestroy($original);
    ImageDestroy($marcadeagua);
}
예제 #18
0
 function __construct($img, $dstpath, $max_width = NULL, $max_height = NULL, $quality = 100)
 {
     $this->srcimg = $img;
     $this->quality = $quality;
     $this->type = $this->checkFileType($this->srcimg);
     //更为严格的检测图片类型
     if (!in_array($this->type, $this->img_array)) {
         return '';
     }
     $this->initi_img();
     //初始化图象
     $this->dst_img($dstpath);
     //目标图象地址
     $this->width = imagesx($this->im);
     $this->height = imagesy($this->im);
     //生成缩略图的高度和宽度
     $this->resize_width = $this->width;
     $this->resize_height = $this->height;
     if (isset($max_width) && isset($max_height)) {
         $this->set_resize_size($max_width, $max_height);
         //按比例生成缩略图的尺寸
     }
     $this->newimg();
     //生成图象
     ImageDestroy($this->im);
 }
예제 #19
0
function create_captcha()
{
    session_start();
    //生成验证码图片
    Header("Content-type: image/PNG");
    $im = imagecreate(44, 18);
    // 画一张指定宽高的图片
    $back = ImageColorAllocate($im, 245, 245, 245);
    // 定义背景颜色
    imagefill($im, 0, 0, $back);
    //把背景颜色填充到刚刚画出来的图片中
    $vcodes = "";
    srand((double) microtime() * 1000000);
    //生成4位数字
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
        // 生成随机颜色
        $authnum = rand(1, 9);
        $vcodes .= $authnum;
        imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
    }
    $_SESSION['VCODE'] = $vcodes;
    for ($i = 0; $i < 100; $i++) {
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
        // 画像素点函数
    }
    ImagePNG($im);
    ImageDestroy($im);
}
예제 #20
0
function create_image()
{
    //generate a random string
    $md5_hash = md5(rand(0, 999));
    //make it 5 characters long
    $security_code = substr($md5_hash, 15, 5);
    //Storing the security code in the session
    $_SESSION["security_code"] = $security_code;
    //Create the image
    $image = @imagecreatefromjpeg("images/static.jpg");
    //Making the font color
    $black = ImageColorAllocate($image, 0, 0, 0);
    //Make the background black
    //ImageFill($image, 0, 0, $bgImg);
    //Set some variables for positioning and font-size, "5" is the largest I could get to work
    $vPos = 10;
    $hPos = 28;
    $fontSize = 5;
    ImageString($image, $fontSize, $hPos, $vPos, $security_code, $black);
    //Tell the browser what kind of file this is
    header("Content-Type: image/jpeg");
    //Output image as a jpeg
    ImageJpeg($image);
    //Free up stuff
    ImageDestroy($image);
}
예제 #21
0
 function extractAppInfo($img)
 {
     //アイコン切り出し
     $homeLeftPadding = 34;
     $homeTopPadding = 67;
     $appSideMargin = 38;
     //1列目と2列め、3列めと4列目の間のマージン
     $appCenterMargin = 40;
     //2列めと3列めの間のマージン
     $appBottomMargin = 62;
     $featurePadding = 6;
     //角丸分を削る
     for ($y = 0; $y < 4; $y++) {
         for ($x = 0; $x < 4; $x++) {
             //アイコン切り出し
             $appXAlpha = $x < 2 ? 0 : $appCenterMargin - $appSideMargin;
             $appX = $homeLeftPadding + ($x * (self::appWidth + $appSideMargin) + $appXAlpha);
             $appY = $homeTopPadding + $y * (self::appHeight + $appBottomMargin);
             $appImg = ImageCreateTrueColor(self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2);
             ImageCopyResampled($appImg, $img, 0, 0, $appX + $featurePadding, $appY + $featurePadding, self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2, self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2);
             $appIdx = $y * 4 + $x;
             $filename = "app_icon.{$appIdx}.png";
             ImagePNG($appImg, $filename);
             echo "{$filename} \n";
             //アイコンを3x3に分割して平均色を抽出、特徴量とする
             //$features = $this->calcIconImgFeature($appImg);
             ImageDestroy($appImg);
         }
     }
 }
예제 #22
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xffffff, $fore_color = 0x0)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r1 = round(($fore_color & 0xff0000) >> 16, 5);
     $b1 = round(($fore_color & 0xff00) >> 8, 5);
     $g1 = round($fore_color & 0xff, 5);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r2 = round(($back_color & 0xff0000) >> 16, 5);
     $b2 = round(($back_color & 0xff00) >> 8, 5);
     $g2 = round($back_color & 0xff, 5);
     $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2);
     $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
예제 #23
0
파일: captcha.php 프로젝트: kuell/chat
function draw_captcha($security_code)
{
    //Set the image width and height
    $width = 100;
    $height = 25;
    //Create the image resource
    $image = ImageCreate($width, $height);
    if (function_exists('imageantialias')) {
        imageantialias($image, true);
    }
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 15, 50, 15);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    $ellipsec = ImageColorAllocate($image, 0, 100, 60);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
    //Add randomly generated string in white to the image
    ImageString($image, 5, 30, 4, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
    imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
예제 #24
0
 /**
  * Generates the captcha image
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return	
  */
 public function generate()
 {
     $id = $this->input->get('id', '', 'int');
     // Load up the captcha object
     $captcha = EB::table('Captcha');
     // Clear outdated keys
     $captcha->clear();
     // load the captcha records.
     $captcha->load($id);
     if (!$captcha->id) {
         return false;
     }
     // @task: Generate a very random integer and take only 5 chars max.
     $hash = JString::substr(md5(rand(0, 9999)), 0, 5);
     $captcha->response = $hash;
     $captcha->store();
     // Captcha width and height
     $width = 100;
     $height = 20;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 204, 204, 204);
     ImageFill($image, 0, 0, $white);
     ImageString($image, 5, 30, 3, $hash, $black);
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
     imageline($image, 0, $height / 2, $width, $height / 2, $gray);
     imageline($image, $width / 2, 0, $width / 2, $height, $gray);
     header('Content-type: image/jpeg');
     ImageJpeg($image);
     ImageDestroy($image);
     exit;
 }
 function create_error($text)
 {
     $text = $text;
     $size = "8";
     $font = "classes/fonts/trebuchet.ttf";
     $TextBoxSize = imagettfbbox($size, 0, $font, preg_replace("/\\[br\\]/is", "\r\n", $text));
     $TxtBx_Lwr_L_x = $TextBoxSize[0];
     $TxtBx_Lwr_L_y = $TextBoxSize[1];
     $TxtBx_Lwr_R_x = $TextBoxSize[2];
     $TxtBx_Lwr_R_y = $TextBoxSize[3];
     $TxtBx_Upr_R_x = $TextBoxSize[4];
     $TxtBx_Upr_R_y = $TextBoxSize[5];
     $TxtBx_Upr_L_x = $TextBoxSize[6];
     $TxtBx_Upr_L_y = $TextBoxSize[7];
     $width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
     $height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
     $y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $img = imagecreate($width + 2, $height + 1);
     // Only PHP-Version 4.3.2 or higher
     if (function_exists('imageantialias')) {
         imageantialias($img, FALSE);
     }
     $white = imagecolorallocate($img, 255, 255, 255);
     $black = imagecolorallocate($img, 0, 0, 0);
     imagecolortransparent($img, $white);
     ImageTTFText($img, $size, 0, $x, $y, $black, $font, preg_replace("/<br>/is", "\r\n", $text));
     header("Content-Type: image/png");
     ImagePNG($img);
     ImageDestroy($img);
     exit;
 }
예제 #26
0
function create_image()
{
    //Let's generate a totally random string using md5
    $md5_hash = md5(rand(0, 999));
    //We don't need a 32 character long string so we trim it down to 5
    $security_code = substr($md5_hash, 15, 5);
    //Set the session to store the security code
    $_SESSION["captchaCode"] = $security_code;
    //Set the image width and height
    $width = 100;
    $height = 20;
    //Create the image resource
    $image = ImageCreate($width, $height);
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    //Add randomly generated string in white to the image
    ImageString($image, 3, 30, 3, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2, $width, $height / 2, $grey);
    imageline($image, $width / 2, 0, $width / 2, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
예제 #27
0
파일: VerifyCode.php 프로젝트: blackzw/auth
function rand_create()
{
    //通知浏览器将要输出PNG图片
    Header("Content-type: image/PNG");
    //准备好随机数发生器种子
    srand((double) microtime() * 1000000);
    //准备图片的相关参数
    $im = imagecreate(62, 20);
    $black = ImageColorAllocate($im, 0, 0, 0);
    //RGB黑色标识符
    $white = ImageColorAllocate($im, 255, 255, 255);
    //RGB白色标识符
    $gray = ImageColorAllocate($im, 200, 200, 200);
    //RGB灰色标识符
    //开始作图
    imagefill($im, 0, 0, $gray);
    while (($randval = rand() % 100000) < 10000) {
    }
    $_SESSION["login_check_num"] = $randval;
    //将四位整数验证码绘入图片
    imagestring($im, 5, 10, 3, $randval, $black);
    //加入干扰象素
    for ($i = 0; $i < 200; $i++) {
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
    }
    //输出验证图片
    ImagePNG($im);
    //销毁图像标识符
    ImageDestroy($im);
}
예제 #28
0
파일: capcha.php 프로젝트: akalend/test
function capcha($salt)
{
    srand(time());
    $md5_hash = md5(rand(0, 9999));
    $security_code = substr($md5_hash, 25, 5);
    $enc = md5($security_code . $salt);
    $_SESSION['count'] = $enc;
    $secure = $_SESSION['count'];
    // echo "--------------------------$secure<br>";
    $width = 50;
    $height = 24;
    $image = ImageCreate($width, $height);
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 100, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    ImageFill($image, 0, 0, $white);
    //Add randomly generated string in white to the image
    ImageString($image, 10, 4, 4, $security_code, $black);
    // ImageRectangle($image,0,16,$width-1,$height-1,$grey);
    imageline($image, 0, $height / 2, $width, $height / 2, $grey);
    imageline($image, $width / 2, 0, $width / 2, $height, $grey);
    header("Content-Type: image/jpeg");
    header("Cache-Control: no-cache, must-revalidate");
    ImageJpeg($image);
    ImageDestroy($image);
}
예제 #29
0
function ResizeImage($im, $maxwidth, $maxheight, $name)
{
    //取得当前图片大小
    $width = imagesx($im);
    $height = imagesy($im);
    //生成缩略图的大小
    if ($width > $maxwidth || $height > $maxheight) {
        $widthratio = $maxwidth / $width;
        $heightratio = $maxheight / $height;
        if ($widthratio < $heightratio) {
            $ratio = $widthratio;
        } else {
            $ratio = $heightratio;
        }
        $newwidth = $width * $ratio;
        $newheight = $height * $ratio;
        if (function_exists("imagecopyresampled")) {
            $newim = imagecreatetruecolor($newwidth, $newheight);
            imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        } else {
            $newim = imagecreate($newwidth, $newheight);
            imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        }
        ImageJpeg($newim, $name);
        ImageDestroy($newim);
    } else {
        ImageJpeg($im, $name);
    }
}
예제 #30
-1
 public static function ResizeImage($Img, $w)
 {
     $filename = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/" . $Img;
     $images = $filename;
     $new_images = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/thumb/" . $Img;
     //copy("/images/thumb/"$_FILES,"Photos/".$_FILES["userfile"]["name"]);
     $width = $w;
     //*** Fix Width & Heigh (Autu caculate) ***//
     $size = GetimageSize($images);
     $height = round($width * $size[1] / $size[0]);
     if ($size[0] == "250") {
         return "The logo has the right width. Doesn't make sense resize it! Good job!";
     }
     $images_orig = ImageCreateFromJPEG($images);
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     $result = ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     ImageJPEG($images_fin, $filename);
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     if ($result) {
         return "Logo resized to " . $width . "px by " . $height . "px";
     } else {
         return "mmm It looks like something unexpected just happened, ask Jose!";
     }
 }