Mrfei 发表于 2017-12-30 07:26:56

详细解释imageTtfText()函数

magecopy() 函数用于拷贝图像或图像的一部分。  
  imagecopyresized() 函数用于拷贝部分图像并调整大小。
  
  imagecopy()
  
  imagecopy() 函数用于拷贝图像或图像的一部分,成功返回 TRUE ,否则返回 FALSE 。
  
  语法:
  
  
bool 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 )  
  参数说明:参数说明
  
  dst_im目标图像
  
  src_im被拷贝的源图像
  
  dst_x目标图像开始 x 坐标
  
  dst_y目标图像开始 y 坐标,x,y同为
0 则从左上角开始  
  src_x拷贝图像开始 x 坐标
  
  src_y拷贝图像开始 y 坐标,x,y同为
0 则从左上角开始拷贝  
  src_w(从 src_x 开始)拷贝的宽度
  
  src_h(从 src_y 开始)拷贝的高度
  
  例子:
  
  
<?php  
  header(
"Content-type: image/jpeg");  
  
//创建目标图像  
  $dst_im = imagecreatetruecolor(150, 150);
  
  //源图像
  
  $src_im = @imagecreatefromjpeg("images/flower_1.jpg");
  
  //拷贝源图像左上角起始 150px 150px
  
  imagecopy( $dst_im, $src_im, 0, 0, 0, 0, 150, 150 );
  
  //输出拷贝后图像
  
  imagejpeg($dst_im);
  
  imagedestroy($dst_im);
  
  imagedestroy($src_im);
  
  ?>
  
  imagecopyresized()
  
  imagecopyresized() 函数用于拷贝图像或图像的一部分并调整大小,成功返回 TRUE ,否则返回 FALSE 。
  
  语法:
  
  bool imagecopyresized( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y,
  
  int dst_w, int dst_h, int src_w, int src_h )
  
  本函数参数可参看 imagecopy() 函数,只是本函数增加了两个参数(注意顺序):
  
  dst_w:目标图像的宽度。
  
  dst_h:目标图像的高度。
  
  imagecopyresized() 的典型应用就是生成图片的缩略图:
  
  <?php
  
  header("Content-type: image/jpeg");
  
  //原图文件
  
  $file = "images/flower_1.jpg";
  
  // 缩略图比例
  
  $percent = 0.5;
  
  // 缩略图尺寸
  
  list($width, $height) = getimagesize($file);
  
  $newwidth = $width * $percent;
  
  $newheight = $height * $percent;
  
  // 加载图像
  
  $src_im = @imagecreatefromjpeg($file);
  
  $dst_im = imagecreatetruecolor($newwidth, $newheight);
  
  // 调整大小
  
  imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  
  //输出缩小后的图像
  
  imagejpeg($dst_im);
  
  imagedestroy($dst_im);
  
  imagedestroy($src_im);
  
  ?>
页: [1]
查看完整版本: 详细解释imageTtfText()函数