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


PHP Imagepng函数代码示例

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


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

示例1: createnewpicture

 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;
     }
 }
开发者ID:JiaJia01,项目名称:homework_09,代码行数:31,代码来源:picture.php

示例2: display

 function display($db_object, $common, $user_id, $default, $error_msg, $learning, $post_var)
 {
     $width = 340;
     $height = 220;
     //	$labelfont = '2';
     $labeltitlefont = '3';
     $image = ImageCreate($width, $height);
     while (list($kk, $vv) = @each($post_var)) {
         ${$kk} = $vv;
     }
     /*
     $to_date=2004-01-02;
     $from_date=2004-01-02;
     $avg_rater=50.23;
     */
     $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff);
     $border = ImageColorAllocate($image, 0x0, 0x0, 0x0);
     $border1 = ImageColorAllocate($image, 0xcccccc, 0x0, 0x0);
     //$border2 = ImageColorAllocate($image,0x000000, 0xcccccc, 0x000000);
     ImageRectangle($image, 40, 20, 240, 160, $border);
     ImageString($image, $labelfont, 15, 20, "100%", $border);
     ImageString($image, $labelfont, 20, 55, "75%", $border);
     ImageString($image, $labelfont, 20, 90, "50%", $border);
     ImageString($image, $labelfont, 20, 125, "25%", $border);
     ImageString($image, $labelfont, 20, 155, "0%", $border);
     $fdate = $learning->changedate_display($from_date);
     $tdate = $learning->changedate_display($to_date);
     $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} ";
     $avg_rt = @explode(",", $avg_rater);
     $id = @explode(",", $ids);
     for ($i = 0; $i < count($avg_rt); $i++) {
         $p1 = rand(0, 200);
         $p2 = rand(30, 250);
         $p3 = rand(100, 250);
         $color = imagecolorallocate($image, $p1, $p2, $p3);
         $avg = $avg_rt[$i];
         $avg_comp = 160 - 140 / 100 * $avg;
         $avg = round($avg, 2);
         $rid = $id[$i];
         $rname = $common->name_display($db_object, $rid);
         ImageStringUp($image, $labeltitlefont, 5, 110, $error_msg['cResults'], $border);
         ImageString($image, $labeltitlefont, 245, 20, $error_msg['cCommitment'], $border);
         ImageString($image, $labeltitlefont, 50, 170, "{$days}", $border);
         //ImageString($image, $labeltitlefont, 50,180, "$rname", $color);
         ImageLine($image, 240, 20, 40, 160, $border1);
         //COMMITMENT LINE
         ImageLine($image, 240, $avg_comp, 40, 160, $color);
         //AVERAGE COMPLETION
         header("Content-type: image/png");
         // or "Content-type: image/png"
         Imagepng($image);
         // or imagepng($image)
     }
     ImageDestroy($image);
 }
开发者ID:nloadholtes,项目名称:people-prodigy,代码行数:55,代码来源:graph_learning_status.php

