malina95
Мастер
Дата регистрации:
15.07.2012 07:13:44
Сообщений: 208
$path_directory = 'avatars/';
if(preg_match('/[.](JPG)|(jpg)|(jpeg)|(JPEG)|(gif)|(GIF)|(png)|(PNG)$/', $_FILES['avatar']['name']))
{
$filename = $_FILES['avatar']['name'];
$file_ext = getExtension($filename);
$source = $_FILES['avatar']['tmp_name'];
$target = $path_directory . $filename;
move_uploaded_file($source, $target);
if(preg_match('/[.](GIF)|(gif)$/', $filename)) {
$im = imagecreatefromgif($path_directory.$filename);
}
if(preg_match('/[.](PNG)|(png)$/', $filename)) {
$im = imagecreatefrompng($path_directory.$filename) ;
}
if(preg_match('/[.](JPG)|(jpg)|(jpeg)|(JPEG)$/', $filename)) {
$im = imagecreatefromjpeg($path_directory.$filename);
}
$w = 130;
$w_src = imagesx($im);
$h_src = imagesy($im);
$dest = imagecreatetruecolor($w, $w);
if ($w_src > $h_src)
imagecopyresampled($dest, $im, 0, 0, round((max($w_src, $h_src) - min($w_src, $h_src)) / 2), 0, $w, $w, min($w_src, $h_src), min($w_src, $h_src));
if ($w_src < $h_src) imagecopyresampled($dest, $im, 0, 0, 0, 0, $w, $w, min($w_src, $h_src), min($w_src, $h_src));
if ($w_src == $h_src)
imagecopyresampled($dest, $im, 0, 0, 0, 0, $w, $w, $w_src, $w_src);
$date = time();
imagejpeg($dest, $path_directory.$date.".".$file_ext);
$avatar = $path_directory.$date.".".$file_ext;
$delfull = $path_directory.$filename;
unlink ($delfull);
$result7 = $mysqli->query("SELECT `avatar` FROM $table_users WHERE `id` = '".$id_user."'"
$myrow7 = $result7->fetch_assoc();
if ($myrow7['avatar'] == $ava) {
$ava = 1;
} else {
unlink ($myrow7['avatar']);
}
}
Помогите пожалуйста, с форматом png тоже беда, появляется картинка но на чёрном фоне, прозрачности просто нету