当前位置: 首页>>代码示例>>PHP>>正文


PHP Imagejpeg函数代码示例

本文整理汇总了PHP中Imagejpeg函数的典型用法代码示例。如果您正苦于以下问题:PHP Imagejpeg函数的具体用法?PHP Imagejpeg怎么用?PHP Imagejpeg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Imagejpeg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lagBildeMedStorrelse

 private function lagBildeMedStorrelse($sti, $filnavn, $nyttFilnavn, $nyBredde, $nyHoyde)
 {
     $gammeltBilde = $sti . $filnavn;
     $bi = ImageCreateFromJPEG($gammeltBilde) or $bi = ImageCreateFromPNG($gammeltBilde) or $bi = ImageCreateFromGIF($gammeltBilde) or $bi = false;
     if ($bi) {
         $naStorrelse = @getimagesize($gammeltBilde);
         $bredde = $naStorrelse[0];
         $hoyde = $naStorrelse[1];
         $hx = 100 / ($bredde / $nyBredde) * 0.01;
         $hx = @round($hoyde * $hx);
         $wx = 100 / ($hoyde / $nyHoyde) * 0.01;
         $wx = @round($bredde * $wx);
         if ($hx < $nyHoyde) {
             $nyHoyde = 100 / ($bredde / $nyBredde) * 0.01;
             $nyHoyde = @round($hoyde * $nyHoyde);
         } else {
             $nyBredde = 100 / ($hoyde / $nyHoyde) * 0.01;
             $nyBredde = @round($bredde * $nyBredde);
         }
         $resBilde = @ImageCreateTrueColor($nyBredde, $nyHoyde);
         @ImageCopyResampled($resBilde, $bi, 0, 0, 0, 0, $nyBredde, $nyHoyde, $bredde, $hoyde);
         @Imagejpeg($resBilde, $sti . $nyttFilnavn, 50);
         return $nyttFilnavn;
     } else {
         return -1;
     }
 }
开发者ID:Jeremiah0211,项目名称:airdog,代码行数:27,代码来源:BildeendringController.php

示例2: captcha

function captcha($numchars)
{
    $vals = "ABCDEFGHIJKLMNOPQRSETUVWZYZabcdefghijklmnopqrstuvwxyz0123456789";
    $numvals = strlen($vals);
    $im = ImageCreate(38 * $numchars + 10, 40);
    $white = ImageColorAllocate($im, 0, 0, 0);
    $black = ImageColorAllocate($im, 120, 200, 68);
    srand((double) microtime() * 1000000);
    $string = "";
    ImageFill($im, 0, 0, $black);
    ImageString($im, 1, 0, 0, "Arcath.net", $white);
    for ($i = 1; $i <= $numchars; $i++) {
        $rand = rand(0, $numvals - 1);
        $out = $vals[$rand];
        $string .= $out;
        ImageString($im, rand(1, 5), $i * 38, rand(5, 25), $out, $white);
    }
    Imagejpeg($im, "images/verify.jpeg");
    ImageDestroy($im);
    return $string;
}
开发者ID:Arcath,项目名称:arcath.net-site-cms,代码行数:21,代码来源:captcha.php

示例3: create_do

 private function create_do()
 {
     $this->im = Imagecreate($this->config['width'], $this->config['height']);
     //设置背景为白色
     Imagecolorallocate($this->im, $this->config['color'][0], $this->config['color'][1], $this->config['color'][2]);
     //为此背景加个边框
     if ($this->config['boxline'] == True) {
         $bordercolor = Imagecolorallocate($this->im, 37, 37, 37);
         Imagerectangle($this->im, 0, 0, $this->config['width'] - 1, $this->config['height'] - 1, $bordercolor);
     }
     //生成验证码
     $this->create_str();
     $coder = $_SESSION[$this->config['codname']];
     //输入文字
     $fontcolor = Imagecolorallocate($this->im, 46, 46, 46);
     for ($i = 0; $i < $this->config['length']; $i++) {
         Imagestring($this->im, 5, $i * 10 + 6, rand(2, 5), $coder[$i], $fontcolor);
     }
     //加入干扰线
     $interfere = $this->config['interfere'];
     $interfere = $interfere > 30 ? "30" : $interfere;
     if (!empty($interfere) && $interfere > 1) {
         for ($i = 1; $i < $interfere; $i++) {
             $linecolor = Imagecolorallocate($this->im, rand(0, 255), rand(0, 255), rand(0, 255));
             $x = rand(1, $this->config['width']);
             $y = rand(1, $this->config['height']);
             $x2 = rand($x - 10, $x + 10);
             $y2 = rand($y - 10, $y + 10);
             Imageline($this->im, $x, $y, $x2, $y2, $linecolor);
         }
     }
     ob_clean();
     Header("Pragma:no-cache\r\n");
     Header("Cache-Control:no-cache\r\n");
     Header("Expires:0\r\n");
     Header("Content-type:Image/jpeg\r\n");
     Imagejpeg($this->im);
     Imagedestroy($this->im);
     exit;
 }
