PHP水印原理

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');//生成新的圖片
?>

發佈了37 篇原創文章 · 獲贊 2 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章