Results 1 to 1 of 1
  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 06:21 PM.

Similar Threads

  1. Replies: 1
    Last Post: April 14th, 2006, 04:14 PM
  2. Importing Large Sized Video Problem
    By hershy in forum Flash IDE
    Replies: 5
    Last Post: March 11th, 2006, 03:02 PM
  3. Problem in visibility of macromedia help files in XP
    By rajesh_pila in forum Flash IDE
    Replies: 1
    Last Post: August 2nd, 2005, 03:18 PM
  4. Help needed with weird loadVars problem
    By Silenus in forum ActionScript 2 (and Earlier)
    Replies: 3
    Last Post: May 17th, 2005, 08:56 AM
  5. thumbnail slideshow with if statements
    By seanc in forum Flash IDE
    Replies: 1
    Last Post: February 19th, 2004, 03:07 PM

Bookmarks

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