开发者ID:s137740,项目名称:lg,代码行数:40,代码来源:ValidateCode.php

示例4: forumbadge_run

function forumbadge_run()
{
    global $session;
    $acctid = httpget("acctid");
    page_header("Badge!");
    //PHP's GD class functions can create a variety of output image
    //types, this example creates a jpeg
    header("Content-Type: image/jpeg");
    //open up the image you want to put text over
    $im = ImageCreateFromPng("modules/buttonbase.png");
    //The numbers are the RGB values of the color you want to use
    $black = ImageColorAllocate($im, 0, 0, 0);
    //The canvas's (0,0) position is the upper left corner
    //So this is how far down and to the right the text should start
    $start_x = 10;
    $start_y = 20;
    $sql = "SELECT race, login, level, dragonkills FROM " . db_prefix("accounts") . " WHERE acctid = {$acctid}";
    $result = db_fetch_assoc(db_query($sql));
    $name = $result['login'];
    $race = $result['race'];
    $level = "Level " . $result['level'];
    $dragonkills = "Drive Kills: " . $result['dragonkills'];
    debug($result);
    //This writes your text on the image in 12 point using verdana.ttf
    //For the type of effects you quoted, you'll want to use a truetype font
    //And not one of GD's built in fonts. Just upload the ttf file from your
    //c: windows fonts directory to your web server to use it.
    Imagettftext($im, 10, 0, 65, 12, $black, 'modules/verdana.ttf', $name);
    Imagettftext($im, 10, 0, 65, 27, $black, 'modules/verdana.ttf', $race);
    Imagettftext($im, 10, 0, 65, 42, $black, 'modules/verdana.ttf', $level);
    Imagettftext($im, 10, 0, 65, 57, $black, 'modules/verdana.ttf', $dragonkills);
    //Creates the jpeg image and sends it to the browser
    //100 is the jpeg quality percentage
    Imagejpeg($im, '', 60);
    ImageDestroy($im);
    page_footer();
}
开发者ID:CavemanJoe,项目名称:Improbable-Island---DragonScales---DragonBones---LotGD-2.0---Season-Three,代码行数:37,代码来源:forumbadge.php

