php无法上传png图片格式,PHP水印无法上传png

我的脚本它与jpg,jpeg,bmp一起工作,当我上传和succsess . 但是当我上传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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值