imagealphablending($NewCanves, false);
imagesavealpha($NewCanves, true);
imagealphablending($SrcImage, true);
PHP Kod:
//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;
}
?>
PHP Kod:
include("includes/xradio_header.php");
include("includes/xradio_function.php");
include("includes/xradio_msg.php");
$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";
}
}
?>