示例5: imageResize

 function imageResize()
 {
     global $engine_path, $ImageTrimX, $ImageTrimY;
     $source = $this->image;
     $newWidth = $this->newWidth;
     $newHeight = $this->newHeight;
     $imType = $this->type;
     if ($imType == "jpeg" || $imType == "pjpeg") {
         $srcImage = ImageCreateFromJPEG($source);
     } elseif ($imType == "gif") {
         $srcImage = LoadGif($source);
     } else {
         $srcImage = ImageCreateFromPNG($source);
     }
     $srcWidth = ImageSX($srcImage);
     $srcHeight = ImageSY($srcImage);
     $ratioWidth = $srcWidth / $newWidth;
     $ratioHeight = $srcHeight / $newHeight;
     if ($ratioWidth < 1 && $this->fix == "width" || $ratioHeight < 1 && $this->fix == "height") {
         $destWidth = $srcWidth;
         $destHeight = $srcHeight;
         //print "mode 1";
         //exit;
     } elseif ($ratioWidth > $ratioHeight || $ratioWidth < $ratioHeight && $this->fix != "width" || $this->fix == "height") {
         $destWidth = $srcWidth / $ratioHeight;
         $destHeight = $newHeight;
         //print "mode 2";
         //exit;
     } else {
         $destWidth = $newWidth;
         $destHeight = $srcHeight / $ratioWidth;
         //print "mode 3 $ratioHeight $ratioWidth $this->fix";
         //exit;
     }
     //$this->newWidth=$destWidth;
     //$this->newHeight=$desHeight;
     //print "$this->newWidth - $this->newHeight";
     //print $srcImage." $ratioWidth $ratioHeight $this->fix $destWidth $destHeight";
     //print "-($newHeight-$destHeight)/2";
     //exit;
     if ($newWidth != $srcWidth && $newHeight != $srcHeight && $newWidth != 160) {
         if (!strlen($ImageTrim)) {
             $ImageTrim = 2;
         }
         if ($ImageTrimY == 0) {
             $y = 0;
         } elseif ($ImageTrimY == 1) {
             $y = ($newHeight - $destHeight) / 4;
         } elseif ($ImageTrimY == 2) {
             $y = ($newHeight - $destHeight) / 2;
         } elseif ($ImageTrimY == 3) {
             $y = 3 * ($newHeight - $destHeight) / 2;
         } elseif ($ImageTrimY == 4) {
             $y = 5 * ($newHeight - $destHeight) / 2;
         }
         if ($ImageTrimX == 0) {
             $x = 0;
         } elseif ($ImageTrimX == 1) {
             $x = ($newWidth - $destWidth) / 4;
         } elseif ($ImageTrimX == 2) {
             $x = ($newWidth - $destWidth) / 2;
         } elseif ($ImageTrimX == 3) {
             $x = 3 * ($newWidth - $destWidth) / 2;
         } elseif ($ImageTrimX == 4) {
             $x = 5 * ($newWidth - $destWidth) / 2;
         }
         //print "$ImageTrimY $ImageTrimX $x $y";
         //exit;
         $destImage = imagecreatetruecolor($newWidth, $newHeight);
         imagecopyresampled($destImage, $srcImage, $x, $y, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
     } else {
         $destImage = imagecreatetruecolor($destWidth, $destHeight);
         imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
     }
     if ($this->mix) {
         $destImage = $this->mix($destImage);
     }
     $name = $engine_path . "img/small/" . $this->name;
     if ($imType == "jpeg" || $imType == "pjpeg") {
         Imagejpeg($destImage, $name);
     } elseif ($imType == "gif") {
         Imagegif($destImage, $name);
     } else {
         Imagepng($destImage, $name);
     }
     $file['tmp_name'] = $name;
     ImageDestroy($srcImage);
     ImageDestroy($destImage);
     return $file;
 }
开发者ID:dapfru,项目名称:gladiators,代码行数:90,代码来源:_cls_image.php

示例6: define

<?php

define("THUMB_MAX_HEIGHT", 75);
define("THUMB_MAX_WIDTH", 75);
if (is_file("{$image}")) {
    header("Content-type: image/jpeg");
    Header("Last-Modified: " . gmdate('D, d M Y H:i:s T', filemtime($image)));
    Header("Expires: " . gmdate('D, d M Y H:i:s T', filemtime($image) + 60 * 60 * 24 * 7));
    $src_img = imagecreatefromjpeg("{$image}");
    if (imagesx($src_img) > imagesy($src_img)) {
        $xsize = THUMB_MAX_HEIGHT;
        $ysize = intval(THUMB_MAX_WIDTH / imagesx($src_img) * imagesy($src_img));
    } else {
        $ysize = THUMB_MAX_WIDTH;
        $xsize = intval(THUMB_MAX_HEIGHT / imagesy($src_img) * imagesx($src_img));
    }
    $dst_img = @imagecreatetruecolor($xsize, $ysize);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $xsize, $ysize, imagesx($src_img), imagesy($src_img));
    Imagejpeg($dst_img);
    ImageDestroy($dst_img);
} else {
    header("HTTP/1.1 404 Not Found");
    exit;
}
?>
 
开发者ID:aklepner,项目名称:bwg,代码行数:25,代码来源:thumb.php

示例7: imagettftext

