• PHP图像操作:3D图、缩放、旋转、裁剪、添加水印(一)


    来源:http://www.ido321.com/875.html

    1、利用php gd库的函数绘制3D扇形统计图

       1: <?php
       2: header("content-type","text/html;charset=utf-8");
       3: /*扇形统计图*/
       4: $image = imagecreatetruecolor(100, 100);    /*创建画布*/
       5:
       6: /*设置画布需要的颜色*/
       7: $white = imagecolorallocate($image,0xff,0xff,0xff);
       8: $gray = imagecolorallocate($image, 0xc0, 0xc0, 0xc0);
       9: $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
      10: $navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
      11: $darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
      12: $red = imagecolorallocate($image, 0xff, 0x00, 0x00);
      13: $darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
      14:
      15: /*填充背景色*/
      16: imagefill($image, 0, 0, $white);
      17:
      18: /*3D制作*/
      19: for($i = 60; $i > 50; $i--)
      20: {
      21:     imagefilledarc($image, 50, $i, 100, 50, -160, 40, $darknavy, IMG_ARC_PIE);
      22:     imagefilledarc($image, 50, $i, 100, 50, 40, 75, $darkgray, IMG_ARC_PIE);
      23:     imagefilledarc($image, 50, $i, 100, 50, 75, 200, $darkred, IMG_ARC_PIE);
      24: }
      25: /*画椭圆弧并填充*/
      26: imagefilledarc($image, 50, 50, 100, 50, -160, 40, $darknavy, IMG_ARC_PIE);
      27: imagefilledarc($image, 50, 50, 100, 50, 40, 75, $darkgray, IMG_ARC_PIE);
      28: imagefilledarc($image, 50, 50, 100, 50, 75, 200, $darkred, IMG_ARC_PIE);
      29:
      30: /*画字符串*/
      31: imagestring($image, 3, 15, 55, "30%", $white);
      32: imagestring($image, 3, 45, 35, "60%", $white);
      33: imagestring($image, 3, 60, 60, "10%", $white);
      34:
      35: /*输出图像*/
      36: header("content-type:image/png");
      37: imagepng($image);
      38:
      39: /*释放资源*/
      40: imagedestroy($image);
      41: ?>

    效果:

     

    2、对图片进行缩放

       1: <div>
       2:     <h4>原图大小</h4>
       3:     <img src="1.png" style="border:1px solid red;">
       4: </div>
       5: <?php
       6: header("content-type","text/html;charset=utf-8");
       7:
       8: /*
       9: *图片缩放
      10: *@param string $filename   图片的url
      11: *@param int    $width      设置图片缩放的最大宽度
      12: *@param int    $height     设置图片缩放的最大高度
      13: */
      14: function thumb($filename,$width=130,$height=130)
      15: {
      16:     /*获取原图的大小*/
      17:     list($width_orig,$height_orig) = getimagesize($filename);
      18:
      19:     /*根据参数$width和$height,换算出等比例的高度和宽度*/
      20:     if($width && ($width_orig < $height_orig))
      21:     {
      22:         $width = ($height / $height_orig) * $width_orig;
      23:     }
      24:     else
      25:     {
      26:         $height = ($width / $width_orig) * $height_orig;
      27:     }
      28:
      29:     /*以新的大小创建画布*/
      30:     $image_p = imagecreatetruecolor($width, $height);
      31:
      32:     /*获取图像资源*/
      33:     $image = imagecreatefrompng($filename);
      34:
      35:     /*使用imagecopyresampled缩放*/
      36:     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
      37:
      38:     /*保存缩放后的图片和命名*/
      39:     imagepng($image_p,'test.png');
      40:
      41:     /*释放资源*/
      42:     imagedestroy($image_p);
      43:     imagedestroy($image);
      44: }
      45: /*调用函数*/
      46: thumb('1.png');
      47: ?>
      48: <div>
      49:     <h4>缩放后的大小</h4>
      50:     <img src="test.png" style="border:1px solid red;">
      51: </div>

    效果:


  • 相关阅读:
    3D游戏常用技巧Normal Mapping (法线贴图)原理解析——高级篇
    [工作积累] OpenGL ES3.0: glInvalidateFramebuffer
    引擎设计跟踪(九.14.2c) 最近一些小的更新
    引擎设计跟踪(九.14.2b) 骨骼动画基本完成
    最近在玩的游戏
    引擎设计跟踪(九.14.2a) 导出插件问题修复和 Tangent Space 裂缝修复
    [工作积累] Google/Amazon平台的各种坑
    [工作积累] NDK通过Java获取package name 和version
    [工作记录] Android OpenSL ES: references & AAC related
    [工作记录] Android OpenGL ES: non-square texture
  • 原文地址:https://www.cnblogs.com/ido321/p/4004670.html
Copyright © 2020-2023  润新知