ImageCreateFrom*图片载入函数
ImageCreateFrom*载入PHP是一个将图片编码转成PHP可识别的编码的过程
ImageCreateFrom*
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromwbmp
imagecreatefromstring
imagecreatefromgif('php100.gif');
3、imagecopy图片合并函数
imagecopy( Dimg, Simg, int x, int y, int src_x, int src_y, int src_w, int src_h )
4、ImageCopyResized图片剪切函数
imagecopyresized( resourcedst_image,resourcesrc_image,intdst_x,
int dst_y, intsrc_x, int src_y,intdst_w, int dst_h,intsrc_w, int src_h)
在使用剪切图之前我们需要先建立一个真彩图,也就是方便内存来存储
代码示例:
<?php
/*
* Created on 2012-2-15
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$image='2418479_171527005580_2.JPG';
$img=getimagesize($image);//建立原始图片
switch ($img[2]) {//getimagesize这个函数返回的数组的索引2表示图像的类型
case 1:
$im=@imagecreatefromgif($image);
break;
case 2:
$im=@imagecreatefromjpeg($image);
break;
case 3:
$im=@imagecreatefrompng($image);
break;
default:
break;
}
$image2='head.jpg';
$img2=getimagesize($image2);//建立第二张图片
switch ($img2[2]) {//getimagesize这个函数返回的数组的索引2表示图像的类型
case 1:
$im2=@imagecreatefromgif($image2);
break;
case 2:
$im2=@imagecreatefromjpeg($image2);
break;
case 3:
$im2=@imagecreatefrompng($image2);
break;
default:
break;
}
imagecopy($im,$im2,110,100,0,0,200,200);//把第二张图片放到原始图片上
header("Content-type: image/jpeg");
imagejpeg($im,'新的图片.jpg');//生成新的图片
?>