imagettftext($finalimage, 9, 0, 35, 376, $black, $font, $level . "%");
$value = array(2, 19, 7, 101, 27, 101, 27, 19);
imagefilledpolygon($finalimage, $value, 4, $red);
$value = array(7, 102, 12, 162, 27, 162, 27, 102);
imagefilledpolygon($finalimage, $value, 4, $orange);
$value = array(12, 163, 17, 221, 27, 221, 27, 163);
imagefilledpolygon($finalimage, $value, 4, $yellow);
$value = array(17, 222, 22, 281, 27, 281, 27, 222);
imagefilledpolygon($finalimage, $value, 4, $yellgr);
$value = array(22, 282, 27, 348, 27, 348, 27, 282);
imagefilledpolygon($finalimage, $value, 4, $green);
imagefilledellipse($finalimage, 65, 101, 6, 6, $red);
imagefilledellipse($finalimage, 65, 161, 6, 6, $orange);
imagefilledellipse($finalimage, 65, 221, 6, 6, $yellow);
imagefilledellipse($finalimage, 65, 281, 6, 6, $yellgr);
imagefilledellipse($finalimage, 65, 346, 6, 6, $green);
if ($t_current > $t_max) {
    $burstImg = ImageCreateFromjpeg('burst.jpg');
    $burstW = ImageSX($burstImg);
    $burstH = ImageSY($burstImg);
    ImageCopy($finalimage, $burstImg, 0, 0, 0, 0, $burstW, $burstH);
}
//Create the final image
Imagejpeg($finalimage, NULL, 99);
//Destroy de rest of images
Imagedestroy($finalimage);
Imagedestroy($thermImage);
Imagedestroy($thermbarImage);
?>
 
开发者ID:jhbsz,项目名称:ossimTest,代码行数:29,代码来源:sec_therm.php

示例8: imagecreatetruecolor

            if ($crop == 'c' and $dx > $x) {
                // scale it to tempImage
                $tempImage = imagecreatetruecolor($dx, $dy);
                ImageCopyResampled($tempImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight);
                // crop it to destImage
                $destImage = imagecreatetruecolor($x, $dy);
                imagecopy($destImage, $tempImage, 0, 0, 0, 0, $x, $dy);
                $bordercolor = ImageColorAllocate($destImage, 0, 0, 0);
                ImageRectangle($destImage, 0, 0, $x - 1, $dy - 1, $bordercolor);
                imagedestroy($tempImage);
            } else {
                $destImage = imagecreatetruecolor($dx, $dy);
                ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight);
            }
        }
        Imagejpeg($destImage, $file_cache_path, 100);
        if (prepWritableFile($file_cache_path)) {
            header("Content-type: image/jpeg");
            readfile($file_cache_path);
        } else {
            // if all caching fails, output directly
            header("Content-type: image/jpeg");
            imagejpeg($destImage);
        }
        imagedestroy($srcImage);
        imagedestroy($destImage);
    }
}
function getExtension($str)
{
    $i = strrpos($str, ".");
开发者ID:smbale,项目名称:open-social-media-toolkit,代码行数:31,代码来源:scaleImage.php

示例9: setThumbnail

 function setThumbnail($file, $upload_dir = ".", $thumbnail_upload_dir = "./thumb", $filename = "", $thumbnail_size = 250, $thumbnail_quality = 76, $limit_size = 2, $type = 1, $check = 0, $image_type = 0, $image_width = 800, $image_height = 600, $limit_length = 30)
 {
     if ($filename == "") {
         $filename = $file[name];
     }
     $img_size = $this->setFileUpload($file, $upload_dir, $filename, $limit_size, $type, $check, $image_type, $image_width, $image_height = 600, $limit_length = 30);
     //앨범에서의 썸네일 이미지를 위해 JPG GD를 사용하여 썸네일 이미지를 생성한다.
     if ($img_size[0] > $img_size[1]) {
         //가로방향 이미지
         if ($img_size[0] > $thumbnail_size) {
             $img_width = $thumbnail_size;
             $img_height = $img_size[1] * $thumbnail_size / $img_size[0];
         } else {
             $img_width = $img_size[0];
             $img_height = $img_size[1];
         }
     } else {
         //세로방향 이미지
         if ($img_size[1] > $thumbnail_size) {
             $img_width = $img_size[0] * $thumbnail_size / $img_size[1];
             $img_height = $thumbnail_size;
         } else {
             $img_width = $img_size[0];
             $img_height = $img_size[1];
         }
     }
     if ($file[type] == "image/pjpeg" && (eregi("\\.jpg\$", $file[name]) || eregi("\\.jpeg\$", $file[name])) && $this->varGDPermit[jpg] == 'Y') {
         $dst_img = ImageCreate($img_width, $img_height);
         // 위에서 계산한대로 빈 이미지 파일을 만듭니다.
         $src_img = ImageCreateFromjpeg("{$upload_dir}/{$filename}");
         // 이미지파일을 읽어들입니다.
         ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img));
         //빈 이미지에다 원본이미지를 줄여서 그립니다.
         $creat_file_name = "{$thumbnail_upload_dir}/{$filename}";
         Imagejpeg($dst_img, $creat_file_name, $thumbnail_quality);
         // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다.
     } else {
         if ($file[type] == "image/x-png" && eregi("\\.png\$", $file[name]) && $this->varGDPermit[png] == 'Y') {
             $dst_img = ImageCreate($img_width, $img_height);
             // 위에서 계산한대로 빈 이미지 파일을 만듭니다.
             $src_img = ImageCreateFrompng("{$upload_dir}/{$filename}");
             // 이미지파일을 읽어들입니다.
             ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img));
             //빈 이미지에다 원본이미지를 줄여서 그립니다.
             $creat_file_name = "{$thumbnail_upload_dir}/{$filename}";
             Imagepng($dst_img, $creat_file_name, $thumbnail_quality);
             // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다.
         } else {
             if ($file[type] == "image/gif" && eregi("\\.gif\$", $file[name]) && $this->varGDPermit[gif] == 'Y') {
                 $dst_img = ImageCreate($img_width, $img_height);
                 // 위에서 계산한대로 빈 이미지 파일을 만듭니다.
                 $src_img = ImageCreateFromgif("{$upload_dir}/{$filename}");
                 // 이미지파일을 읽어들입니다.
                 ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img));
                 //빈 이미지에다 원본이미지를 줄여서 그립니다.
                 $creat_file_name = "{$thumbnail_upload_dir}/{$filename}";
                 Imagegif($dst_img, $creat_file_name, $thumbnail_quality);
                 // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다.
             } else {
                 $this->errmsg("{$file['type']}은 GD를 지원하지 않습니다!!");
             }
         }
     }
     ImageDestroy($dst_img);
     //로드한 메모리를 비워줍니다. gd는 꼭 이걸 해주어야 합니다.
     ImageDestroy($src_img);
 }
