• 15-08-2021, 11:03:42
    #1
    Merhaba, php ile fotoğraf uploadladıktan sonra fotoğrafın transparanlığı bozuluyor. Biraz araştırdırdım aşağıdaki ayarları yapmam gerektiğini buldum ancak php bilgim tam olmadığından kendi scriptimde düzenleyemedim. Yardımcı olabilir misiniz?

    imagealphablending($NewCanves, false); imagesavealpha($NewCanves, true);  imagealphablending($SrcImage, true);
    $url_action="";
    if(isset($_GET['action'])){
    $action=$_GET['action'];
    if($action=="add"){
    if(isset($_POST['submit'])){
    if($_FILES['genre_img']['name']!=""){
    $genre_image="genre_".rand(0,99999)."_".$_FILES['genre_img']['name'];
    $tpath1='uploads/genres/'.$genre_image;
    $pic1=process_image($_FILES["genre_img"]["tmp_name"], $tpath1, 100);
    }
    $data = array(
    'name' => $_POST['genre_name'],
    'img' => $genre_image
    );
    $qry = insert_tbl('genres',$data);
    $_SESSION['msg']="6";
    header( "Location:x_add_genre.php?action=add");
    exit;
    }
    }
    elseif($action=="delete_image"){
    $genre_id=$_GET['id'];
    $img_res=mysqli_query($mysqli,"SELECT * FROM genres WHERE id=$genre_id");
    $img_res_row=mysqli_fetch_assoc($img_res);
    if($img_res_row['img']!=""){
    unlink('uploads/genres/'.$img_res_row['img']);
    $data = array(
    'img' => ""
    );
    update_tbl('genres', $data, "WHERE id = $genre_id");
    header( "Location:x_add_genre.php?action=edit&id=".$genre_id);
    exit;
    }
    }
    elseif($action=="edit"){
    if(isset($_POST['submit']) and isset($_POST['genre_id'])){
    $genre_id=$_POST['genre_id'];
    $genre_name=$_POST['genre_name'];
    $genre_name=str_replace("'","\'",$genre_name);
    
    $genre_image="";
    $img_res=mysqli_query($mysqli,"SELECT * FROM genres WHERE id=$genre_id");
    $img_res_row=mysqli_fetch_assoc($img_res);
    if($img_res_row['img']!=""){
    $genre_image=$img_res_row['img'];
    }
    //check delete old image
    if($_FILES['genre_img']['name']!=""){
    if($genre_image!=""){
    unlink('uploads/genres/'.$genre_image);
    }
    //put new image
    $genre_image="genre_".rand(0,99999)."_".$_FILES['genre_img']['name'];
    $tpath1='uploads/genres/'.$genre_image;
    $pic1=process_image($_FILES["genre_img"]["tmp_name"], $tpath1, 100);
    }
    if($genre_image!=""){
    $data = array(
    'name' => $genre_name,
    'img' => $genre_image
    );
    }
    else{
    $data = array(
    'name' => $genre_name,
    'img' => ''
    );
    }
    update_tbl('genres', $data, "WHERE id = $genre_id");
    $_SESSION['msg']="7";
    header("Location:x_add_genre.php?action=edit&id=".$genre_id);
    exit;
    }
    $genre_id=$_GET['id'];
    $qry="SELECT * FROM genres where id=$genre_id";
    $result=mysqli_query($mysqli,$qry);
    $row=mysqli_fetch_assoc($result);
    }
    elseif($action=="copy"){
    $genre_id=$_GET['id'];
    $qry="SELECT * FROM genres where id=$genre_id";
    $result=mysqli_query($mysqli,$qry);
    $row=mysqli_fetch_assoc($result);
    $url_action="x_add_genre.php?action=add";
            }
  • 16-08-2021, 16:47:14
    #2
    "process_image" şu fonksiyonun içeriğini yazarsanız buraya yardımcı olalım.
  • 16-08-2021, 17:20:52
    #3
    QuarkChain adlı üyeden alıntı: mesajı görüntüle
    "process_image" şu fonksiyonun içeriğini yazarsanız buraya yardımcı olalım.
    Atmayı unutmuşum kusura bakmayın
    //process image before uploading to server
    function process_image($source_url, $destination_url, $quality){
        $info = getimagesize($source_url);
        if ($info['mime'] == 'image/jpeg'){
          $image = imagecreatefromjpeg($source_url);
        }
        elseif ($info['mime'] == 'image/png'){
          $image = imagecreatefrompng($source_url);
        }
        imagejpeg($image, $destination_url, $quality);
        return $destination_url;
    }
  • 16-08-2021, 17:43:23
    #4
    Bu şekilde deneyebilirsiniz.

    function process_image($source_url, $destination_url, $quality){
        $info = getimagesize($source_url);
        $width = $info[0];
        $height = $info[1];
    
        if ($info['mime'] == 'image/jpeg'){
          $image = imagecreatefromjpeg($source_url);
          imagejpeg($image, $destination_url, $quality);
        } else if ($info['mime'] == 'image/png'){
          $image = imagecreatefrompng($source_url);
          $thumb = imagecreatetruecolor($width, $height);
          imagealphablending($thumb, false);
          imagesavealpha($thumb, true);  
          imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, $width, $height);
          imagepng($thumb, $destination_url);
        }
        
        return $destination_url;
    }
    mrdeejay adlı üyeden alıntı: mesajı görüntüle
    Atmayı unutmuşum kusura bakmayın
    //process image before uploading to server
    function process_image($source_url, $destination_url, $quality){
        $info = getimagesize($source_url);
        if ($info['mime'] == 'image/jpeg'){
          $image = imagecreatefromjpeg($source_url);
        }
        elseif ($info['mime'] == 'image/png'){
          $image = imagecreatefrompng($source_url);
        }
        imagejpeg($image, $destination_url, $quality);
        return $destination_url;
    }
  • 16-08-2021, 18:07:31
    #5
    QuarkChain adlı üyeden alıntı: mesajı görüntüle
    Bu şekilde deneyebilirsiniz.

    function process_image($source_url, $destination_url, $quality){
        $info = getimagesize($source_url);
        $width = $info[0];
        $height = $info[1];
    
        if ($info['mime'] == 'image/jpeg'){
          $image = imagecreatefromjpeg($source_url);
          imagejpeg($image, $destination_url, $quality);
        } else if ($info['mime'] == 'image/png'){
          $image = imagecreatefrompng($source_url);
          $thumb = imagecreatetruecolor($width, $height);
          imagealphablending($thumb, false);
          imagesavealpha($thumb, true);  
          imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, $width, $height);
          imagepng($thumb, $destination_url);
        }
        
        return $destination_url;
    }
    Çok teşekkürler sorun çözüldü