zoukankan      html  css  js  c++  java
  • PHP操作图片简单案例

    $name = "哇哈哈";
    $namea = "计算机应用管理";
    $nameb = "软件开发";
    //新建一个真彩色图像 -- imagecreatetruecolor(int $width , int $height)
    $im = imagecreatetruecolor(800, 500);
    //由文件或 URL 创建一个新图象 -- imagecreatefromjpeg(string $filename)
    $bg = imagecreatefromjpeg('toutu.jpg');
    
    //拷贝图像的一部分 -- imagecopy(resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h)
    //将 src_im 图像中坐标从 src_x,src_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_x 和 dst_y 的位置上。
    imagecopy($im,$bg,0,0,0,0,900,539);
    //imagedestroy — 销毁一图像
    imagedestroy($bg);
    //为一幅图像分配颜色 -- imagecolorallocate( resource $image , int $red , int $green , int $blue)
    $black = imagecolorallocate($im, 60, 60, 60);
    $font = 'fh.ttf';
    $blacka = imagecolorallocate($im, 0, 0, 0);
    //用TrueType字体向图像写入文本 -- imagettftext(resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text)
    //image--由图象创建函数返回的图象资源。
    //size--字体的尺寸
    //angle--角度制表示的角度,0 度为从左向右读的文本
    //x由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)
    //y Y 坐标。它设定了字体基线的位置,不是字符的最底端。
    //color 颜色索引。使用负的颜色索引值具有关闭防锯齿的效果
    //fontfile 是想要使用的 TrueType 字体的路径。
    imagettftext($im, 14, 0, 285, 217, $blacka, $font, $name);
    imagettftext($im, 14, 0, 485, 250, $blacka, $font, $namea);
    imagettftext($im, 14, 0, 391, 280, $blacka, $font, $nameb);
    
    // 输出图像
    header("Content-type: image/png");
    imagejpeg($im);
  • 相关阅读:
    DSP Builder设计一个滤波器
    Modelsim 10.0 对Altera FFT IP 进行仿真
    FPGA内部计算小数
    TIOBE 2012年3月编程语言排行榜:JS超越Perl和Python
    转载 10个新鲜的Ajax相关的jQuery插件
    转载 使用HTML5、CSS3和jQuery增强网站用户体验
    转载 Java堆内存的10个要点
    累 腾讯笔试
    python 浮点数取整
    转载 一个页面重构工程师眼中的“用户体验”
  • 原文地址:https://www.cnblogs.com/yeshaoxiang/p/7832397.html
Copyright © 2011-2022 走看看