Kako da omogucim dodavanje slika i png formata?

Ovako mogu da dodajem slike “gif”, “jpeg”, “jpg”, “JPG” formata.Kako da omogucim dodavanje za png?

$image_path = "watermark.png";

function watermark_image($oldimage_name, $new_image_name)
{
global $image_path;
list($owidth,$oheight) = getimagesize($oldimage_name);
$height = 600; 
$width = floor($owidth * ($height / $oheight));
$im = imagecreatetruecolor($width, $height);
$img_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$watermark = imagecreatefrompng($image_path);
list($w_width, $w_height) = getimagesize($image_path); 
$pos_x = $width - $w_width; 
$pos_y = $height - $w_height;
imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
imagejpeg($im, $new_image_name, 100);
imagedestroy($im);
unlink($oldimage_name);
return true;
}            
    
$demo_image= "";
if ($_FILES){
for ($i=0;$i<count($_FILES['file']['name']);$i++){
$ran_num =  mt_rand().mt_rand().mt_rand();
$path = "upload/";
$valid_formats = array("gif", "jpeg", "jpg",  "JPG");
$name = $_FILES["file"]["name"][$i];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats) && $_FILES['file']['size'][$i] <= 300*1024)
{
$upload_status = move_uploaded_file($_FILES['file']['tmp_name'][$i], $path.$_FILES["file"]["name"][$i]);
if($upload_status){
$new_name = $path.$ran_num.".jpg";
// Here you have to user functins watermark_text or watermark_image
if(watermark_image($path.$_FILES["file"]["name"][$i], $new_name))
$demo_image = $new_name;
if(!empty($demo_image)){
echo '<img src="'.$demo_image.'" />';
}
else{
}

}}
else
$msg="File size Max 300 KB or Invalid file format.";
}
}
}

$valid_formats = array(“gif”, “jpeg”, “jpg”, “JPG”, “png”, “PNG”);

Probao sam al nemoze samo to.
Morao sam i ovo da dodam:

$fparts = pathinfo($oldimage_name);
    $ext = strtolower($fparts['extension']);
if (!in_array($ext,array('gif','jpg','png','jpeg'))) return false;
    if ($ext == 'gif')$img_src = imagecreatefromgif($oldimage_name);
    else if ($ext == 'png')$img_src = imagecreatefrompng($oldimage_name);
    else if ($ext == 'jpg' || $ext == 'jpeg')$img_src = imagecreatefromjpeg($oldimage_name);

Reseno je.U svakom slucaju Hvala!


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Profit Monkey