Jump to content


Photo

Image Resizing Problem


  • Please log in to reply
3 replies to this topic

#1 Jervous

Jervous
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 March 2006 - 02:50 PM

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 :)

// 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");
}

$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 :)

#2 Masna

Masna
  • Staff Alumni
  • Advanced Member
  • 288 posts
  • LocationNew York

Posted 13 March 2006 - 02:59 PM

[!--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)
I like LoL.

#3 Jervous

Jervous
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 March 2006 - 03:18 PM

It's because I am creating a script for users to upload and change their images, and yes, it is possible.

#4 Jervous

Jervous
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 March 2006 - 03:56 PM

Anyone at all? Please?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users