示例3: setimg

 public function setimg($img, $age, $gender, $score, $infos, $res, $skin, $huitou, $target, $types)
 {
     $dst = "/mnt/meilimei/m/upload/mojokbg.png";
     //得到原始图片信息
     $dst_im = imagecreatefrompng($dst);
     $dst_info = getimagesize($dst);
     //水印图像
     $src = "/mnt/meilimei/m/upload/mojokbg2.png";
     $src_im = imagecreatefrompng($src);
     $src_info = getimagesize($src);
     if ($types == 'image/png') {
         $im = imagecreatefrompng($img);
         //imagecreatefrompng
     } elseif ($types == 'image/jpeg') {
         $im = imagecreatefromjpeg($img);
     } elseif ($types == 'image/gif') {
         $im = imagecreatefromgif($img);
     } elseif ($types == 'image/bmp') {
         $im = imagecreatefromwbmp($img);
     }
     $im_src = getimagesize($img);
     $temp_img = imagecreatetruecolor(320, 480);
     //创建画布
     //$im=create($src);
     imagecopyresampled($temp_img, $im, 0, 0, 0, 0, 226, 313, $im_src[0], $im_src[1]);
     //人脸
     $alpha = 100;
     imagecopy($dst_im, $temp_img, 48, 75, 0, 0, 226, 313);
     //后人脸
     imagecopy($dst_im, $src_im, 45, 72, 0, 0, 237, 323);
     //背景
     //$im = imagecreate(400 , 300);
     $gray = ImageColorAllocate($dst_im, 255, 255, 255);
     $pink = ImageColorAllocate($dst_im, 246, 109, 152);
     $fontfilebold = "/mnt/meilimei/m/upload/msyhbd.ttf";
     $fontfile = "/mnt/meilimei/m/upload/msyh.ttf";
     $str = iconv('GB2312', 'UTF-8', $huitou . '%');
     $str1 = $infos;
     $str2 = iconv('GB2312', 'UTF-8', $skin);
     $str3 = iconv('GB2312', 'UTF-8', $score);
     $str4 = iconv('GB2312', 'UTF-8', $age);
     ImageTTFText($dst_im, 22, 0, 175, 40, $gray, $fontfilebold, $str);
     ImageTTFText($dst_im, 11, 0, 50, 65, $gray, $fontfile, $str1);
     ImageTTFText($dst_im, 19, 0, 67, 225, $pink, $fontfilebold, $str2);
     ImageTTFText($dst_im, 19, 0, 67, 273, $pink, $fontfilebold, $str3);
     ImageTTFText($dst_im, 19, 0, 67, 320, $pink, $fontfilebold, $str4);
     imagesavealpha($src_im, true);
     imagesavealpha($dst_im, true);
     Imagepng($dst_im, "/mnt/meilimei/m/upload/webmojing/" . date('Y') . '/' . date('m') . '/' . $target . ".jpg");
     return ImageDestroy($dst_im);
 }
开发者ID:sexseses,项目名称:meilimei_old_api,代码行数:51,代码来源:mojing.php

示例4: img

function img($text)
{
    $img_height = 50;
    $img_width = 18;
    $img = imagecreate($img_height, $img_width);
    ImageColorAllocate($img, 255, 255, 255);
    $black = ImageColorAllocate($img, 0, 0, 0);
    for ($i = 0; $i < 10; $i++) {
        ImageString($img, 1, mt_rand(1, $img_height), mt_rand(0, $img_width), "Q", imageColorAllocate($img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)));
    }
    ImageRectangle($img, 0, 0, $img_height - 1, $img_width - 1, $black);
    //
    Imagestring($img, 5, 5, 2, $text, imageColorAllocate($img, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)));
    Imagepng($img);
    ImageDestroy($img);
}
开发者ID:jyyy410team,项目名称:hts,代码行数:16,代码来源:getcodes.php

示例5: display

 function display($db_object, $common, $user_id, $default, $error_msg, $learning, $post_var)
 {
     $width = 340;
     $height = 220;
     //	$labelfont = '2';
     $labeltitlefont = '3';
     $image = ImageCreate($width, $height);
     while (list($kk, $vv) = @each($post_var)) {
         ${$kk} = $vv;
     }
     $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff);
     $border = ImageColorAllocate($image, 0x0, 0x0, 0x0);
     $border1 = ImageColorAllocate($image, 0xcccccc, 0x0, 0x0);
     $border2 = ImageColorAllocate($image, 0x0, 0xcccccc, 0x0);
     ImageRectangle($image, 40, 20, 240, 160, $border);
     ImageString($image, $labelfont, 15, 20, "100%", $border);
     ImageString($image, $labelfont, 20, 55, "75%", $border);
     ImageString($image, $labelfont, 20, 90, "50%", $border);
     ImageString($image, $labelfont, 20, 125, "25%", $border);
     ImageString($image, $labelfont, 20, 155, "0%", $border);
     $fdate = $learning->changedate_display($from_date);
     $tdate = $learning->changedate_display($to_date);
     $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} ";
     $avg_comp = 160 - 140 / 100 * $avg;
     $avg = round($avg, 2);
     ImageStringUp($image, $labeltitlefont, 5, 110, $error_msg['cResults'], $border);
     ImageString($image, $labeltitlefont, 245, 20, $error_msg['cCommitment'], $border);
     ImageString($image, $labeltitlefont, 50, 170, "{$days}", $border);
     ImageString($image, $labeltitlefont, 50, 200, $error_msg['cCTimelyCompletionofActivities'], $border);
     ImageString($image, $labeltitlefont, 50, 185, $error_msg['cAverage'], $border);
     ImageString($image, $labeltitlefont, 115, 185, $avg, $border);
     ImageLine($image, 240, 20, 40, 160, $border1);
     //COMMITMENT LINE
     ImageLine($image, 240, $avg_comp, 40, 160, $border2);
     //AVERAGE COMPLETION
     ImageString($image, $labeltitlefont, 245, $avg_comp, $error_msg['cAccomplishment'], $border);
     header("Content-type: image/png");
     // or "Content-type: image/png"
     Imagepng($image);
     // or imagepng($image)
     ImageDestroy($image);
 }
