What's wrong with my thumbnail script?

Discussion in 'PHP' started by Maverick88, Oct 15, 2007.

  1. #1
    Hi,

    I am trying to create a PHP thumbnail script, but I am getting a few errors.
    I hope someone can help me out.

    This is the code:

    As you can see I am trying to make a thumbnail from an image called "Sig.jpg".

    This are the errors I get:

    What's the problem?
    Thanks in advance.
     
    Maverick88, Oct 15, 2007 IP
  2. amorph

    amorph Peon

    Messages:
    200
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think your file (sig.jpg) is broken. Can you open it normally?
     
    amorph, Oct 15, 2007 IP
  3. Maverick88

    Maverick88 Peon

    Messages:
    272
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Maverick88, Oct 15, 2007 IP
  4. Invent

    Invent Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?php
    
    $image = "Sig.jpg";
    $image = imagecreatefromjpeg($image);
    $width = imagesx($image);
    $height = imagesy($image);
    
    if ($width = $height) {
    $new_width = 150;
    $new_height = 150; }
    elseif ($width > $height) {
    $new_width = 150;
    $new_height = $height * ($new_width/$width); }
    elseif ($width < $height) {
    $new_height = 150;
    $new_width = $width * ($new_height/$height); }
    
    $thumb = imagecreatetruecolor($new_width,$new_height);
    
    imagecopyresampled($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height);
    imagejpeg($thumb,$file."_thumb".$type);
    
    ?>
    
    PHP:
    Also, you haven't defined $type for the 'imagejpeg' function.
     
    Invent, Oct 15, 2007 IP
  5. Maverick88

    Maverick88 Peon

    Messages:
    272
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I didn't put the whole code, but the $type is defined.
     
    Maverick88, Oct 15, 2007 IP
  6. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Do you have GD library installed
     
    undir, Oct 16, 2007 IP
  7. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    check image path and name (note that file names is case sensitive)
     
    kreoton, Oct 16, 2007 IP
  8. TechEvangelist

    TechEvangelist Guest

    Messages:
    919
    Likes Received:
    140
    Best Answers:
    0
    Trophy Points:
    133
    #8
    You are not pulling in the image. You are just assigning a file name to the $image variable.

    http://www.php.net/imagesx

    Scroll down the page to the comments.

    If you are working with a JPG, you need to use

    $img = ImageCreateFromJpeg($image);

    for a GIF use:

    $img = ImageCreateFromGif($image);

    for a PNG use:

    $img = ImageCreateFromPng($image);
     
    TechEvangelist, Oct 16, 2007 IP
  9. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?php
    header('Content-type: image/jpeg');
    list($width, $height) = getimagesize("image.jpg");
    $a = imagecreatetruecolor(100, 100);
    $b = imagecreatefromjpeg($filename);
    imagecopyresampled($a, $b, 0, 0, 0, 0, 100, 100, $width, $height);
    imagejpeg($a, null, 100);
    ?>

    This code will generate 100x100 big thumbnain
     
    grikis, Oct 16, 2007 IP