bluebutterflyofyourmind Posted November 18, 2007 Share Posted November 18, 2007 hey there. i've succesfuly created a thumbnail from an image that has be verified and copied to a folder on the server for later calling from a database. I'm having trouble saving the new thumbnail file that has been created. using move_uploaded_file($thumb, $thumbupload); does not work. is there a GD function for writing an image to a directory? the thumbnail as be created and just needs to be written now. thanks Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 18, 2007 Share Posted November 18, 2007 You might get a more specific / suited answer if you provide some of the code you use to create the thumbnails. The creation of images (resizing ect.) is often very closely combined with saving them as an actual file on the server. But imagejpeg(), imagegif() and imagepng() should do what you want: http://dk2.php.net/manual/en/function.imagejpeg.php Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted November 18, 2007 Author Share Posted November 18, 2007 sorry bout that. here's the code used to create the thumbnail. only jpegs and pngs are being uploaded and this has been verified already. $uploaddir = 'Orig/'; $uploadfile = $uploaddir . basename($_FILES['imagefile']['name']); move_uploaded_file($_FILES['imagefile']['tmp_name'], $uploadfile); list($width, $height, $type, $attr) = getimagesize($uploadfile); if($filetype == "image/jpeg"){ //header("Content-Type: image/jpeg"); $Orig = imagecreatefromjpeg($uploadfile); $extension = ".jpeg"; } else if($filetype == "image/png"){ //header("Content-Type: image/png"); $Orig = imagecreatefrompng($uploadfile); $extension = ".png"; } else{ echo "ERROR ERROR ERROR!!!!!!!!!!<BR>"; } $thumb = imagecreatetruecolor(100,100); imagecopyresampled($thumb,$Orig,0,0,0,0,100,100,$width,$height); echo "variable thumb = ".$thumb; $uploadthumbdir = 'Thmb/'; $thumbupload = $uploadthumbdir . basename($_FILES['imagefile']['name']); move_uploaded_file($thumb, $thumbupload); echo "finished uploading thumb image"; echo "thumb = ".$thumb."<BR>"; echo "thumbupload = ".$thumbupload."<BR>"; echo "Original image = <img src=".$uploadfile." /><BR>"; echo "Thumbnail = <img src=".$thumbupload." /><BR>"; excuse the abundance of echo's....i'm just using them for debugging purposes. thanks Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted November 18, 2007 Author Share Posted November 18, 2007 image jpeg and imagepng() worked beautifully. Thanks!!!! Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 18, 2007 Share Posted November 18, 2007 You simply add one of the functions I listed in my last reply after you have used imagecopyresampled: <?php //From your code $thumb = imagecreatetruecolor(100,100); imagecopyresampled($thumb,$Orig,0,0,0,0,100,100,$width,$height); //Save the image as JPEG to a folder imagejpeg($thumb, '/path/to/save/image/to/filename.jpg', 75); //Save the image as PNG to a folder imagepng($thumb, '/path/to/save/image/to/filename.png'); ?> Read up on the functions here: http://php.net/manual/en/function.imagejpeg.php http://php.net/manual/en/function.imagepng.php Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted November 18, 2007 Author Share Posted November 18, 2007 :)totally right. thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.