@vadikjust

При попытке ресайза изображения получаю черный фон?

Добрый день, при попытке ресайза изображения получаю черный фон, в чем может быть проблема?
function img_resize($path,$tmp_name,$new_name,$new_width){
	$path_info = pathinfo($tmp_name);
	
	if ($path_info['extension']!='jpg') {
		echo "file not jpg!";
        exit;
	}
	
    if (!file_exists($tmp_name)){
        echo "file not found!";
        exit;
    }
    if (!is_writable($path)){
        echo "error:permission denied!";
        exit;
    }
    list($width, $height) = getimagesize($tmp_name);
    $new_height = abs($new_width * $height / $width); 
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($tmp_name); 
    imagecopyresampled($image_p, $image, 0, 0, 0, 0,
                        $new_width, $new_height, $width, $height); 
    imagejpeg($image_p, $path . $new_name); 
    return $new_name;
}
  • Вопрос задан
  • 49 просмотров
Пригласить эксперта
Ответы на вопрос 1
webinar
@webinar Куратор тега PHP
Учим yii: https://youtu.be/-WRMlGHLgRg
imagecolorallocate + imagefill задают цвет фона, первый попавшийся под руку пример:
<?php 
	
// Set the vertices of polygon 
$values = array( 
			150, 50, // Point 1 (x, y) 
			50, 250, // Point 2 (x, y) 
			250, 250 // Point 3 (x, y) 
		); 
	
// Create the size of image or blank image 
$image = imagecreatetruecolor(300, 300); 
	
// Set the background color of image 
$background_color = imagecolorallocate($image, 0, 153, 0); 
	
// Fill background with above selected color 
imagefill($image, 0, 0, $background_color); 

// Allocate a color for the polygon 
$image_color = imagecolorallocate($image, 255, 255, 255); 
	
// Draw the polygon 
imagepolygon($image, $values, 3, $image_color); 
	
// Output the picture to the browser 
header('Content-type: image/png'); 
	
imagepng($image); 
?>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽
25 апр. 2024, в 09:29
2500 руб./за проект
25 апр. 2024, в 09:27
4000 руб./за проект
25 апр. 2024, в 09:20
10000 руб./за проект