Jump to content

Archived

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

Jervous

Image Resizing Problem

Recommended Posts

Hello everyone. I am writing a script to resize images, and am stuck with this problem. I know for a fact that the problem is NOT that any of the variables are unset, because I have checked and they are all set. If anyone could help I would be very appreciative :)

[code]// Make new image
$new = imagecreatetruecolor($new_width, $new_height);

// Create source image
if ($file_type_ns == "jpg" OR $file_type_ns == "jpeg"){
   $source = imagecreatefromjpeg("uploads/$file_name");
}
    if ($file_type_ns == "gif"){
   $source = imagecreatefromgif("uploads/$file_name");
}
    if ($file_type_ns == "png"){
   $source = imagecreatefrompng("uploads/$file_name");
}

// Build new image
imagecopyresampled($new, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output new image
if ($info_type == "jpeg" OR $info_type == "jpg"){
  imagejpeg($new, "images/$file_name_ns.jpeg", $quality);
}

if ($info_type == "gif"){
  imagegif($new, "images/$file_name_ns.gif");
}

if ($info_type == "png"){
  imagepng($new, "images/$file_name_ns.png");
}[/code]

$file_type_ns: the file type from $_FILES with the suffix extension
$info_type: the new file type that a user has already chosen from a form

Once again, all these variables have already been set. I get no errors or anything, but when I go to look at the new image, it is the right size and type, but it is completely black. Thanks to anyone who can help :)

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]the new file type that a user has already chosen from a form[/quote]

This may seem a bit of a stupid question, but, "new file type that a user has already chosen". Why are you allowing users choose the file type? Use the file type they uploaded. Can the file type be changed, just like that? (Excuse me if I'm wrong, I barley ever work with the image functions of PHP)

Share this post


Link to post
Share on other sites
It's because I am creating a script for users to upload and change their images, and yes, it is possible.

Share this post


Link to post
Share on other sites

×

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.