angel1987 Posted October 1, 2010 Share Posted October 1, 2010 I have been searching since past 3 days and came across many functions on php.net and other sites but i am unable to get it to work. Because in my case already uploaded image names are coming out of database through a while loop. So not sure how to integrate those functions here. Its a very simple process, images are uploaded and stored in a gallery folder and their names are stored in database. Then these images are displayed through while loop as follows <?php $sql = "SELECT * FROM gallery"; $result = @mysql_query($sql) or die(mysql_error()); while($rows = @mysql_fetch_array($result)){ $file = $rows['filename']; ?> <img src="gallery/<?php echo $file; ?>" border="0" /> <br /> <?php } ?> But image dimension can be random so i want it to show in a fixed size of 150x150. I am looking for a very simple method to make that happen. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/ Share on other sites More sharing options...
litebearer Posted October 1, 2010 Share Posted October 1, 2010 rather than repeatedly resizing the images, have you considered creating thumbnails at the time the images are uploaded? Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117898 Share on other sites More sharing options...
angel1987 Posted October 1, 2010 Author Share Posted October 1, 2010 There are many images already uploaded, at first i used javascript for resizing on the fly, but that displayed the entire image and then resized it to smaller scale. so now i am looking for another way to do it on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117903 Share on other sites More sharing options...
chintansshah Posted October 1, 2010 Share Posted October 1, 2010 Please use below function before after uploading image for resize it. After resizing successfully, save thumb image in Database also. function createthumb($name,$filename,$new_w,$new_h){ $system=explode('.',$name); if (preg_match('/jpg|jpeg/',$system[1])){ $src_img=imagecreatefromjpeg($name); } if (preg_match('/png/',$system[1])){ $src_img=imagecreatefrompng($name); } Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117904 Share on other sites More sharing options...
litebearer Posted October 1, 2010 Share Posted October 1, 2010 Have you checked http://phpthumb.sourceforge.net/ Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117907 Share on other sites More sharing options...
angel1987 Posted October 1, 2010 Author Share Posted October 1, 2010 @ litebearer I have came across many such scripts from other sites, but they didn't work. About the link you gave, i tried it but it does not show any image. When i check the source it shows this... <img src="scripts/phpThumb.php?src=gallery/916839599703125000image1.jpg&w=100"> The image path is correct but image is not displayed. It only works normally like in the code i gave above. Where am i going wrong? @ chintansshah Images are already uploaded, so i am looking for a simple method to do it on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117916 Share on other sites More sharing options...
litebearer Posted October 1, 2010 Share Posted October 1, 2010 I presume.. 1. you have a folder named 'scripts' 2. in that folder you have a file named 'phpThumb.php' 3. you have a folder named 'allery' 4. in that folder you have an image named '916839599703125000image1.jpg' There also, inconjunction with the above, be a need to 'adjust' the path to the image. Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117919 Share on other sites More sharing options...
litebearer Posted October 1, 2010 Share Posted October 1, 2010 as an aside... I still recommend 1. create folder called thumbs 2. use a simple function (only need to do this one time) that will take all of the images already uploaded and create thumbs of them. 3. add a thumb-creatation function to your upload script The savings on time and cpu usgae will be greatly increased Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117921 Share on other sites More sharing options...
angel1987 Posted October 1, 2010 Author Share Posted October 1, 2010 All the references and paths are correct. Still it won't work. About the code for creating new thumbnails. Is is the one given by @chintansshah above? It does not shows the path where the thumbs will be saved? Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117925 Share on other sites More sharing options...
litebearer Posted October 1, 2010 Share Posted October 1, 2010 here is function I use to resize existing images http://www.nstoia.com/toh/imageresize.php Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117929 Share on other sites More sharing options...
angel1987 Posted October 1, 2010 Author Share Posted October 1, 2010 Ok i tried it. But for resizing while uploading and storing filenames in database i am trying the script on this website. http://www.plus2net.com/php_tutorial/php_thumbnail.php And it works partially, it can copy the image on server and also store all the data in database, but it just won't create thumbnails. From that script, it is giving this error if (!($_FILES[userfile][type] =="image/pjpeg" OR $_FILES[userfile][type]=="image/gif")){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>"; I am uploading jpg files. Is there any different between jpg and jpeg and JPG and JPEG? Some images shows jpg and some shows jpeg as extension and i played with extension but still it won't work. Quote Link to comment https://forums.phpfreaks.com/topic/214892-please-help-with-auto-image-resize-in-php/#findComment-1117935 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.