Example #1
2
function kicsinyites($forras, $kimenet, $max)
{
    if (!isset($max)) {
        $max = 120;
    }
    # maximum size of 1 side of the picture.
    $src_img = ImagecreateFromJpeg($forras);
    $oh = imagesy($src_img);
    # original height
    $ow = imagesx($src_img);
    # original width
    $new_h = $oh;
    $new_w = $ow;
    if ($oh > $max || $ow > $max) {
        $r = $oh / $ow;
        $new_h = $oh > $ow ? $max : $max * $r;
        $new_w = $new_h / $r;
    }
    // note TrueColor does 256 and not.. 8
    $dst_img = ImageCreateTrueColor($new_w, $new_h);
    /* imageantialias($dst_img, true); */
    /* ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); */
    ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
    ImageJpeg($dst_img, "{$kimenet}");
}
Example #2
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);
}
Example #3
0
 /**
  * 把图片生成缩略图1
  * @param string $srcFile	源文件			
  * @param string $dstFile	目标文件
  * @param int $dstW		目标图片宽度		
  * @param int $dstH		目标文件高度
  * @param string $dstFormat	目标文件生成的格式, 有png和jpg两种格式
  * @return 错误返回错误对象
  */
 public static function makeThumb1($srcFile, $dstFile, $dstW, $dstH, $dstFormat = "png")
 {
     //打开图片
     $data = GetImageSize($srcFile, &$info);
     switch ($data[2]) {
         case 1:
             $im = @ImageCreateFromGIF($srcFile);
             break;
         case 2:
             $im = @imagecreatefromjpeg($srcFile);
             break;
         case 3:
             $im = @ImageCreateFromPNG($srcFile);
             break;
     }
     if (!$im) {
         throw new TM_Exception(__CLASS__ . ": Create image failed");
     }
     //设定图片大小
     $srcW = ImageSX($im);
     $srcH = ImageSY($im);
     $ni = ImageCreate($dstW, $dstH);
     ImageCopyResized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
     //生成指定格式的图片
     if ($dstFormat == "png") {
         imagepng($ni, $dstFile);
     } elseif ($dstFormat == "jpg") {
         ImageJpeg($ni, $dstFile);
     } else {
         imagepng($ni, $dstFile);
     }
 }
Example #4
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);
    }
}
Example #5
0
 private function createnewpicture()
 {
     $local = $this->path_two . $this->file['name'];
     move_uploaded_file($this->file['tmp_name'], $local);
     $filename = $this->file['tmp_name'] . "/" . $this->file['name'];
     $this->location = $this->path . "/" . $this->file['name'];
     switch ($this->file['type']) {
         case 'image/jpeg':
             $src = imagecreatefromjpeg($local);
             break;
         case 'image/png':
             $src = imagecreatefrompng($local);
             break;
         case 'image/gif':
             $src = imagecreatefromgif($local);
             break;
         default:
             break;
     }
     $sx = imagesx($src);
     $sy = imagesy($src);
     $new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
     if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
         if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
             //imagejpeg($this->location);
             return true;
         }
     } else {
         return false;
     }
 }
Example #6
0
 function newimg()
 {
     //改变后的图象的比例
     $resize_ratio = $this->resize_width / $this->resize_height;
     //实际图象的比例
     $ratio = $this->width / $this->height;
     if ($this->cut == "1") {
         if ($ratio >= $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_width, $this->resize_height);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->height * $resize_ratio, $this->height);
             ImageJpeg($newimg, $this->dstimg);
         }
         if ($ratio < $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_width, $this->resize_height);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, $this->width / $resize_ratio);
             ImageJpeg($newimg, $this->dstimg);
         }
     } else {
         if ($ratio >= $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_width, $this->resize_width / $ratio);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_width / $ratio, $this->width, $this->height);
             ImageJpeg($newimg, $this->dstimg);
         }
         if ($ratio < $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_height * $ratio, $this->resize_height);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_height * $ratio, $this->resize_height, $this->width, $this->height);
             ImageJpeg($newimg, $this->dstimg);
         }
     }
 }
