我的網站(以html和php整體編碼)包含一項功能,允許某些用戶上傳圖片。圖像被調整大小和使用此代碼加水印:用php爲水印圖片加水印
function watermarkpic($filename) {
ini_set('max_input_time', 300);
require 'config.php';
$watermark = imagecreatefrompng('watermarknew.png');
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
if(preg_match('/[.](jpg)$/', $filename)) {
$originalimage = imagecreatefromjpeg($path_to_image_directory . $filename);
} else if (preg_match('/[.](gif)$/', $filename)) {
$originalimage = imagecreatefromgif($path_to_image_directory . $filename);
} else if (preg_match('/[.](png)$/', $filename)) {
$originalimage = imagecreatefrompng($path_to_image_directory . $filename);
}
$originalwidth = imagesx($originalimage);
$originalheight = imagesy($originalimage);
$maxsize = 800;
$imgratio = $originalwidth/$originalheight;
if($imgratio > 1) {
$finalwidth = $maxsize;
$finalheight = $maxsize/$imgratio;
}
else {
$finalheight = $maxsize;
$finalwidth = $maxsize * $imgratio;
}
$finalimage = imagecreatetruecolor($finalwidth,$finalheight);
imagecopyresampled($finalimage, $originalimage, 0,0,0,0,$finalwidth,$finalheight,$originalwidth,$originalheight);
imagecopymerge($finalimage, $watermark, 0, 0, 0, 0, $watermarkwidth, $watermarkheight, 100);
//now move the file where it needs to go
if(!file_exists($path_to_medimage_directory)) {
if(!mkdir($path_to_medimage_directory)) {
die("There was a problem. Please try again!");
}
}
imagejpeg($finalimage, $path_to_medimage_directory . $filename);
}
的問題是,所述水印具有透明背景,但它顯示爲具有圖像在黑色背景上。我看過有關alpha混合等的東西,但我不知道這是什麼。我想了解我在做什麼,以及如何解決問題,使水印透明,因爲它應該是。真實的圖片應該填補空白。
在此先感謝。
Jpegs不支持透明度 – 2012-02-24 15:59:59