开发者ID:jin255ff,项目名称:company_website,代码行数:67,代码来源:PublicFunction.class.php

示例10: cropped

 function cropped()
 {
     Header("Content-Type: image/jpeg");
     $_SEGS = $this->uri->ruri_to_assoc();
     $this->im = $this->gallery_model->get_data_row($_SEGS['file_id'], $_SEGS['id']);
     $width_max = 600;
     $height_max = 600;
     //echo $this->im['links'];
     $this->im = str_replace(base_url(), '', $this->im['links']);
     if (file_exists($this->im)) {
         list($width, $height, $type, $attr) = getimagesize($this->im);
         if ($width >= $height) {
             $percent = $width_max / $width;
             $width_new = $width * $percent;
             $height_new = $height * $percent;
         } else {
             $percent = $height_max / $height;
             $width_new = $width * $percent;
             $height_new = $height * $percent;
         }
     }
     //echo $percent;die;
     $new = imagecreatetruecolor($width_new, $height_new);
     $this->im = imagecreatefromjpeg($this->im);
     imagecopyresized($new, $this->im, 0, 0, 0, 0, $width_new, $height_new, $width, $height);
     Imagejpeg($new);
     ImageDestroy($new);
 }
开发者ID:viktoredz,项目名称:1nf0k35-2016,代码行数:28,代码来源:admin_content.php

示例11: resizeimage

