Jr- Posted January 24, 2007 Share Posted January 24, 2007 I am trying to create thumbnails of images that I upload but I just want a thumbnail of the whole image just smaller resolution. I have the upload script done I just need to know two things:1. how do I copy images.2. how do I resize the copied image.If someone could post up some stuff that would be greatly appreciated.Thanks,Jr- Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/ Share on other sites More sharing options...
redbullmarky Posted January 24, 2007 Share Posted January 24, 2007 [url=http://www.php.net/imagecopy]imagecopy()[/url][url=http://www.php.net/imagecopyresized]imagecopyresized()[/url][url=http://www.php.net/imagecopyresampled]imagecopyresampled()[/url] Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168236 Share on other sites More sharing options...
The Little Guy Posted January 24, 2007 Share Posted January 24, 2007 I don't know if this is what you want, it creates a thumbnail and saves it, just change the 300 at the very bottom to how ever wide you want the image.[code=php:0]<?phpfunction createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality = 100){ # function should be called createJpegThumbnail(); # $quality = 100 is maximum quality # file size will come down for lower quality level $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName"); $thumbHeight = ($origHeight = imagesy($srcImg)) * ($thumbWidth / ($origWidth = imagesx($srcImg))); $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight); imagejpeg($thumbImg, "$thumbDirectory/$imageName", $quality); imagedestroy($srcImg); imagedestroy($thumbImg);} createThumbnail("images/graphics", "$name", "images/graphics/thumbs", 300);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168241 Share on other sites More sharing options...
Jr- Posted January 24, 2007 Author Share Posted January 24, 2007 hmm... tried using the function you posted Little Guy but get this error. Do you know why?Warning: imagejpeg(): Unable to open 'image/pic.jpg' for writing in photos.php on line 127This is what I put in:$fileDirectory = "image";createThumbnail($fileDirectory , "pic.jpg", $fileDirectory , 50); Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168310 Share on other sites More sharing options...
The Little Guy Posted January 24, 2007 Share Posted January 24, 2007 probably because the image is non-existent in the image directory Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168317 Share on other sites More sharing options...
Jr- Posted January 24, 2007 Author Share Posted January 24, 2007 Nope, its in the directory. Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168332 Share on other sites More sharing options...
The Little Guy Posted January 24, 2007 Share Posted January 24, 2007 This function is calling the directory form the current directory that this file is in, so if the directory image isn't in this directory that would be on reason this isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168337 Share on other sites More sharing options...
Jr- Posted January 26, 2007 Author Share Posted January 26, 2007 Ok, I keep trying this:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?$myImage = "test.jpg";function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality = 100){ # function should be called createJpegThumbnail(); # $quality = 100 is maximum quality # file size will come down for lower quality level $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName"); $thumbHeight = ($origHeight = imagesy($srcImg)) * ($thumbWidth / ($origWidth = imagesx($srcImg))); $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight); imagejpeg($thumbImg, "$thumbDirectory/$imageName", $quality); imagedestroy($srcImg); imagedestroy($thumbImg);} createThumbnail("image", $myImage, "image", 50);?></body></html>...and get this error:Warning: imagejpeg(): Unable to open 'image/test.jpg' for writing in /usr/local/pem/vhosts/116423/webspace/httpdocs/grayfire/photos/uploadTest_2.php on line 25It should use the image that I have in a directory and output a thumbnail of that image to the browser right?Thanks,Jr- Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-169501 Share on other sites More sharing options...
The Little Guy Posted January 26, 2007 Share Posted January 26, 2007 so from the current position of this file, there is a directory in this directory called image and that is where it is stored. Right? Cause that is what your saying.What your saying is this is your file structure.[attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-169532 Share on other sites More sharing options...
Jr- Posted January 26, 2007 Author Share Posted January 26, 2007 yeah that's how it is but I still get that error. Also I was having trouble trying to get the image to save to a file instead of trying to output it to the browser but I couldn't get that to work either. Do I have something wrong with the code that I can't get this to work either of those ways? Thanks again for all of the help. ;) Quote Link to comment https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-169535 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.