Example #7
0
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);
}
Example #8
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;
 }
Example #9
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;
 }
Example #10
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);
}
 function create_image($string_captcha, $width = 130, $height = 35)
 {
     //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);
     $security_code = $string_captcha;
     /* ********************************************
        Use this part if you need to Set the session 
        to store the security code                */
     $_SESSION['security_code'] = $security_code;
     $CodeInd = 0;
     $arrSecCode = array();
     $chars = preg_split('//', $security_code);
     $security_code = implode(" ", $chars);
     //Set the image width and height
     //$width = 130;
     //$height = 35;
     //Create the image resource
     $image = ImageCreate($width, $height);
     //We are making three colors, white, black and gray
     $arrB = array(0, 255, 129, 10, 48, 200, 186);
     $arrR = array(0, 255, 129, 111, 48, 210, 126);
     $arrG = array(0, 205, 139, 110, 48, 5, 186);
     $black = ImageColorAllocate($image, $arrR[rand(0, 6)], $arrG[rand(0, 6)], $arrB[rand(0, 6)]);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $grey = ImageColorAllocate($image, 175, 253, 253);
     //Make the background black
     ImageFill($image, 0, 0, $black);
     $font = 5;
     $arrSel = array(1, 2, 3, 4);
     $selectedNum = $arrSel[rand(0, 3)];
     ImageString($image, $font, 10, 10, $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);
     if ($selectedNum == 1) {
         imageline($image, 0, $height / 2, $width, $height / 5, $grey);
         imageline($image, $width / 2, 0, $width / 3, $height / 5, $grey);
         imageline($image, $width / 2, 0, $width / 10, $height, $grey);
         imageline($image, $width / 2, 0, $width / 10, $height / 6, $grey);
     }
     if ($selectedNum == 2) {
         imageline($image, $width / 1, 0, $width / 6, $height, $grey);
         imageline($image, 0, $height / 5, $width, $height / 8, $grey);
         imageline($image, 0, $height / 5, $width / 5, $height / 8, $grey);
         imageline($image, 0, $height / 3, $width, $height, $grey);
     }
     if ($selectedNum == 3) {
         imageline($image, 0, $height, $width, 0, $grey);
         imageline($image, 0, 0, $height, $height, $grey);
         imageline($image, $width / 5, 0, $width / 6, $height, $grey);
         imageline($image, $width / 4, 0, $width / 4, $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);
 }
Example #12
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);
 }
