添加到QQ书签 | 设为首页 | 加入收藏 | 繁體中文 | 网站地图
 | 网站首页 | QQ空间大图 | QQ空间FLASH模块 | QQ闪字表情 | QQ系列 | QQ下载 | 博客系列 | 完美图片 | 游戏秘籍 | 基础教程 | 
 | 精美字体 | 精品娃娃 | 个性签名 | 动感图片 | 制作素材 | 边框线条 | 视频·搞笑图片 | 基础知识 | 网页设计 | 
推 荐 阅 读
  • 没有推荐文章
  • 阅 读 排 行
    ·网页鼠标特效:在鼠标后面…
    ·在文本框默认自动输入当前…
    ·网页图片特效:图片动态水…
    ·网页鼠标特效:黑暗火光
    ·CSS基础知识:样式表CSS中…
    ·PHP源代码:图片加入文字…
    ·PHP源代码:Email图片生成
    ·CSS解决图片下有空隙
    ·纯CSS制作的网页中的ligh…
    ·网页图片鼠标动作特效:图…
    ·在线处理示意等待的AJAX动…
    ·11个图片上传加水印PHP源…
    ·CSS实现排版段落前面空两…
    ·网页时间特效:漂亮的脚本…
    ·PHP源代码:在图片上添加…
    ·DIV和CSS排版中制作细线条…
    ·CSS样式表参考:常用的CS…
    ·CSS优化:网页技术CSS的f…
    ·网页相册图片特效:矩阵鼠…
    ·PHP创建文字图片源码
     
    11个图片上传加水印PHP源代码 【字体:
     您现在的位置: QQ宝页站 >> 网页设计 >> PHP >> 正文 添加到百度搜藏 添加到QQ书签
     作者:佚名    文章来源:不详    点击数:    更新时间:2008-7-25  

    <?PHP
    /*
    @ file:pullImageEx.php
    @ explain : draw text on picture
    @ author : 左鹞飞 zuo_yfATyahoo.com
    @ create time: 2005/02/16
    */
    class pullImageEx{
        var $font_size=3;
     var $origin_file_path="";
     var $dest_file_path=""; 
     var $text="testing";
     var $text_color="FFFFFF";
     var $bg_color="000000";
     var $textlines=1;
     var $line_space=4;
     var $bg_rectangle_width=120;
     var $bg_rectangle_height=80;
     var $Opacity=50;
    function pullImageEx()
    {
     
    }
    function setBgRectangle($w=120,$h=80){$this->bg_rectangle_width=$w;$this->bg_rectangle_height=$h;}
    function setOriginFilePath($fp=""){$this->origin_file_path=$fp;}
    function setDestFilePath($fp=""){$this->dest_file_path=$fp;}
    function setText($txt="testing"){$this->text=$txt;}
    function setLineSpace($ls=4){$this->line_space=$ls;}
    function setTextFontSize($fs=1){$this->font_size=$fs;}
    function setTextColor($tc="FFFFFF"){$this->text_color=$tc;}
    function setRectangleBgColor($bc="000000"){$this->bg_color=$bc;}
    function setOpacity($opacities=50){$this->Opacity=$opacities;}
    function colordecode($hex){
       $code[r] = hexdec(substr($hex, 0 ,2));
       $code[g] = hexdec(substr($hex, 2 ,2));
       $code[b] = hexdec(substr($hex, 4 ,2));
       return $code;
    }
    function drawText()
    {
     $im=$this->createOverlayPic($this->bg_rectangle_width,$this->bg_rectangle_height,$this->bg_color,$this->text_color,$this->font_size,$this->text,$this->line_space);
     $this->mergePix($this->origin_file_path,$im,$this->dest_file_path,0,$this->Opacity);
    }
    function preProcessText($text)
    {
     
    }
    function createOverlayPic($pic_width,$pic_height,$pic_bg_color,$txt_color,$txt_font_size,$text,$line_space)
    {
     $im = @imagecreate ($pic_width, $pic_height) or die ("Cannot Initialize new GD image stream");
     //set backgroud canvas
     $bg_color=$this->colordecode($pic_bg_color);
     $background_color = imagecolorallocate ($im, $bg_color[r], $bg_color[g], $bg_color[b]);
     @imagefilledrectangle ($im, 0, 0, $pic_width, $pic_height, $background_color);
     
     $t_color=$this->colordecode($txt_color);
     $text_color = imagecolorallocate ($im, $t_color[r], $t_color[g], $t_color[b]);
     //get font pix size
     $text_ary=explode("\r\n",$text);
     $lines=sizeof($text_ary);
     $val_span=ImageFontHeight($txt_font_size) + $line_space;
     
     $text_height=$lines*$val_span;
     $init_height=($pic_height/2)-($text_height/2);
     
     for($i=0;$i<$lines;$i++)
     {
      $c_width  = ImageFontWidth($txt_font_size) * strlen($text_ary[$i]);
      $dest_x = ( $pic_width / 2 ) - ( $c_width / 2 );
         $dest_y = $init_height + $val_span*$i;
      imagestring ($im, $txt_font_size, $dest_x, $dest_y,  $text_ary[$i], $text_color);
     }
     //imagepng ($im);
        return $im;
    }
    function mergePix($canvas_png,$overlay_img, $targetfile, $pos=0,$Opacity=50)
    {
      
    //Get the resource handle of the pictures
       //$overlay_img = imageCreateFromPng($overlay_png);
       $canvas_img = imageCreateFromPNG($canvas_png);

    //Get the sizes of both pix   
       $canvas_png_width=imageSX($canvas_img);
       $canvas_png_height=imageSY($canvas_img);
       $overlay_png_width=imageSX($overlay_img);
       $overlay_png_height=imageSY($overlay_img);

    //middle
       if( $pos == 0 )
       {
           $dest_x = ( $canvas_png_width / 2 ) - ( $overlay_png_width / 2 );
           $dest_y = ( $canvas_png_height / 2 ) - ( $overlay_png_height / 2 );
       }

    //top left
       if( $pos == 1 )
       {
           $dest_x = 0;
           $dest_y = 0;
       }

    //top right
       if( $pos == 2 )
       {
           $dest_x = $canvas_png_width - $overlay_png_width;
           $dest_y = 0;
       }

    //bottom right
       if( $pos == 3 )
       {
           $dest_x = $canvas_png_width - $overlay_png_width;
           $dest_y = $canvas_png_height - $overlay_png_height;
       }

    //bottom left   
       if( $pos == 4 )
       {
           $dest_x = 0;
           $dest_y = $canvas_png_height - $overlay_png_height;
       }

    //top middle
       if( $pos == 5 )
       {
           $dest_x = ( ( $canvas_png_width - $overlay_png_width ) / 2 );
           $dest_y = 0;
       }

    //middle right
       if( $pos == 6 )
       {
           $dest_x = $canvas_png_width - $overlay_png_width;
           $dest_y = ( $canvas_png_height / 2 ) - ( $overlay_png_height / 2 );
       }
          
    //bottom middle   
       if( $pos == 7 )
       {
           $dest_x = ( ( $canvas_png_width - $overlay_png_width ) / 2 );
           $dest_y = $canvas_png_height - $overlay_png_height;
       }

    //middle left
       if( $pos == 8 )
       {
           $dest_x = 0;
           $dest_y = ( $canvas_png_height / 2 ) - ( $overlay_png_height / 2 );
       }
      
    //The main thing : merge the two pix   
       imageCopyMerge($canvas_img, $overlay_img,$dest_x,$dest_y,0,0,$overlay_png_width,$overlay_png_height,$Opacity);

    //Create a png out of the modified picture
       imagepng ($canvas_img,"$targetfile");
       imagedestroy($overlay_img);
       imagedestroy($canvas_img);
      
    }
    }
    ?>

    上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 


    Google
     
    文章录入:丹峰    责任编辑:丹峰 
  • 上一篇文章:

  • 下一篇文章:
  •  
    设为首页 / 加入收藏 / 联系站长 / 友情链接 / 本站动态 / 用户留言 / 版权申明
    QQ宝页站 www.QQBye.com 信息备案:粤ICP备06124483号