Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 1 of 1

Thread: thumbnail problem...

  1. #1

    thumbnail problem...

    here is my code. it does exactly what i want it to do...upload an image and then create a thumbnail. only problem is...when i create the thumbnail. its not so much as a thumbnail as it is a small black picture. because the entire thing is just black. not a smaller version of the picture. any help please?

    PHP Code:
    if ($_FILES['file']['type'] == "image/gif" or $_FILES['file']['type'] == 'image/jpeg' or $_FILES['file']['type'] == 'image/pjpeg'){ 
        
    $target_path './data/images/uploads/'
        
    $thumb_path $target_path."thumbs/"
        
    $target_path $target_path basename$_FILES['file']['name']); 
        if(
    move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { 
            echo 
    "The file "basename$_FILES['file']['name']). " has been uploaded<br>"
    } else{ 
         die(
    "There was an error uploading the file, please try again!"); 

    } else { 
        die(
    "File must be an image<br>"); 

            
    createthumb($target_path,$thumb_path.basename$_FILES['file']['name']),59,59); 

    the createthumb function:

    PHP Code:
    function createthumb($name,$filename,$new_w,$new_h)
    {
        
    $size getimagesize($name);
     
    $system=explode(".",$name);
     if (
    preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
     if (
    preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
     
    $old_x=$size[0];
     
    $old_y=$size[1];
     if (
    $old_x $old_y
     {
      
    $thumb_w=$new_w;
      
    $thumb_h=$old_y*($new_h/$old_x);
     }
     if (
    $old_x $old_y
     {
      
    $thumb_w=$old_x*($new_w/$old_y);
      
    $thumb_h=$new_h;
     }
     if (
    $old_x == $old_y
     {
      
    $thumb_w=$new_w;
      
    $thumb_h=$new_h;
     }
     
    $dst_img imagecreatetruecolor($thumb_w,$thumb_h);
     
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
     if (
    preg_match("/png/",$system[1]))
     {
      
    imagepng($dst_img,$filename); 
     } else {
      
    imagejpeg($dst_img,$filename); 
     }
     
    imagedestroy($dst_img); 
     
    imagedestroy($src_img); 

    Last edited by eyeofthestorm; November 1st, 2005 at 07:21 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012