开发者ID:nloadholtes,项目名称:people-prodigy,代码行数:42,代码来源:graph_results.php

示例6: createCaptcha

 /**
  * @throws Exception
  * 生成验证码 , 存放到token相对应的session里面
  */
 public function createCaptcha()
 {
     $token = $_COOKIE["token"];
     if (empty($token)) {
         throw new Exception("无法生产验证码,请稍后在试");
     }
     $string = "abcdefghijklmnopqrstuvwxyz0123456789";
     $str = "";
     for ($i = 0; $i < 4; $i++) {
         $pos = rand(0, 35);
         $str .= $string[$pos];
     }
     $this->load->library('session');
     $flag = $this->session->set_userdata($token . "_captcha", $str);
     $img_handle = Imagecreate(80, 20);
     //图片大小80X20
     $back_color = ImageColorAllocate($img_handle, 255, 255, 255);
     //背景颜色(白色)
     $txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
     //文本颜色(黑色)
     //加入干扰线
     for ($i = 0; $i < 3; $i++) {
         $line = ImageColorAllocate($img_handle, rand(0, 255), rand(0, 255), rand(0, 255));
         Imageline($img_handle, rand(0, 15), rand(0, 15), rand(100, 150), rand(10, 50), $line);
     }
     //加入干扰象素
     for ($i = 0; $i < 200; $i++) {
         $randcolor = ImageColorallocate($img_handle, rand(0, 255), rand(0, 255), rand(0, 255));
         Imagesetpixel($img_handle, rand() % 100, rand() % 50, $randcolor);
     }
     Imagefill($img_handle, 0, 0, $back_color);
     //填充图片背景色
     ImageString($img_handle, 28, 20, 0, $str, $txt_color);
     //水平填充一行字符串
     ob_clean();
     // ob_clean()清空输出缓存区
     header("Content-type: image/png");
     //生成验证码图片
     Imagepng($img_handle);
     //显示图片
 }
开发者ID:baiyk,项目名称:medicalProject,代码行数:45,代码来源:Verify_model.php

示例7: _output_image

 function _output_image($destination_file, $image_type, $image)
 {
     //if destination file is empty image will be output to browser
     // right now $image_type can be JPEG or PNG
     global $ERR, $create_text;
     $destination_file = trim($destination_file);
     $res = false;
     //Create Text
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $red = ImageColorAllocate($image, 255, 0, 0);
     $blue = ImageColorAllocate($image, 0, 0, 255);
     $lightblue = ImageColorAllocate($image, 0, 128, 255);
     $green = ImageColorAllocate($image, 0, 255, 0);
     $violet = ImageColorAllocate($image, 225, 128, 225);
     $orange = ImageColorAllocate($image, 255, 128, 0);
     $gray = ImageColorAllocate($image, 192, 192, 192);
     $pink = ImageColorAllocate($image, 255, 0, 128);
     $brown = ImageColorAllocate($image, 128, 0, 0);
     $darkgreen = ImageColorAllocate($image, 0, 128, 0);
     ImageString($image, 3, 2, 1, $create_text, $white);
     if ($image) {
         switch ($image_type) {
             case 'JPEG':
             case 'JPG':
                 $res = ImageJpeg($image, $destination_file, $this->jpeg_quality);
                 break;
             case 'PNG':
                 $res = Imagepng($image, $destination_file);
                 break;
             default:
                 $this->error($ERR["UNKNOWN_OUTPUT_FORMAT"] . " {$image_type}");
                 break;
         }
     } else {
         $this->error($ERR["NO_IMAGE_FOR_OUTPUT"]);
     }
     if (!$res) {
         $this->error($ERR["UNABLE_TO_OUTPUT"] . " {$destination_file}");
     }
     return $res;
 }