Example #13
0
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);
}
Example #14
0
function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
    if ($toFile == "") {
        $toFile = $srcFile;
    }
    $info = "";
    $data = GetImageSize($srcFile, $info);
    switch ($data[2]) {
        case 1:
            if (!function_exists("imagecreatefromgif")) {
                echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromGIF($srcFile);
            break;
        case 2:
            if (!function_exists("imagecreatefromjpeg")) {
                echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromJpeg($srcFile);
            break;
        case 3:
            $im = ImageCreateFromPNG($srcFile);
            break;
    }
    $srcW = ImageSX($im);
    $srcH = ImageSY($im);
    $toWH = $toW / $toH;
    $srcWH = $srcW / $srcH;
    if ($toWH <= $srcWH) {
        $ftoW = $toW;
        $ftoH = $ftoW * ($srcH / $srcW);
    } else {
        $ftoH = $toH;
        $ftoW = $ftoH * ($srcW / $srcH);
    }
    if ($srcW > $toW || $srcH > $toH) {
        if (function_exists("imagecreatetruecolor")) {
            @($ni = ImageCreateTrueColor($ftoW, $ftoH));
            if ($ni) {
                ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            } else {
                $ni = ImageCreate($ftoW, $ftoH);
                ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            }
        } else {
            $ni = ImageCreate($ftoW, $ftoH);
            ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
        }
        if (function_exists('imagejpeg')) {
            ImageJpeg($ni, $toFile);
        } else {
            ImagePNG($ni, $toFile);
        }
        ImageDestroy($ni);
    }
    ImageDestroy($im);
}
Example #15
0
function ResizeImage($Filename, $Thumbnail, $Size)
{
    $Path = pathinfo($Filename);
    $Extension = $Path['extension'];
    $ImageData = @GetImageSize($Filename);
    $Width = $ImageData[0];
    $Height = $ImageData[1];
    if ($Width >= $Height and $Width > $Size) {
        $NewWidth = $Size;
        $NewHeight = $Size / $Width * $Height;
    } elseif ($Height >= $Width and $Height > $Size) {
        $NewWidth = $Size / $Height * $Width;
        $NewHeight = $Size;
    } else {
        $NewWidth = $Width;
        $NewHeight = $Height;
    }
    $NewImage = @ImageCreateTrueColor($NewWidth, $NewHeight);
    if (preg_match('/^gif$/i', $Extension)) {
        $Image = @ImageCreateFromGif($Filename);
    } elseif (preg_match('/^png$/i', $Extension)) {
        $Image = @ImageCreateFromPng($Filename);
    } else {
        $Image = @ImageCreateFromJpeg($Filename);
    }
    if ($ImageData[2] == IMAGETYPE_GIF or $ImageData[2] == IMAGETYPE_PNG) {
        $TransIndex = imagecolortransparent($Image);
        // If we have a specific transparent color
        if ($TransIndex >= 0) {
            // Get the original image's transparent color's RGB values
            $TransColor = imagecolorsforindex($Image, $TransIndex);
            // Allocate the same color in the new image resource
            $TransIndex = imagecolorallocate($NewImage, $TransColor['red'], $TransColor['green'], $TransColor['blue']);
            // Completely fill the background of the new image with allocated color.
            imagefill($NewImage, 0, 0, $TransIndex);
            // Set the background color for new image to transparent
            imagecolortransparent($NewImage, $TransIndex);
        } elseif ($ImageData[2] == IMAGETYPE_PNG) {
            // Turn off transparency blending (temporarily)
            imagealphablending($NewImage, false);
            // Create a new transparent color for image
            $color = imagecolorallocatealpha($NewImage, 0, 0, 0, 127);
            // Completely fill the background of the new image with allocated color.
            imagefill($NewImage, 0, 0, $color);
            // Restore transparency blending
            imagesavealpha($NewImage, true);
        }
    }
    @ImageCopyResampled($NewImage, $Image, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
    if (preg_match('/^gif$/i', $Extension)) {
        @ImageGif($NewImage, $Thumbnail);
    } elseif (preg_match('/^png$/i', $Extension)) {
        @ImagePng($NewImage, $Thumbnail);
    } else {
        @ImageJpeg($NewImage, $Thumbnail);
    }
    @chmod($Thumbnail, 0644);
}
Example #16
0
function imgUpload($attr)
{
    $path_big = $_SERVER['DOCUMENT_ROOT'] . "/activities";
    $path_thumbs = $_SERVER['DOCUMENT_ROOT'] . "/activities/thumbs";
    $img_thumb_width = 160;
    //
    $extlimit = "yes";
    //Limit allowed extensions? (no for all extensions allowed)
    $limitedext = array(".gif", ".jpg", ".png", ".jpeg", ".bmp");
    $file_type = $attr['type'];
    $file_name = $attr['name'];
    $file_size = $attr['size'];
    $file_tmp = $attr['tmp_name'];
    if (!is_uploaded_file($file_tmp)) {
        echo "Error: Please select a file to upload!. <br>--<a href=\"{$_SERVER['PHP_SELF']}\">back</a>";
    }
    $ext = strrchr($file_name, '.');
    $ext = strtolower($ext);
    if ($extlimit == "yes" && !in_array($ext, $limitedext)) {
        echo "Wrong file extension.  <br>--<a href=\"{$_SERVER['PHP_SELF']}\">back</a>";
    }
    $getExt = explode('.', $file_name);
    $file_ext = $getExt[count($getExt) - 1];
    $rand_name = md5(time());
    $rand_name = rand(0, 999999999);
    $ThumbWidth = $img_thumb_width;
    if ($file_size) {
        if ($file_type == "image/pjpeg" || $file_type == "image/jpeg") {
            $new_img = imagecreatefromjpeg($file_tmp);
        } elseif ($file_type == "image/x-png" || $file_type == "image/png") {
            $new_img = imagecreatefrompng($file_tmp);
        } elseif ($file_type == "image/gif") {
            $new_img = imagecreatefromgif($file_tmp);
        }
        list($width, $height) = getimagesize($file_tmp);
        $imgratio = $width / $height;
        if ($imgratio > 1) {
            $newwidth = $ThumbWidth;
            $newheight = $ThumbWidth / $imgratio;
        } else {
            $newheight = $ThumbWidth;
            $newwidth = $ThumbWidth * $imgratio;
        }
        if (function_exists(imagecreatetruecolor)) {
            $resized_img = imagecreatetruecolor($newwidth, $newheight);
        } else {
            die("Error: Please make sure you have GD library ver 2+");
        }
        imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        ImageJpeg($resized_img, "{$path_thumbs}/{$rand_name}.{$file_ext}");
        ImageDestroy($resized_img);
        ImageDestroy($new_img);
    }
    move_uploaded_file($file_tmp, "{$path_big}/{$rand_name}.{$file_ext}");
    return "{$rand_name}.{$file_ext}";
}
Example #17
0
function scale($img, $maxwidth, $maxheight)
{
    $imginfo = getimagesize($img);
    $imgwidth = $imginfo[0];
    $imgheight = $imginfo[1];
    if ($imgwidth > $maxwidth) {
        $ration = $maxwidth / $imgwidth;
        $newwidth = round($imgwidth * $ration);
        $newheight = round($imgheight * $ration);
        if ($newheight > $maxheight) {
            $ration = $maxheight / $newheight;
            $newwidth = round($newwidth * $ration);
            $newheight = round($newheight * $ration);
            $dst_img = ImageCreateTrueColor($newwidth, $newheight);
            $image = imagecreatefromjpeg($img);
            ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
            ImageJpeg($dst_img, $img, 90);
            ImageDestroy($dst_img);
        } else {
            $dst_img = ImageCreateTrueColor($newwidth, $newheight);
            $image = imagecreatefromjpeg($img);
            ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
            ImageJpeg($dst_img, $img, 90);
            ImageDestroy($dst_img);
        }
    } else {
        if ($imgheight > $maxheight) {
            $ration = $maxheight / $imgheight;
            $newwidth = round($imgwidth * $ration);
            $newheight = round($imgheight * $ration);
            if ($newwidth > $maxwidth) {
                $ration = $maxwidth / $newwidth;
                $newwidth = round($newwidth * $ration);
                $newheight = round($newheight * $ration);
                $dst_img = ImageCreateTrueColor($newwidth, $newheight);
                $image = imagecreatefromjpeg($img);
                ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
                ImageJpeg($dst_img, $img, 90);
                ImageDestroy($dst_img);
            } else {
                $dst_img = ImageCreateTrueColor($newwidth, $newheight);
                $image = imagecreatefromjpeg($img);
                ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
                ImageJpeg($dst_img, $img, 90);
                ImageDestroy($dst_img);
            }
        } else {
            $dst_img = ImageCreateTrueColor($newwidth, $newheight);
            $image = imagecreatefromjpeg($img);
            ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
            ImageJpeg($dst_img, $img, 90);
            ImageDestroy($dst_img);
        }
    }
}
Example #18
0
function ResizeImage($imgPath, $maxwidth, $maxheight, $name)
{
    $ary = explode(".", $imgPath);
    $ext = $ary[count($ary) - 1];
    if ($ext == "jpg" || $ext == "jepg") {
        $im = imagecreatefromjpeg($imgPath);
    } elseif ($ext == "png") {
        $im = imagecreatefrompng($imgPath);
    } elseif ($ext == "gif") {
        $im = imagecreatefromgif($imgPath);
    }
    if ($im) {
        if (file_exists("{$name}.jpg")) {
            unlink("{$name}.jpg");
        }
        $width = imagesx($im);
        $height = imagesy($im);
        if ($maxwidth && $width > $maxwidth || $maxheight && $height > $maxheight) {
            if ($maxwidth && $width > $maxwidth) {
                $widthratio = $maxwidth / $width;
                $RESIZEWIDTH = true;
            }
            if ($maxheight && $height > $maxheight) {
                $heightratio = $maxheight / $height;
                $RESIZEHEIGHT = true;
            }
            if ($RESIZEWIDTH && $RESIZEHEIGHT) {
                if ($widthratio < $heightratio) {
                    $ratio = $widthratio;
                } else {
                    $ratio = $heightratio;
                }
            } elseif ($RESIZEWIDTH) {
                $ratio = $widthratio;
            } elseif ($RESIZEHEIGHT) {
                $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 . ".jpg");
            ImageDestroy($newim);
        } else {
            ImageJpeg($im, $name . ".jpg");
        }
        ImageDestroy($im);
    }
    return $name . ".jpg";
}
Example #19
0
 public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
 {
     $image = self::image($frame, $pixelPerPoint, $outerFrame);
     if ($filename === false) {
         Header("Content-type: image/jpeg");
         ImageJpeg($image, null, $q);
     } else {
         ImageJpeg($image, $filename, $q);
     }
     ImageDestroy($image);
 }
Example #20
0
function jpeg($panels, $name)
{
    if (count($panels) > 0) {
        echo "Les images générées vont être enregistrées au format JPEG.\n";
    }
    $i = 0;
    while (isset($panels[$i])) {
        ImageJpeg($panels[$i], $name . $i . ".jpeg");
        $i++;
    }
}
Example #21
0
 private static function img_resizer($src, $quality, $w, $h, $saveas)
 {
     /* v2.5 with auto crop */
     $r = 1;
     $e = strtolower(substr($src, strrpos($src, ".") + 1, 3));
     if ($e == "jpg" || $e == "jpeg") {
         $OldImage = imagecreatefromjpeg($src) or $r = 0;
     } elseif ($e == "gif") {
         $OldImage = ImageCreateFromGif($src) or $r = 0;
     } elseif ($e == "bmp") {
         $OldImage = ImageCreateFromwbmp($src) or $r = 0;
     } elseif ($e == "png") {
         $OldImage = ImageCreateFromPng($src) or $r = 0;
     } else {
         _o("No es una imagen v&aacute;lida! (" . $e . ") -- " . $src);
         $r = 0;
     }
     if ($r) {
         list($width, $height) = getimagesize($src);
         // check if ratios match
         $_ratio = array($width / $height, $w / $h);
         if ($_ratio[0] != $_ratio[1]) {
             // crop image
             // find the right scale to use
             $_scale = min((double) ($width / $w), (double) ($height / $h));
             // coords to crop
             $cropX = (double) ($width - $_scale * $w);
             $cropY = (double) ($height - $_scale * $h);
             // cropped image size
             $cropW = (double) ($width - $cropX);
             $cropH = (double) ($height - $cropY);
             $crop = ImageCreateTrueColor($cropW, $cropH);
             // crop the middle part of the image to fit proportions
             ImageCopy($crop, $OldImage, 0, 0, (int) ($cropX / 2), (int) ($cropY / 2), $cropW, $cropH);
         }
         // do the thumbnail
         $NewThumb = ImageCreateTrueColor($w, $h);
         if (isset($crop)) {
             // been cropped
             ImageCopyResampled($NewThumb, $crop, 0, 0, 0, 0, $w, $h, $cropW, $cropH);
             ImageDestroy($crop);
         } else {
             // ratio match, regular resize
             ImageCopyResampled($NewThumb, $OldImage, 0, 0, 0, 0, $w, $h, $width, $height);
         }
         _ckdir($saveas);
         ImageJpeg($NewThumb, $saveas, $quality);
         ImageDestroy($NewThumb);
         ImageDestroy($OldImage);
     }
     return $r;
 }
Example #22
0
 public function FlushObject()
 {
     if ($this->mStyle & BCS_BORDER) {
         $this->DrawBorder();
     }
     if ($this->mStyle & BCS_IMAGE_PNG) {
         ImagePng($this->mImg);
     } else {
         if ($this->mStyle & BCS_IMAGE_JPEG) {
             ImageJpeg($this->mImg);
         }
     }
 }
Example #23
0
function createImage()
{
    $imageString = $_GET['type'];
    $length = strlen($imageString);
    $max = 6;
    $x = ($max - $length) * 7;
    $image = ImageCreateFromJpeg("../images/file_manager_file.jpg");
    $black = ImageColorAllocate($image, 0, 0, 0);
    ImageString($image, 6, $x, 45, $imageString, $black);
    header("Content-Type: image/jpeg");
    ImageJpeg($image);
    ImageDestroy($image);
}
Example #24
0
 function grip($K, $OldImageFile, $NewImageFile)
 {
     $WidthAndHeight = getimagesize($OldImageFile);
     $Width = $WidthAndHeight[0];
     $Height = $WidthAndHeight[1];
     $NewWidth = ceil($Width * $K);
     $NewHeight = ceil($Height * $K);
     $src = ImageCreateFromJpeg($OldImageFile);
     $dst = imagecreatetruecolor($NewWidth, $NewHeight);
     ImageCopyResampled($dst, $src, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
     ImageJpeg($dst, $NewImageFile, 80);
     ImageDestroy($src);
     ImageDestroy($dst);
 }
Example #25
0
	/**
	 * Generates a random captcha image
	 *
	 **/
	function display($cachable = false, $urlparams = false)
	{
		$id			= JRequest::getInt( 'captcha-id' , '' );
		$captcha	= Komento::getTable( 'Captcha' , 'KomentoTable' );

		if( ob_get_length() !== false )
		{
			while (@ ob_end_clean());
			if( function_exists( 'ob_clean' ) )
			{
				@ob_clean();
			}
		}

		// 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;
	}
Example #26
0
function create_image()
{
    $hack = "fantastic@hackerfantastic:~\$ nmap -n " . $_SERVER['REMOTE_ADDR'];
    $hack2 = "Starting Nmap 4.62 ( http://nmap.org ) at 2009-07-10 08:32 UTC";
    $hack3 = "Interesting ports on " . $_SERVER['REMOTE_ADDR'] . ":";
    $hack4 = "Not shown: 1712 closed ports";
    $hack5 = "PORT      STATE SERVICE";
    $hack6 = "22/tcp    open  ssh";
    $hack7 = "Nmap done: 1 IP address (1 host up) scanned in 0.960 seconds";
    $hack8 = "fantastic@hackerfantastic:~\$ ./0pen0wn -h " . $_SERVER['REMOTE_ADDR'] . " -p 22";
    $hack9 = "[+] 0wn0wn . anti-sec group (priv8 release)";
    $hacka = "[+] Target: " . $_SERVER['REMOTE_ADDR'];
    $hackb = "[+] SSH Port: 22 ";
    $hackc = "[-] GOBBLE!GOBBLE!";
    $hackd = "sh-3.2# uname";
    $hacke = "Linux";
    $hackf = "sh-3.2# id";
    $hack10 = "uid=0(root) gid=0(root) groups=0(root)";
    $hack11 = "sh-3.2# rm -rf / 2>/dev/null";
    $hack12 = "sh-3.2# ";
    $width = 667;
    $height = 420;
    $image = ImageCreate($width, $height);
    $image = imagecreatefromjpeg("./background.jpg");
    $green = ImageColorAllocate($image, 0, 255, 51);
    $black = ImageColorAllocate($image, 0, 0, 0);
    ImageString($image, 3, 10, 33, $hack, $green);
    ImageString($image, 3, 10, 57, $hack2, $green);
    // 27
    ImageString($image, 3, 10, 69, $hack3, $green);
    ImageString($image, 3, 10, 81, $hack4, $green);
    ImageString($image, 3, 10, 93, $hack5, $green);
    ImageString($image, 3, 10, 105, $hack6, $green);
    ImageString($image, 3, 10, 129, $hack7, $green);
    ImageString($image, 3, 10, 141, $hack8, $green);
    ImageString($image, 3, 10, 153, $hack9, $green);
    ImageString($image, 3, 10, 165, $hacka, $green);
    ImageString($image, 3, 10, 177, $hackb, $green);
    ImageString($image, 3, 10, 189, $hackc, $green);
    ImageString($image, 3, 10, 213, $hackd, $green);
    ImageString($image, 3, 10, 225, $hacke, $green);
    ImageString($image, 3, 10, 237, $hackf, $green);
    ImageString($image, 3, 10, 249, $hack10, $green);
    ImageString($image, 3, 10, 261, $hack11, $green);
    ImageString($image, 3, 10, 273, $hack12, $green);
    header("Content-Type: image/jpeg");
    ImageJpeg($image);
    ImageDestroy($image);
}
Example #27
0
 /**
  * @param $frame
  * @param bool $filename
  * @param int $pixelPerPoint
  * @param int $outerFrame
  * @param bool $saveAndPrint
  * @param RgbColor $fgColor
  * @param RgbColor $bgColor
  * @param int $q
  */
 public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $saveAndPrint = false, RgbColor $fgColor = null, RgbColor $bgColor = null, $q = 85)
 {
     $image = static::image($frame, $pixelPerPoint, $outerFrame, $fgColor, $bgColor);
     if ($filename === false) {
         Header("Content-type: image/jpeg");
         ImageJpeg($image, null, $q);
     } else {
         ImageJpeg($image, $filename, $q);
         if ($saveAndPrint === true) {
             Header("Content-type: image/jpeg");
             ImageJpeg($image, null, $q);
         }
     }
     ImageDestroy($image);
 }
Example #28
0
function ShowImageHeader($ImageHandle)
{
    if (ImageTypes() & IMG_PNG) {
        Header("Content-type: image/png");
        ImagePng($ImageHandle);
    } elseif (ImageTypes() & IMG_GIF) {
        Header("Content-type: image/gif");
        ImageGif($ImageHandle);
    } elseif (ImageTypes() & IMG_JPEG) {
        Header("Content-type: image/jpeg");
        ImageJpeg($ImageHandle, "", 0.5);
    } else {
        die("No images support");
    }
    ImageDestroy($ImageHandle);
}
Example #29
0
function create_image()
{
    $md5_hash = md5(rand(0, 999));
    $code = substr($md5_hash, 15, 5);
    $_SESSION["code"] = $code;
    $width = 100;
    $height = 30;
    $image = ImageCreate($width, $height);
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    ImageFill($image, 0, 0, $black);
    ImageString($image, 5, 30, 6, $code, $white);
    header("Content-Type: image/jpeg");
    ImageJpeg($image);
    ImageDestroy($image);
}
Example #30
0
 public function create_image()
 {
     $md5_hash = md5(rand(0, 999));
     $security_code = substr($md5_hash, 15, 5);
     $_SESSION['security_code'] = $security_code;
     $width = 80;
     $height = 25;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     ImageFill($image, 0, 0, $black);
     ImageString($image, 5, 20, 5, $security_code, $white);
     header("Content-Type: image/jpeg");
     ImageJpeg($image);
     ImageDestroy($image);
 }