function resizeimage($imgp, $imgw, $imgh)
{
    $imagepath = base64_decode($imgp);
    #echo '.... ' . base64_decode( $imgp );
    #flush();die(' stop!');
    # Thanks to Michał Albrecht!
    $suffix = strtolower(substr($imagepath, -4));
    $imgsize = @getimagesize($imagepath);
    # http://be.php.net/getimagesize
    $head = "Content-type: {$imgsize['mime']}";
    if ($suffix == ".gif") {
        #$head = "Content-type: image/gif";
        $img = imagecreatefromgif($imagepath);
        if (!$img) {
            brokenimage("Error loading GIF");
        }
    } else {
        if ($suffix == ".jpg" or $suffix == "jpeg") {
            #$head = "Content-type: image/jpeg";
            $img = imagecreatefromjpeg($imagepath);
            if (!$img) {
                brokenimage("Error loading JPG");
            }
        } else {
            if ($suffix == ".png") {
                #$head = "Content-type: image/png";
                $img = imagecreatefrompng($imagepath);
                if (!$img) {
                    brokenimage("Error loading PNG");
                }
            }
        }
    }
    # Resize the image
    $src_h = ImageSY($img);
    $src_w = ImageSX($img);
    $dst_img = imagecreatetruecolor($imgw, $imgh);
    imagecopyresampled($dst_img, $img, 0, 0, 0, 0, $imgw, $imgh, $src_w, $src_h);
    $img = $dst_img;
    imageinterlace($img, 1);
    imagecolortransparent($img);
    ob_start();
    if ($suffix == ".gif") {
        Imagegif($img);
    } else {
        if ($suffix == ".jpg" or $suffix == ".jpeg") {
            Imagejpeg($img, '', 80);
        } else {
            if ($suffix == ".png") {
                Imagepng($img);
            }
        }
    }
    $result = ob_get_clean();
    #ImageDestroy($img);
    $result = serialize(array($head, base64_encode($result)));
    return $result;
}
开发者ID:ndp,项目名称:aida-americas.org-src,代码行数:58,代码来源:image.php

示例12: image_handler

 public function image_handler($source_image, $destination, $tn_w = 100, $tn_h = 100, $quality = 80, $wmsource = false)
 {
     #find out what type of image this is
     $info = getimagesize($source_image);
     $imgtype = image_type_to_mime_type($info[2]);
     #assuming the mime type is correct
     switch ($imgtype) {
         case 'image/jpeg':
             $source = imagecreatefromjpeg($source_image);
             break;
         case 'image/gif':
             $source = imagecreatefromgif($source_image);
             break;
         case 'image/png':
             $source = imagecreatefrompng($source_image);
             break;
         default:
             die('Invalid image type.');
     }
     #Figure out the dimensions of the image and the dimensions of the desired thumbnail
     $src_w = imagesx($source);
     $src_h = imagesy($source);
     $src_ratio = $src_w / $src_h;
     if (empty($tn_h)) {
         $tn_h = $tn_w / $src_ratio;
     }
     if ($tn_w / $tn_h > $src_ratio) {
         $new_h = $tn_w / $src_ratio;
         $new_w = $tn_w;
     } else {
         $new_w = $tn_h * $src_ratio;
         $new_h = $tn_h;
     }
     #Do some math to figure out which way we'll need to crop the image
     #to get it proportional to the new size, then crop or adjust as needed
     $x_mid = $new_w / 2;
     $y_mid = $new_h / 2;
     $newpic = imagecreatetruecolor(round($new_w), round($new_h));
     imagecopyresampled($newpic, $source, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);
     $final = imagecreatetruecolor($tn_w, $tn_h);
     //imagecopyresampled($final, $newpic, 0, 0, 0, 0, $tn_w, $tn_h, $tn_w, $tn_h);
     imagecopyresampled($final, $newpic, 0, 0, $x_mid - $tn_w / 2, $y_mid - $tn_h / 2, $tn_w, $tn_h, $tn_w, $tn_h);
     #if we need to add a watermark
     if ($wmsource) {
         #find out what type of image the watermark is
         $info = getimagesize($wmsource);
         $imgtype = image_type_to_mime_type($info[2]);
         #assuming the mime type is correct
         switch ($imgtype) {
             case 'image/jpeg':
                 $watermark = imagecreatefromjpeg($wmsource);
                 break;
             case 'image/gif':
                 $watermark = imagecreatefromgif($wmsource);
                 break;
             case 'image/png':
                 $watermark = imagecreatefrompng($wmsource);
                 break;
             default:
                 die('Invalid watermark type.');
         }
         #if we're adding a watermark, figure out the size of the watermark
         #and then place the watermark image on the bottom right of the image
         $wm_w = imagesx($watermark);
         $wm_h = imagesy($watermark);
         imagecopy($final, $watermark, $tn_w - $wm_w, $tn_h - $wm_h, 0, 0, $tn_w, $tn_h);
     }
     return Imagejpeg($final, $destination, $quality);
 }
