PHP水印无法上传png

时间:2014-05-29 05:07:51

标签: php png jpeg watermark

当我上传和succsess时,我的脚本与jpg,jpeg,bmp配合使用。 但是当我上传png时,它会存储在我的文件夹中,但图像是空白的,背景为黑色。

有什么方法可以解决这个问题吗?

$water_mark_text_2 = "text";
$font_path = "fonts/BRLNSR.TTF";
$font_size = 25;       // in pixcels
//$water_mark_text_1 = "9";

function watermark_text($oldimage_name, $new_image_name){
    global $font_path, $font_size, $water_mark_text_1, $water_mark_text_2;
    list($width,$height) = getimagesize($oldimage_name);
    $image = imagecreate(100, 100);
    // sets some colors
    $white = imagecolorallocate($image, 255, 255, 255);
    $black = imagecolorallocate($image, 0, 0, 0);
    $image = imagecreatetruecolor($width, $height);
    $image_src = imagecreatefromjpeg($oldimage_name);
    imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $width, $height);
    //imagecopyresampled($image, $stamp, $image_src, 0, 0, 0, 0, $width, $height, $width, $height , imagesx($stamp), imagesy($stamp), 60);
    // $black = imagecolorallocate($image, 0, 0, 0);
    $blue = imagecolorallocate($image, 79, 166, 185);
    // imagettftext($image, $font_size, 0, 30, 190, $black, $font_path, $water_mark_text_1);
    imagettftext($image, $font_size, 0, 5, 20,  $white, $font_path, $water_mark_text_2);
    imagejpeg($image, $new_image_name, 100);
    imagedestroy($image);
    unlink($oldimage_name);
    return true;
}

$path = "$stored/";
$valid_formats = array("jpg", "bmp","jpeg","JPG","png");
$name = $_FILES['img']['name'];

list($txt, $ext) = explode(".", $name);
$upload_status = move_uploaded_file($_FILES['img']['tmp_name'],$path.$name);

$new_name = $stored.$md5_img.".jpg";
watermark_text($path.$_FILES['img']['name'], $new_name);

如果我将imagecreatefromjpeg更改为imagecreatefrompng,将imagejpg更改为imagepng。 图像仍然上传,但我无法打开。

0 个答案:

没有答案