Jump to content

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 :)
Link to comment
https://forums.phpfreaks.com/topic/4835-image-resizing-problem/
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)
Link to comment
https://forums.phpfreaks.com/topic/4835-image-resizing-problem/#findComment-17004
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.