开发者ID:robocon,项目名称:maxsite,代码行数:42,代码来源:class.resizepic.php

示例8: Imagegif

        $img = Imagegif($dst_img, '', $_quality_);
        $ob_contents = ob_get_contents();
        // Save file
        $fp = fopen("{$path}", 'wb');
        fwrite($fp, $ob_contents);
        fclose($fp);
        ob_end_flush();
    }
}
if (substr($_GET['img'], -3) == "png") {
    header("Content-type: image/png");
    if (file_exists($path)) {
        echo file_get_contents($path);
    } else {
        if (strnatcmp(phpversion(), '4.3.0') > 0) {
            $_quality_ = (int) ($_quality_ / 10);
        }
        $src_img = ImageCreateFromPng($_image_);
        $dst_img = imagecreatetruecolor($new_w, $new_h);
        ImagePaletteCopy($dst_img, $src_img);
        ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
        ob_start();
        $img = Imagepng($dst_img, '', $_quality_);
        $ob_contents = ob_get_contents();
        // Save file
        $fp = fopen("{$path}", 'wb');
        fwrite($fp, $ob_contents);
        fclose($fp);
        ob_end_flush();
    }
}
开发者ID:rkostko,项目名称:NeoRaid-CMS,代码行数:31,代码来源:showthumb.php

示例9: GuildLogo


//.........这里部分代码省略.........
                 switch (substr($hex, $offset, 1)) {
                     case "0":
                         $c1 = "0";
                         $c2 = "0";
                         $c3 = "0";
                         break;
                     case "1":
                         $c1 = "0";
                         $c2 = "0";
                         $c3 = "0";
                         break;
                     case "2":
                         $c1 = "128";
                         $c2 = "128";
                         $c3 = "128";
                         break;
                     case "3":
                         $c1 = "255";
                         $c2 = "255";
                         $c3 = "255";
                         break;
                     case "4":
                         $c1 = "255";
                         $c2 = "0";
                         $c3 = "0";
                         break;
                     case "5":
                         $c1 = "255";
                         $c2 = "128";
                         $c3 = "0";
                         break;
                     case "6":
                         $c1 = "255";
                         $c2 = "255";
                         $c3 = "0";
                         break;
                     case "7":
                         $c1 = "128";
                         $c2 = "255";
                         $c3 = "0";
                         break;
                     case "8":
                         $c1 = "0";
                         $c2 = "255";
                         $c3 = "0";
                         break;
                     case "9":
                         $c1 = "0";
                         $c2 = "255";
                         $c3 = "128";
                         break;
                     case "a":
                         $c1 = "0";
                         $c2 = "255";
                         $c3 = "255";
                         break;
                     case "b":
                         $c1 = "0";
                         $c2 = "128";
                         $c3 = "255";
                         break;
                     case "c":
                         $c1 = "0";
                         $c2 = "0";
                         $c3 = "255";
                         break;
                     case "d":
                         $c1 = "128";
                         $c2 = "0";
                         $c3 = "255";
                         break;
                     case "e":
                         $c1 = "255";
                         $c2 = "0";
                         $c3 = "255";
                         break;
                     case "f":
                         $c1 = "255";
                         $c2 = "0";
                         $c3 = "128";
                         break;
                     default:
                         $c1 = "255";
                         $c2 = "255";
                         $c3 = "255";
                         break;
                 }
                 $row[$x] = $x * $pixelSize;
                 $row[$y] = $y * $pixelSize;
                 $row2[$x] = $row[$x] + $pixelSize;
                 $row2[$y] = $row[$y] + $pixelSize;
                 $color[$y][$x] = imagecolorallocate($img, $c1, $c2, $c3);
                 imagefilledrectangle($img, $row[$x], $row[$y], $row2[$x], $row2[$y], $color[$y][$x]);
             }
         }
         Imagepng($img, $path . $name . "-" . $size . ".png");
         Imagedestroy($img);
         return $path . $name . "-" . $size . ".png";
     }
 }
