Jump to content

Attempting to resize jpeg images


Recommended Posts

i am attempting to resize an jpeg image, which works fine but when it comes to viewing the image, it is replaced with a black image, i believe it mite be that that imagecreatefromjpeg or imagecreatetruecolor functions mite be failing but ive been unable to find any immediate solutions ive included my code below, any suggestions would be much appreciated.

function resizeImage($imgfile_name,$uploaddir,$rand)
{
//ratio to resize
$percent = 0.5;

$final_filename = str_replace(" ", "_", $imgfile_name);
  $newfile = ''.$uploaddir .''.$final_filename.'';
  $destination_file = 'C:/PHP/thumbs/'.$rand.'A.jpg';
 
  // Content type
//header('Content-type: image/jpeg'); 
            list($pic_width,$pic_height) = getimagesize($newfile);
            echo "Image: ".$final_filename." currently has a width: ".$pic_width." and a height: ".$pic_height."";
            $new_width = $pic_width * $percent;
$new_height = $pic_height * $percent;
echo "Image: ".$final_filename." will have a width: ".$new_width." and a height: ".$new_height."";

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);

$image = imagecreatefromjpeg($newfile);

$resampled = imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $pic_width, $_picheight);

// Output
imagejpeg($image_p,$destination_file,100);
 
  return;
}
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.