开发者ID:hugoboss62,项目名称:myMVC,代码行数:69,代码来源:Upload.php

示例13: func_resize_save

 public function func_resize_save($dst_file, $src_file, $save_path, $max_x, $max_y)
 {
     $img_size = getimagesize($src_file);
     $img_replace = basename($src_file);
     switch ($img_size[2]) {
         //gif
         case 1:
             $src_img = ImageCreateFromgif($src_file);
             $dst_img = ImageCreateTrueColor($max_x, $max_y);
             ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]);
             Imagegif($dst_img, $save_path . $img_replace, 100);
             break;
             //jpeg or jpg
         //jpeg or jpg
         case 2:
             $src_img = ImageCreateFromjpeg($src_file);
             $dst_img = ImageCreateTrueColor($max_x, $max_y);
             ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]);
             Imagejpeg($dst_img, $save_path . $img_replace, 100);
             break;
             //png
         //png
         case 3:
             $src_img = ImageCreateFrompng($src_file);
             $dst_img = ImageCreateTrueColor($max_x, $max_y);
             ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]);
             Imagepng($dst_img, $save_path . $img_replace, 9);
             break;
     }
     ImageDestroy($dst_img);
     ImageDestroy($src_img);
 }
开发者ID:devwit,项目名称:toonytool,代码行数:32,代码来源:lib.class.php

示例14: redimPhoto

 /**
  * redimensionne la photo 
  * 
  * @param $chemin r&eacute;pertoire de la photo 
  * @param $photo la photo que l'on souhaite redimensionner
  * @param $taille la taille d&eacute;sir&eacute; 
  */
 function redimPhoto($chemin, $photo, $taille)
 {
     //redimensionnement photo petit format
     $size = getimagesize($chemin . "o" . $photo);
     if ($size[0] > $taille || $size[1] > $taille) {
         if ($size[0] > $size[1]) {
             // largeur suprieure  la hauteur
             $wg = $taille;
             $hg = number_format($size[1] / ($size[0] / $taille), 0, ",", "");
         } else {
             // hauteur suprieure  la largeur
             $hg = $taille;
             $wg = number_format($size[0] / ($size[1] / $taille), 0, ",", "");
         }
     } else {
         $wg = $size[0];
         $hg = $size[1];
     }
     $src_img = imagecreatefromjpeg($chemin . "o" . $photo);
     $dst_img = imagecreatetruecolor($wg, $hg);
     imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $wg, $hg, $size[0], $size[1]);
     Imagejpeg($dst_img, $chemin . $photo, 100);
 }
开发者ID:rcampistron,项目名称:ParagrapheCMS,代码行数:30,代码来源:Photo.inc.php

示例15: str_replace

    $image = $_POST['image'];
    $filter_image = str_replace("data:image/png;base64,", "", $image);
    // input is in format 1,2,3...|1,2,3...|...
    if ($filter_image == $invalid) {
        $im = "";
        echo "false";
    } else {
        $im = imagecreatetruecolor(320, 240);
        foreach (explode("|", $_POST['image']) as $y => $csv) {
            foreach (explode(";", $csv) as $x => $color) {
                imagesetpixel($im, $x, $y, $color);
            }
        }
    }
} else {
    // input is in format: data:image/png;base64,...
    $image = $_POST['image'];
    $filter_image = str_replace("data:image/png;base64,", "", $image);
    if ($filter_image == $invalid) {
        $im = "";
        echo "false";
    } else {
        $im = imagecreatefrompng($_POST['image']);
    }
}
if ($im) {
    $filename = time() . $uid . ".jpg";
    $data = $FbWall->Image_Upload($uid, $filename);
    imagejpeg($im);
    Imagejpeg($im, "uploads/" . $filename);
}
开发者ID:neevan1e,项目名称:Done,代码行数:31,代码来源:webcam_image_ajax.php


注:本文中的Imagejpeg函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。