开发者ID:SanneA,项目名称:wodegongjubao,代码行数:101,代码来源:MuonlineUser.php

示例10: header

<?php

header("Content-type: image/png");
$string = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = '';
for ($i = 0; $i < 6; $i++) {
    $pos = rand(0, 36);
    $str .= $string[$pos];
}
$img_handle = ImageCreate(60, 20) or die("Cannot Create image");
//Image size (x,y)
$back_color = ImageColorAllocate($img_handle, 255, 255, 255);
//Background color RBG
$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
//Text Color RBG
ImageString($img_handle, 31, 5, 0, $str, $txt_color);
Imagepng($img_handle);
session_start();
$_SESSION['img_number'] = $str;
开发者ID:semplon,项目名称:aksarajawagenerator,代码行数:19,代码来源:captcha.php

示例11: createBarCode

 public function createBarCode($image_type = 'png', $file_name = null)
 {
     $this->parseCode();
     $this->image = ImageCreate($this->width + 2 * $this->quiet_zone, $this->height + $this->font_height + $this->quiet_zone);
     $this->bgcolor = imagecolorallocate($this->image, $this->bgcolor >> 16, $this->bgcolor >> 8 & 0xff, $this->bgcolor & 0xff);
     $this->color = imagecolorallocate($this->image, $this->color >> 16, $this->color >> 8 & 0xff, $this->color & 0xff);
     ImageFilledRectangle($this->image, 0, 0, $this->width + 2 * $this->quiet_zone, $this->height + $this->font_height, $this->bgcolor);
     $sx = $this->quiet_zone;
     $sy = $this->font_height - 1;
     $fw = 10;
     //編號為2或3的字體的寬度為10,為4或5的字體寬度為11
     if ($this->font_type > 3) {
         $sy++;
         $fw = 11;
     }
     $ex = 0;
     if ($this->text) {
         //不显示号码,则生成满的条码
         if ($this->showType == 'top') {
             $ey = $this->height + $this->font_height - 2;
             //条码显示上方
         } else {
             if ($this->showType == 'bottom') {
                 $ey = $this->height - 2;
                 //条码显示下方
                 $sy = $this->quiet_zone;
             }
         }
     } else {
         $ey = $this->height + $this->font_height;
         $sy = $this->quiet_zone;
     }
     for ($i = 0; $i < strlen($this->bin_code); $i++) {
         $ex = $sx + $this->unit_width * (int) $this->bin_code[$i] - 1;
         if ($i % 2 == 0) {
             ImageFilledRectangle($this->image, $sx, $sy, $ex, $ey, $this->color);
         }
         $sx = $ex + 1;
     }
     if ($this->text) {
         //存在条码号再显示
         $t_num = strlen($this->text);
         $t_x = $this->width / $t_num;
         $t_sx = ($t_x - $fw) / 2;
         //目的为了使文字居中平均分布
         if ($this->showType == 'top') {
             $y = 0;
         } else {
             if ($this->showType == 'bottom') {
                 $y = $this->height;
             }
         }
         for ($i = 0; $i < $t_num; $i++) {
             imagechar($this->image, $this->font_type, 6 * $this->unit_width + $t_sx + $i * $t_x, $y, $this->text[$i], $this->color);
         }
     }
     if (!$file_name) {
         header("Content-Type: image/" . $image_type);
     }
     switch ($image_type) {
         case 'jpg':
         case 'jpeg':
             Imagejpeg($this->image, $file_name);
             break;
         case 'png':
             Imagepng($this->image, $file_name);
             break;
         case 'gif':
             break;
             Imagegif($this->image, $file_name);
         default:
             Imagepng($this->image, $file_name);
             break;
     }
 }
开发者ID:node-rookie,项目名称:bdg,代码行数:75,代码来源:scanCode.class.php

示例12: ImageTTFText

