SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Accredited Master scotty2260's Avatar
    Join Date
    Apr 2004
    Location
    California
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto thumbnail not working

    I am using the script below (out of an online tutorial) to thumbnail images on the fly. For some reason it just gives me a black image.

    I did some error checking, and I know that it is getting the right name of the file, but still black.

    Thanks for any help!.
    PHP Code:
    <?php
    # Constants
    define(IMAGE_BASE'http://www.mouseguide.com/admin/updates/uploaded/2005-06-17/');
    define(MAX_WIDTH350);
    define(MAX_HEIGHT280);
    # Get image location
    $image_file str_replace('..'''$_GET['file']); // From URL, ?file=$file
    $image_path IMAGE_BASE "$image_file";
    # Load image
    $img null;
    $ext strtolower(end(explode('.'$image_path)));
    if (
    $ext == 'jpg' || $ext == 'jpeg') {
        
    $img = @imagecreatefromjpeg($image_path);
    } else if (
    $ext == 'png') {
        
    $img = @imagecreatefrompng($image_path);
    # Only if your version of GD includes GIF support
    } else if ($ext == 'gif') {
        
    $img = @imagecreatefrompng($image_path);
    }
    # If an image was successfully loaded, test the image for size
    if ($img) {
        
    # Get image size and scale ratio
        
    $width imagesx($img);
        
    $height imagesy($img);
        
    $scale min(MAX_WIDTH/$widthMAX_HEIGHT/$height);
        
    # If the image is larger than the max shrink it
        
    if ($scale 1) {
            
    $new_width floor($scale*$width);
            
    $new_height floor($scale*$height);
            
    # Create a new temporary image
            
    $tmp_img imagecreatetruecolor($new_width$new_height);
            
    # Copy and resize old image into new image
            
    imagecopyresized($tmp_img$img0000,
                             
    $new_width$new_height$width$height);
            
    imagedestroy($img);
            
    $img $tmp_img;
        }
    }
    # Create error image if necessary
    if (!$img) {
        
    $img imagecreate(MAX_WIDTHMAX_HEIGHT);
        
    imagecolorallocate($img,0,0,0);
        
    $c imagecolorallocate($img,70,70,70);
        
    imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);
        
    imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);
    }
    # Display the image
    header("Content-type: image/jpeg");
    imagejpeg($img);
    ?>
    Scott

  2. #2
    SitePoint Guru gavwvin's Avatar
    Join Date
    Nov 2004
    Location
    Cornwall, UK
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    remove the
    header("Content-type: image/jpeg");
    line for now, and remove the @ symbols from the imagecreate functions, and see if you are getting any errors.

  3. #3
    Accredited Master scotty2260's Avatar
    Join Date
    Apr 2004
    Location
    California
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I found the problem. The directory where the images are located is password protected. When I removed the password protection it started working.

    Thanks though!
    Scott


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
  •