3
在GD中將一個圖像與另一個圖像相互掩蓋的基本代碼是什麼 - 黑色形狀和透明背景的一個圖像將用於裁剪另一個圖像 - 照片使照片呈黑色圖像的形狀。圖片GD和PNG蒙版
alt text http://img522.imageshack.us/img522/2200/maskingstoryboard1.png
在GD中將一個圖像與另一個圖像相互掩蓋的基本代碼是什麼 - 黑色形狀和透明背景的一個圖像將用於裁剪另一個圖像 - 照片使照片呈黑色圖像的形狀。圖片GD和PNG蒙版
alt text http://img522.imageshack.us/img522/2200/maskingstoryboard1.png
一種方式做到這一點是使用phpThumb。
基本參考這裏:http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php#x31
如果動態創建這將是東西那樣簡單的新形象:
<img src="../phpThumb.php?src=path/to/image/image.jp&fltr[]=mask|path/to/mask/mask.png&f=png" alt="">
要輸出成PNG。
如果圖像上傳後,這樣做是爲了創建一個新的圖像將被存儲在服務器,首先弄清楚phpThumb的基礎上,然後設置與所有其他的覆蓋參數:
例如:
...
require_once('phpThumb/phpthumb.class.php');
//Begin phpThumb work to resize image and create thumbnail
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . $destination;
$uploadfile = $uploaddir . $file;
$phpThumb = new phpThumb();
// set data source -- do this first, any settings must be made AFTER this call
$phpThumb->setSourceFilename($uploadfile);
$phpThumb->setParameter('w', 360); //change to update the picture size
$phpThumb->setParameter('h', 470); //change to update the picture size
$phpThumb->setParameter('fltr[]', 'mask|path/to/mask/mask.png'); //set mask
$phpThumb->setParameter('f', 'png'); //set png output format
$outputdir = $_SERVER['DOCUMENT_ROOT'] . $destination;
$output_filename = $outputdir . "masked" . $file;
$phpThumb->setParameter('config_allow_src_above_docroot', true);
if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
if ($phpThumb->RenderToFile($output_filename)) {
...
真棒。我會稍微等待一個答案,表明儘可能的裸露骨骼代碼,但這是接受答案的候選人。謝謝。 – henrijs 2010-04-24 01:59:51
不知道它會比這更光禿禿的骨頭,如果是這樣,我會對它感興趣;) – 2010-04-24 03:25:54