PHP Thumbnails

Discussion in 'Software' started by goldfish, Jan 29, 2004.

  1. goldfish

    goldfish Lt. Sushi.DC

    http://www.hypostasis.co.uk/pics.php
    Check that.

    The thumbnails look like pieces of crap. Here have some php code :
    PHP:
        $src_img imagecreatefromjpeg("pics/".$_FILES['userfile']['name']);
        
    $origw=imagesx($src_img);
        
    $origh=imagesy($src_img);
        
    $dst_img imagecreate(150,150);
        
    imagecopyresized($dst_img,$src_img,0,0,0,0,100,100,$origw,$origh);
        
    imagejpeg($dst_img"pics/t".$_FILES['userfile']['name']);
    Basically what Im wondering is what has it made such mullered thumbnails? :S
     
  2. Kodo

    Kodo SNATCHSQUATCH

    PHP:
    $origw=imagesx($src_img); 
        
    $origh=imagesy($src_img); 
        
    $dst_img imagecreate(150,150);
    take look at that..

    you have origw assuming ORIGINAL WIDTH and origh assuming ORIGINAL HEIGHT

    then you create the image with a 150,150 ratio..
    I assume the function IMAGECREATE uses the size params to generate the thumbnail in which case I would use

    PHP:
     $dst_img=imagecreate(($origw/4),($origh/4)) 
    that takes the original height and width and divides it by 4 to give you a 25% size.. increase the number to decrease the size.

    yes?
     
  3. goldfish

    goldfish Lt. Sushi.DC

    ok.... i want all the images to be of 150 height. Ive changed the code:
    PHP:
        $origw=imagesx($src_img);
        
    $origh=imagesy($src_img);
        
    $imageratio $origh $origw;
        
    $newh 150;
        
    $neww $newh $imageratio;
        
    $dst_img imagecreate($neww,$newh);
    This should keep the aspect ratio of the image, and give it a height of 150.

    BUT for some reason it creates an image which is really wide, 150 tall, and a bit faded.
    meh?


    EDIT : oops, divided wrong way around :p

    But why are the colours all screwed up? why cant i have thumbnails like dA!?
     
    Last edited: Jan 29, 2004
  4. goldfish

    goldfish Lt. Sushi.DC

    I *rule*
    PHP:
        $src_img imagecreatefromjpeg("pics/".$_FILES['userfile']['name']);
        
    $origw=imagesx($src_img);
        
    $origh=imagesy($src_img);
        
    $imageratio $origw $origh;
        
    $newh 150;
        
    $neww $newh $imageratio;
        
    $dst_img imagecreatetruecolor($neww,$newh);
        
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$neww,$newh,$origw,$origh);
        
    imagejpeg($dst_img"pics/t".$_FILES['userfile']['name']);
    this now uses GD2.
     
  5. Kodo

    Kodo SNATCHSQUATCH

    good deal man! :)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds