• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

CodeIgniter图像处理类的深入解析_php技巧

php 搞代码 3年前 (2022-01-26) 23次浏览 已收录 0个评论

image.php

<?php<BR>class Image extends Controller {<BR>    function Image()<BR>    {<BR>    parent::Controller();   <BR>    $this->load->library('image_lib');   <BR>    }<br><br>    //缩略图<BR>    function index(){<BR>        echo '* 调整图像大小 <br><BR>            * 创建缩略图 <br><BR>            * 图像裁剪 <br><BR>            * 图像旋转 <br><BR>            * 添加图像水印 <br><BR>        ';<BR>    }<BR>    //缩略图<BR>    function resize(){<BR>    /*<BR>    注意<BR>    当$config['create_thumb']等于FALSE并且$config['new_image']没有指定时,会调整原图的大小<BR>    当$config['create_thumb']等于TRUE并且$config['new_image']没有指定时,生成文件名为(原图名 _thumb.扩展名)<BR>    当$config['create_thumb']等于FALSE并且$config['new_image']指定时,生成文件名为$config['new_image']的值<BR>    当$config['create_thumb']等于TRUE并且$config['new_image']指定时,生成文件名为(原图名 _thumb.扩展名)<BR>    */<BR>        $config['image_library'] = 'gd2';//(必须)设置图像库<BR>        $config['source_image'] = 'ptjsite/upload/55002.jpg';//(必须)设置原始图像的名字/路径<BR>        $config['dynamic_output'] = FALSE;//决定新图像的生成是要写入硬盘还是动态的存在<BR>        $config['quality'] = '90%';//设置图像的品质。品质越高,图像文件越大<BR>        $config['new_image'] = 'ptjsite/upload/resize004.gif';//设置图像的目标名/路径。<BR>        $config['width'] = 575;//(必须)设置你想要得图像宽度。<BR>        $config['height'] = 350;//(必须)设置你想要得图像高度<BR>        $config['create_thumb'] = TRUE;//让图像处理函数产生一个预览图像(将_thumb插入文件扩展名之前)<BR>        $config['thumb_marker'] = '_thumb';//指定预览图像的标示。它将在被插入文件扩展名之前。例如,mypic.jpg 将会变成 mypic_thumb.jpg<BR>        $config['maintain_ratio'] = TRUE;//维持比例<BR>        $config['master_dim'] = 'auto';//auto, width, height 指定主轴线<BR>        $this->image_lib->initialize($config);<BR>        if (!$this->image_lib->resize())<BR>        {<BR>            echo $this->image_lib->display_errors();<BR>        }else{<BR>            echo "成功的";<BR>        }<BR>    }<BR>    //图像裁剪<BR>    function crop(){   <BR>        $config['image_library'] = 'gd2';//设置图像库<BR>        $config['source_image'] = 'ptjsite/upload/004.gif';//(必须)设置原始图像的名字/路径<BR>        $config['dynamic_output'] = FALSE;//决定新图像的生成是要写入硬盘还是动态的存在<BR>        $config['quality'] = '90%';//设置图像的品质。品质越高,图像文件越大<BR>        $config['new_image'] = 'ptjsite/upload/crop004.gif';//(必须)设置图像的目标名/路径。<br><br>        $config['width'] = 75;//(必须)设置你想要得图像宽度。<BR>        $config['height'] = 50;//(必须)设置你想要得图像高度<BR>        $config['maintain_ratio'] = TRUE;//维持比例<BR>        $config['x_axis'] = '30';//(必须)从左边取的像素值<BR>        $config['y_axis'] = '40';//(必须)从头部取的像素值<br><br>        $this->image_lib->initialize($config);<br><br>        if (!$this->image_lib->crop())<BR>        {<BR>            echo $this->image_lib->display_errors();<BR>        }else{<BR>            echo "成功的";<BR>        }<BR>    }<br><br>   <BR>    //图像旋转<BR>    function rotate(){   <BR>        $config['image_library'] = 'gd2';//(必须)设置图像库<BR>        $config['source_image'] = 'ptjsite/upload/001.jpg';//(必须)设置原始图像的名字/路径<BR>        $config['dynamic_output'] = FALSE;//决定新图像的生成是要写入硬盘还是动态的存在<BR>        $config['quality'] = '90%';//设置图像的品质。品质越高,图像文件越大<BR>        $config['new_image'] = 'ptjsite/upload/rotate001.jpg';//设置图像的目标名/路径<BR>        $config['rotation_angle'] = 'vrt';//有5个旋转选项 逆时针90 180 270 度 vrt 竖向翻转 hor 横向翻转   <BR>        $this->image_lib->initialize($config);<br><br>        if ( ! $this->image_lib->rotate())<BR>        {<BR>            echo $this->image_lib->display_errors();<BR>        }<BR>    }<br><br>    //文字水印<BR>    function watermark(){<BR>        $config['image_library'] = 'gd2';//(必须)设置图像库<BR>        $config['source_image'] = 'ptjsite/upload/003.jpg';//(必须)设置原图像的名字和路径. 路径必须是相对或绝对路径,但不能是URL.<BR>        $config['dynamic_output'] = FALSE;//TRUE 动态的存在(直接向浏览器中以输出图像),FALSE 写入硬盘<BR>        $config['quality'] = '90%';//设置图像的品质。品质越高,图像文件越大<BR>        $config['new_image'] = 'ptjsite/upload/crop004.gif';//设置图像的目标名/路径。<br><br>        $config['wm_type'] = 'overlay';//(必须)设置想要使用的水印处理类型(text, overlay)<BR>        $config['wm_padding'] = '5';//图像相对位置(单位像素)<BR>        $config['wm_vrt_alignment'] = 'middle';//竖轴位置 top, middle, bottom<BR>        $config['wm_hor_alignment'] = 'center';//横轴位置 left, center, right<BR>        $config['wm_vrt_offset'] = '0';//指定一个垂直偏移量(以像素为单位)<BR>        $config['wm_hor_offset'] = '0';//指定一个横向偏移量(以像素为单位)<BR>        /* 文字水印参数设置 */<BR>        $config['wm_text'] = 'Copyright 2008 - John Doe';//(必须)水印的文字内容<BR>        $config['wm_font_path'] = 'ptj_system/fonts/type-ra.ttf';//字体名字和路径<BR>        $config['wm_font_size'] = '16';//(必须)文字大小<BR>        $config['wm_font_color'] = 'FF0000';//(必须)文字颜色,十六进制数<BR>        $config['wm_shadow_color'] = 'FF0000';//投影颜色,十六进制数<BR>        $config['wm_shadow_distance'] = '3';//字体和投影距离(单位像素)。<BR>        /* 图像水印参数设置 */<BR>        /*<BR>        $config['wm_overlay_path'] = 'ptjsite/upload/overlay.png';//水印图像的名字和路径<BR>        $config['wm_opacity'] = '50';//水印图像的透明度<BR>        $config['wm_x_transp'] = '4';//水印图像通道<BR>        $config['wm_y_transp'] = '4';//水印图像通道<BR>        */<BR>        $this->image_lib->initialize($config);<BR>        $this->image_lib->watermark();<BR>    }<br><br>    //图像水印<BR>    function watermark2(){<BR>        $config['image_library'] = 'gd2';//(必须)设置图像库<BR>        $config['source_image'] = 'ptjsite/upload/003.jpg';//(必须)设置原图像的名字和路径. 路径必须是相对或绝对路径,但不能是URL.<BR>        $config['dynamic_output'] = FALSE;//TRUE 动态的存在(直接向浏览器中以输出图像),FALSE 写入硬盘<BR>        $config['quality'] = '90%';//设置图像的品质。品质越高,图像文件越大<BR>        $config['new_image'] = 'ptjsite/upload/crop004.gif';//设置图像的目标名/路径。<br><br>        $config['wm_type'] = 'overlay';//(必须)设置想要使用的水印处理类型(text, overlay)<BR>        $config['wm_padding'] = '5';//图像相对位置(单位像素)<BR>        $config['wm_vrt_alignment'] = 'middle';//竖轴位置 top, middle, bottom<BR>        $config['wm_hor_alignment'] = 'center';//横轴位置 lef<strong style="color:transparent">本文来源gaodai#ma#com搞@@代~&码*网/</strong><strong>搞gaodaima代码</strong>t, center, right<BR>        $config['wm_vrt_offset'] = '0';//指定一个垂直偏移量(以像素为单位)<BR>        $config['wm_hor_offset'] = '0';//指定一个横向偏移量(以像素为单位)<BR>        /* 文字水印参数设置 */<BR>        /*<BR>        $config['wm_text'] = 'Copyright 2008 - John Doe';//(必须)水印的文字内容<BR>        $config['wm_font_path'] = 'ptj_system/fonts/type-ra.ttf';//字体名字和路径<BR>        $config['wm_font_size'] = '16';//(必须)文字大小<BR>        $config['wm_font_color'] = 'FF0000';//(必须)文字颜色,十六进制数<BR>        $config['wm_shadow_color'] = 'FF0000';//投影颜色,十六进制数<BR>        $config['wm_shadow_distance'] = '3';//字体和投影距离(单位像素)。<BR>        */<br><br>        /* 图像水印参数设置 */<BR>        $config['wm_overlay_path'] = 'ptjsite/upload/overlay.png';//水印图像的名字和路径<BR>        $config['wm_opacity'] = '50';//水印图像的透明度<BR>        $config['wm_x_transp'] = '4';//水印图像通道<BR>        $config['wm_y_transp'] = '4';//水印图像通道<br><br>        $this->image_lib->initialize($config);<BR>        $this->image_lib->watermark();<BR>    }<BR>}<BR>?> <BR>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:CodeIgniter图像处理类的深入解析_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址