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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.