The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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