/*
/* -------------- START ----------------------------------------------*/
/*$txt=$LDNoOccList;
ImageTTFText ($im, 15, 0, 9, 27, $black, "arial.ttf",$txt);
$txt=$LDFromWard.strtoupper($station);
ImageTTFText ($im, 15, 0, 9, 52, $black, "arial.ttf",$txt);
$txt=$LDWithinLast.($c-1).$LDDays;
ImageTTFText ($im, 15, 0, 9, 77, $black, "arial.ttf",$txt);
$txt=$LDAvailable;
ImageTTFText ($im, 15, 0, 9, 102, $black, "arial.ttf",$txt);
*/
/* -------------- END -------------------------------------------------*/
// ******************************************************************
// * the following code is the default - uses system fonts
// ******************************************************************
/* -------------- START  ----------------------*/
$txt = $LDNoOccList;
ImageString($im, 3, 9, 17, $txt, $black);
$txt = $LDFromWard . strtoupper($station);
ImageString($im, 3, 9, 42, $txt, $black);
$txt = $LDWithinLast;
ImageString($im, 3, 9, 67, $txt, $black);
$txt = $c - 1 . $LDDays . " " . $LDAvailable;
ImageString($im, 3, 9, 92, $txt, $black);
/* -------------- END --------------------------*/
Imagepng($im);
ImageDestroy($im);
?>


开发者ID:patmark,项目名称:care2x-tz,代码行数:28,代码来源:nobellist.php

示例13: beResizeImg


//.........这里部分代码省略.........
             $srcy = (int) (($imagedata[1] - $srchei) / 2);
         } elseif ($imagedata[0] / $new_iw > $imagedata[1] / $new_ih) {
             //original to wide
             $srcwid = (int) ($new_iw * ($imagedata[1] / $new_ih));
             $srcx = (int) (($imagedata[0] - $srcwid) / 2);
         }
     }
     //set image type and set image name
     $ipath = pathinfo($isrc);
     $itype = strtolower($ipath["extension"]);
     $iname = substr($ipath["basename"], 0, -(strlen($itype) + 1)) . "_" . $new_iw . "_" . $new_ih . "_" . $iqual . "." . $itype;
     //check if $idst is set to a subdirectory and if so add it to the path
     $idir = $idst != "" ? $ipath["dirname"] . "/" . $idst : $ipath["dirname"];
     //check if image exists, else create it
     if (!JFile::exists($idir . "/" . $iname)) {
         if ($itype == "jpg" && function_exists("imagecreatefromjpeg")) {
             $image = imagecreatefromjpeg($isrc);
             $image_dest = imagecreatetruecolor($new_iw, $new_ih);
             imagecopyresampled($image_dest, $image, 0, 0, $srcx, $srcy, $new_iw, $new_ih, $srcwid, $srchei);
             ob_start();
             // start a new output buffer
             imagejpeg($image_dest, NULL, $iqual);
             $buffer = ob_get_contents();
             ob_end_clean();
             // stop this output buffer
         } elseif ($itype == "gif" && function_exists("imagecreatefromgif")) {
             $image = imagecreatefromgif($isrc);
             $image_dest = imagecreatetruecolor($new_iw, $new_ih);
             imagealphablending($image_dest, false);
             // get and reallocate transparency-color
             $transindex = imagecolortransparent($image);
             if ($transindex >= 0) {
                 $transcol = imagecolorsforindex($image, $transindex);
                 $transindex = imagecolorallocatealpha($image_dest, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
                 imagefill($image_dest, 0, 0, $transindex);
             }
             // resample
             imagecopyresampled($image_dest, $image, 0, 0, $srcx, $srcy, $new_iw, $new_ih, $srcwid, $srchei);
             // restore transparency
             if ($transindex >= 0) {
                 imagecolortransparent($image_dest, $transindex);
                 for ($y = 0; $y < $new_ih; ++$y) {
                     for ($x = 0; $x < $new_iw; ++$x) {
                         if ((imagecolorat($image_dest, $x, $y) >> 24 & 0x7f) >= 100) {
                             imagesetpixel($image_dest, $x, $y, $transindex);
                         }
                     }
                 }
             }
             imagetruecolortopalette($image_dest, true, 255);
             imagesavealpha($image_dest, false);
             ob_start();
             // start a new output buffer
             imagegif($image_dest, NULL, $iqual);
             $buffer = ob_get_contents();
             ob_end_clean();
             // stop this output buffer
         } elseif ($itype == "png" && function_exists("imagecreatefrompng")) {
             $image = ImageCreateFromPng($isrc);
             $image_dest = ImageCreateTrueColor($new_iw, $new_ih);
             $transindex = imagecolortransparent($image);
             $istruecolor = imageistruecolor($image);
             if ($transindex >= 0) {
                 ImageColorTransparent($image_dest, ImageColorAllocate($image_dest, 0, 0, 0));
                 ImageAlphaBlending($image_dest, false);
             } elseif (!$istruecolor) {
                 ImagePaletteCopy($image_dest, $image);
             } else {
                 ImageColorTransparent($image_dest, ImageColorAllocate($image_dest, 0, 0, 0));
                 ImageAlphaBlending($image_dest, false);
                 ImageSaveAlpha($image_dest, true);
             }
             ImageCopyResized($image_dest, $image, 0, 0, $srcx, $srcy, $new_iw, $new_ih, $srcwid, $srchei);
             $iqual_png = 100 - $iqual;
             if (substr(phpversion(), 0, 1) >= 5) {
                 $iqual_png = intval(($iqual - 10) / 10);
             }
             ob_start();
             // start a new output buffer
             Imagepng($image_dest, NULL, $iqual_png);
             $buffer = ob_get_contents();
             ob_end_clean();
             // stop this output buffer
         }
         if (isset($buffer) && $buffer != "") {
             JFile::write($idir . '/' . $iname, $buffer);
             unset($buffer);
         }
         if (isset($image)) {
             imagedestroy($image);
         }
         if (isset($image_dest)) {
             imagedestroy($image_dest);
         }
     }
     //utf8_encode and rawurlencode file name
     $iname = rawurlencode(utf8_encode($iname));
     //return path/filename/type/width/height
     return $thenewimage = array($idir . '/' . $iname, $iname, $itype, $new_iw, $new_ih);
 }
