Jump to content

help with image resize


pmiller624

Recommended Posts

ok, what my code does take a image that the user uploaded then takes in and width and height then resizes it.

 

it gets the width and height from the user through textboxes and what is happening is when a user put either zero or nothing into the boxes the image is turned black does anyone know why this is happening.

 

here is what i got

<?php
session_start();
?>
<?php
$filename = $_SESSION['imagename'];
$width = $_SESSION['width'];
$height = $_SESSION['height'];
list($getWidth, $getHeight) = getimagesize("userimages/" . $filename);
if($width > 0){
	$newWidth = $width;
}else{
	$newWidth = $getWidth;
}
if($height > 0){
	$newHeight = $height;
}else{
	$newHeight = $getHeight;
}
$image_p = imagecreatetruecolor($newWidth, $newHeight);
$image = imagecreatefromjpeg("userimages/".$filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg( $image_p, "userimages/".$filename, 100 );
header( 'Location: setup.php' ) ;
?>

Link to comment
https://forums.phpfreaks.com/topic/150407-help-with-image-resize/
Share on other sites

i am guessing here

 

  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

 

6 000000 = black

 

so #000000 is black as safe friendly web color.

 

i guess it normal.

 

use a if($what_ever==0){

 

$what_ever=defualt_number;

}

 

to stop the pic being black.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.