php 給圖片加灰色透明效果

來源:互聯網
上載者:User

原理:

1.首先計算出原圖片的尺寸
2.建立相同尺寸的半透明圖片
3.使用 imagecopy()方法,把新建立的半透明圖片與原圖合并

 代碼如下 複製代碼

<?php
/*php 給圖片加灰色透明效果*/
$imfile = './0.jpg';//原圖
$origim = imagecreatefromjpeg($imfile);//從 JPEG 檔案或 URL 建立一映像
 
$w=imagesx($origim);//原圖寬度
$h=imagesy($origim);//原圖高度
 
$newimg = imagecreatetruecolor($w, $h);//返回一個映像標識符,代表了一幅大小為    x_size 和 y_size 的黑色映像。imagecreatetruecolor//     
 
$color=imagecolorallocatealpha($newimg,0,0,0,75);//為一幅映像分配顏色 + alpha; 和 imagecolorallocate() 相同,但多了一個額外的透明度參數 alpha,其值從 0 到 127。0 表示完全不透明,127 表示完全透明。 
 
imagecolortransparent($newimg,$color);//將某個顏色定義為透明色
 
imagefill($newimg,0,0,$color);//地區填充;resource $image , int $x , int $y , int $color 
 
imagecopy($origim,$newimg, 0,0, 0, 0,$w, $h);//拷貝映像的一部分;將 src_im 映像中座標從 src_x,src_y 開始,寬度為 src_w,高度為 src_h 的一部分拷貝到 dst_im 映像中座標為 dst_x 和 dst_y 的位置上。
 
imagejpeg($origim, './2.jpg');//輸出圖象到瀏覽器或檔案。;resource $image [, string $filename [, int $quality ]]
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.