开发者ID:sansandeep143,项目名称:av,代码行数:101,代码来源:cssgalleryhelper.php

示例14: 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

示例15: createThumb

 function createThumb($upfile, $dstfile, $max_width, $max_height)
 {
     $size = getimagesize($upfile);
     $width = $size[0];
     $height = $size[1];
     $x_ratio = $max_width / $width;
     $y_ratio = $max_height / $height;
     if ($width <= $max_width && $height <= $max_height) {
         $tn_width = $width;
         $tn_height = $height;
     } elseif ($x_ratio * $height < $max_height) {
         $tn_height = ceil($x_ratio * $height);
         $tn_width = $max_width;
     } else {
         $tn_width = ceil($y_ratio * $width);
         $tn_height = $max_height;
     }
     if ($size['mime'] == "image/jpeg") {
         $src = ImageCreateFromJpeg($upfile);
         $dst = ImageCreateTrueColor($tn_width, $tn_height);
         imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
         imageinterlace($dst, true);
         ImageJpeg($dst, $dstfile, 100);
     } else {
         if ($size['mime'] == "image/png") {
             $src = ImageCreateFrompng($upfile);
             $dst = ImageCreateTrueColor($tn_width, $tn_height);
             imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
             // integer representation of the color black (rgb: 0,0,0)
             $background = imagecolorallocate($dst, 255, 255, 0);
             // removing the black from the placeholder
             imagecolortransparent($dst, $background);
             // turning off alpha blending (to ensure alpha channel information
             // is preserved, rather than removed (blending with the rest of the
             // image in the form of black))
             imagealphablending($dst, false);
             // turning on alpha channel information saving (to ensure the full range
             // of transparency is preserved)
             imagesavealpha($dst, true);
             Imagepng($dst, $dstfile);
         } else {
             $src = ImageCreateFromGif($upfile);
             $dst = ImageCreateTrueColor($tn_width, $tn_height);
             imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
             imagegif($dst, $dstfile);
         }
     }
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:48,代码来源:UsersController.php


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