Save thumbernails and delete original images

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jankie
    New Member
    • May 2007
    • 58

    Save thumbernails and delete original images

    Ok,I now realized that imagecopyresize does not actually resize original image for good,but just resizes the display.
    I can live with that.
    Can someone help me to get this piece of code save the created thumbernail instead of outputing the resized result on the fly to the browser ?
    I want the created thumbernail saved in the same directory as the original uploaded image.Even better overwrites it and just keep the reduced version.

    [code=php]
    $imagepath = $uploaddir.$ima geName;
    list($width,$he ight)=getimages ize($imagepath) ;
    if($height > 480){
    $image = imagecreatefrom jpeg($imagepath );
    $newheight=480;
    $newwidth=($wid th/$height)*480;
    $thumb = imagecreatetrue color($newwidth ,$newheight);
    imagecopyresamp led($thumb,$ima ge,0,0,0,0,$new width,$newheigh t,$width,$heigh t);
    imagejpeg($thum b,$image,100);
    imagedestroy($i mage);
    imagedestroy($t humb);
    }
    else if($width > 620){
    $image = imagecreatefrom jpeg($imagepath );
    $newwidth=620;
    $newheight=($he ight/$width)*620;
    $thumb =imagecreatetru ecolor($newwidt h,$newheight);
    imagecopyresamp led($thumb,$ima ge,0,0,0,0,$new width,$newheigh t,$width,$heigh t);
    header("Content-Type: image/jpeg");

    imagejpeg($thum b,$image,100);
    imagedestroy($i mage);
    imagedestroy($t humb);
    }
    echo "<img src\"$imagepath \" height=\"$newhe ight\" width=\"$newwid th\" />";
    [/code]
    < Please use [code] tags when posting code! -Atli >
    Last edited by Atli; Jun 29 '07, 06:02 PM. Reason: Added code tags.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    imagejpeg only takes up to three parameters. The first parameter is the image resource, the second is the file to save it to, and the third is the quality. I don't think your $image variable is a filename. :-p

    Comment

    • Jankie
      New Member
      • May 2007
      • 58

      #3
      $image is the path to a filename.It saves the original just not the thumbernail

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Originally posted by Jankie
        $image is the path to a filename.It saves the original just not the thumbernail
        No, that's what I'm trying to tell you. $image is NOT a filepath.

        [code=php]$image = imagecreatefrom jpeg($imagepath );[/code]

        See?

        Comment

        Working...