1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Thumbnails and Truecolors

Discussion in 'PHP' started by Banda, Apr 5, 2007.

  1. Banda

    Banda New Member

    Joined:
    Mar 12, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Why my thumbnails doesn't look same as orginal picture? Colors are wrong, but I don't know how I fix them.
    Here is code:
    PHP:
    <?php
     $image_path 
    "images/"//Kansio jossa alkuper√§iset kuvat on
     
    $thumb_path "thumbs/"//Kansio johon Thumbnail kuvat laitetaan
     
    $thumb_width 100//Thumbin leveys
     //Avataan Kansio jossa kuvat ovat
     
    $hak opendir($image_path);
     
    //luetaan ensimm√§isen tiedoston nimi
     
    $image_name readdir($hak);
     
     
    //jatketaan niin kauan kun $nimi ei ole false
     
    while ($image_name) {
        
    //tulostetaan tiedoston nimi
        
    thumbnail($image_path,$thumb_path,$image_name,$thumb_width);
        
    //luetaan seuraavan tiedoston nimi
        
    $image_name readdir($hak);
     }
     
     
    //suljetaan hakemisto
     
    closedir($hak);
     function 
    thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
     {
         
    $orginal_path $image_path .'/'.$image_name;
         
    $src_img imagecreatefromjpeg($orginal_path);
         
    $origw=imagesx($src_img);
         
    $origh=imagesy($src_img);
         
    $new_w $thumb_width;
         
    $diff=$origw/$new_w;
         
    $new_h=$new_w;
         
    $dst_img imagecreate($new_w,$new_h);
         
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
         
         
    $destination_path $thumb_path .'/'.$image_name;
         
    imagejpeg($dst_img$destination_path);
         return 
    true;
         echo 
    'Kuva ' $image_name ' on muutettu thumbnailiksi onnistuneesti';
     }
     
     
    ?>
     
    Last edited by a moderator: Apr 6, 2007
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    PHP:
    //use
    imagecreatetruecolor($new_w,$new_h);
    //instead of
    imagecreate($new_w,$new_h);
     
  3. Banda

    Banda New Member

    Joined:
    Mar 12, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Now I have bigger problem now it only show Warnings:
    Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /mbnet/v/veskue/imagegallery/creator.php on line 23

    Warning: imagecreatefromjpeg(): 'images//.' is not a valid JPEG file in /mbnet/v/veskue/imagegallery/creator.php on line 23

    Warning: imagesx(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 24

    Warning: imagesy(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 25

    Warning: imagesx(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 30

    Warning: imagesy(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 30

    Warning: imagecopyresized(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 30

    Warning: imagejpeg(): Unable to open 'thumbs//.' for writing in /mbnet/v/veskue/imagegallery/creator.php on line 33

    Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /mbnet/v/veskue/imagegallery/creator.php on line 23

    Warning: imagecreatefromjpeg(): 'images//..' is not a valid JPEG file in /mbnet/v/veskue/imagegallery/creator.php on line 23

    Warning: imagesx(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 24

    Warning: imagesy(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 25

    Warning: imagesx(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 30

    Warning: imagesy(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 30

    Warning: imagecopyresized(): supplied argument is not a valid Image resource in /mbnet/v/veskue/imagegallery/creator.php on line 30

    Warning: imagejpeg(): Unable to open 'thumbs//..' for writing in /mbnet/v/veskue/imagegallery/creator.php on line 33

    What is wrong
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Try using a different image! If that doesn't work try undoing the last change you made to the code!

    imagecreatetruecolor() requires GD 2.0.1 or later.
     

Share This Page